cgroup_fj_proc.c revision 6c4d1c6d4b3c116ff88f9209b4860940fb8659a8
1/******************************************************************************/ 2/* */ 3/* Copyright (c) 2009 FUJITSU LIMITED */ 4/* */ 5/* This program is free software; you can redistribute it and/or modify */ 6/* it under the terms of the GNU General Public License as published by */ 7/* the Free Software Foundation; either version 2 of the License, or */ 8/* (at your option) any later version. */ 9/* */ 10/* This program is distributed in the hope that it will be useful, */ 11/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 12/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ 13/* the GNU General Public License for more details. */ 14/* */ 15/* You should have received a copy of the GNU General Public License */ 16/* along with this program; if not, write to the Free Software */ 17/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 18/* */ 19/* Author: Shi Weihua <shiwh@cn.fujitsu.com> */ 20/* */ 21/******************************************************************************/ 22 23#include <sys/types.h> 24#include <sys/wait.h> 25#include <err.h> 26#include <errno.h> 27#include <signal.h> 28#include <stdlib.h> 29#include <unistd.h> 30#include <stdio.h> 31 32#define UNUSED __attribute__ ((unused)) 33 34static int test_switch = 0; 35 36void sighandler(UNUSED int signo) 37{ 38 test_switch = !test_switch; 39} 40 41int main(void) 42{ 43 sigset_t sigset; 44 struct sigaction sa; 45 pid_t pid; 46 int status; 47 int count = 0; 48 49 sa.sa_handler = sighandler; 50 if (sigemptyset(&sa.sa_mask) < 0) 51 err(1, "sigemptyset()"); 52 53 sa.sa_flags = 0; 54 if (sigaction(SIGUSR1, &sa, NULL) < 0) 55 err(1, "sigaction()"); 56 57 if (sigemptyset(&sigset) < 0) 58 err(1, "sigemptyset()"); 59 60 /* wait for the signal SIGUSR1 to start testing */ 61 sigsuspend(&sigset); 62 if (errno != EINTR) 63 err(1, "sigsuspend()"); 64 65 do { 66 count++; 67 pid = fork(); 68 if (pid == -1) 69 err(1, "fork()"); 70 else if (pid == 0) { 71 return 0; 72 } else { 73 wait(&status); 74 } 75 } while (test_switch); 76 77 return 0; 78} 79