1 #include <unistd.h> 2 #include <stdio.h> 3 #include <signal.h> 4 5 static int sigchld_no; 6 static int nosig_no; 7 static int weird_value; 8 9 void 10 sigchld_handler (int signo) 11 { 12 sigchld_no++; 13 printf ("Got sigchld %d.\n", sigchld_no); 14 } 15 16 int 17 call_me (int some_value) 18 { 19 int ret_val = 0; 20 int i; 21 for (i = 0; i < some_value; i++) 22 { 23 int result = 0; 24 if (i%2 == 0) 25 result = kill (getpid(), SIGCHLD); 26 else 27 sigchld_no++; 28 29 usleep(1000); 30 if (result == 0) 31 ret_val++; 32 } 33 usleep (10000); 34 return ret_val; 35 } 36 37 int 38 call_me_nosig (int some_value) 39 { 40 int ret_val = 0; 41 int i; 42 for (i = 0; i < some_value; i++) 43 weird_value += i % 4; 44 45 nosig_no += some_value; 46 return some_value; 47 } 48 49 int 50 main () 51 { 52 int ret_val; 53 signal (SIGCHLD, sigchld_handler); 54 55 ret_val = call_me (2); // Stop here in main. 56 57 ret_val = call_me_nosig (10); 58 59 return 0; 60 61 } 62