Guest User

Untitled

a guest
Apr 29th, 2015
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. /* parent */
  2. #include <stdio.h>
  3. #include <signal.h>
  4. #include <unistd.h>
  5. #include <sys/types.h>
  6.  
  7. int flag;
  8.  
  9. void sigusr1_handler( int sig )
  10. {
  11.   printf( "caught sigusr1! terminating!\n" );
  12.   flag = 0;
  13. }
  14.  
  15. int main()
  16. {
  17.   flag = 1;
  18.   signal( SIGUSR1, sigusr1_handler );
  19.   if( fork() == 0 ) execve( "./bin2", NULL, NULL );
  20.   while( flag );
  21. }
  22.  
  23. /* child */
  24. #include <stdio.h>
  25. #include <signal.h>
  26. #include <unistd.h>
  27. #include <sys/types.h>
  28. #include <errno.h>
  29. #include <assert.h>
  30.  
  31. void sigusr1_handler( int sig )
  32. {
  33.   printf( "sending signal to parent return: %d\n", kill( getppid(), SIGUSR1 ) );
  34.   exit( 0 );
  35. }
  36.  
  37.  
  38. int main( int argc, char **argv )
  39. {
  40.   errno = 0;
  41.   signal( SIGUSR1, sigusr1_handler );
  42.   assert( errno == 0 );
  43.   while( 1 );
  44. }
Advertisement
Add Comment
Please, Sign In to add comment