1f08c3bdfSopenharmony_ci/* 2f08c3bdfSopenharmony_ci * Copyright (c) 2015 Cedric Hnyda <chnyda@suse.com> 3f08c3bdfSopenharmony_ci * 4f08c3bdfSopenharmony_ci * This program is free software; you can redistribute it and/or 5f08c3bdfSopenharmony_ci * modify it under the terms of the GNU General Public License as 6f08c3bdfSopenharmony_ci * published by the Free Software Foundation; either version 2 of 7f08c3bdfSopenharmony_ci * the License, or (at your option) any later version. 8f08c3bdfSopenharmony_ci * 9f08c3bdfSopenharmony_ci * This program is distributed in the hope that it would be useful, 10f08c3bdfSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 11f08c3bdfSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12f08c3bdfSopenharmony_ci * GNU General Public License for more details. 13f08c3bdfSopenharmony_ci * 14f08c3bdfSopenharmony_ci * You should have received a copy of the GNU General Public License 15f08c3bdfSopenharmony_ci * along with this program; if not, write the Free Software Foundation, 16f08c3bdfSopenharmony_ci * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17f08c3bdfSopenharmony_ci */ 18f08c3bdfSopenharmony_ci 19f08c3bdfSopenharmony_ci/* 20f08c3bdfSopenharmony_ci* Description: 21f08c3bdfSopenharmony_ci* Write the current process in argv[1] 22f08c3bdfSopenharmony_ci*/ 23f08c3bdfSopenharmony_ci 24f08c3bdfSopenharmony_ci#include <stdio.h> 25f08c3bdfSopenharmony_ci#include <sys/time.h> 26f08c3bdfSopenharmony_ci#include <sys/types.h> 27f08c3bdfSopenharmony_ci#include <unistd.h> 28f08c3bdfSopenharmony_ci#include <signal.h> 29f08c3bdfSopenharmony_ci#include <stdlib.h> 30f08c3bdfSopenharmony_ci#include <string.h> 31f08c3bdfSopenharmony_ci 32f08c3bdfSopenharmony_cistatic void sig_handler(int signo) 33f08c3bdfSopenharmony_ci{ 34f08c3bdfSopenharmony_ci _exit(0); 35f08c3bdfSopenharmony_ci} 36f08c3bdfSopenharmony_ci 37f08c3bdfSopenharmony_ciint main(int argc, char **argv) 38f08c3bdfSopenharmony_ci{ 39f08c3bdfSopenharmony_ci FILE *f; 40f08c3bdfSopenharmony_ci struct sigaction sa; 41f08c3bdfSopenharmony_ci 42f08c3bdfSopenharmony_ci if (argc != 2) { 43f08c3bdfSopenharmony_ci fprintf(stderr, "Usage: %s /cgroup/.../tasks\n", argv[0]); 44f08c3bdfSopenharmony_ci return 1; 45f08c3bdfSopenharmony_ci } 46f08c3bdfSopenharmony_ci 47f08c3bdfSopenharmony_ci f = fopen(argv[1], "a"); 48f08c3bdfSopenharmony_ci if (!f) { 49f08c3bdfSopenharmony_ci perror("fopen failed"); 50f08c3bdfSopenharmony_ci return 1; 51f08c3bdfSopenharmony_ci } 52f08c3bdfSopenharmony_ci 53f08c3bdfSopenharmony_ci fprintf(f, "%i\n", getpid()); 54f08c3bdfSopenharmony_ci fclose(f); 55f08c3bdfSopenharmony_ci 56f08c3bdfSopenharmony_ci memset(&sa, 0, sizeof(sa)); 57f08c3bdfSopenharmony_ci sigemptyset(&sa.sa_mask); 58f08c3bdfSopenharmony_ci sa.sa_handler = sig_handler; 59f08c3bdfSopenharmony_ci 60f08c3bdfSopenharmony_ci if (sigaction(SIGVTALRM, &sa, NULL)) { 61f08c3bdfSopenharmony_ci perror("sigaction failed"); 62f08c3bdfSopenharmony_ci return 1; 63f08c3bdfSopenharmony_ci } 64f08c3bdfSopenharmony_ci 65f08c3bdfSopenharmony_ci struct itimerval it = {.it_value = {.tv_sec = 0, .tv_usec = 10000}}; 66f08c3bdfSopenharmony_ci 67f08c3bdfSopenharmony_ci setitimer(ITIMER_VIRTUAL, &it, NULL); 68f08c3bdfSopenharmony_ci for (;;); 69f08c3bdfSopenharmony_ci return 0; 70f08c3bdfSopenharmony_ci} 71