Next:
Piping Up: Program Listings Previous: signal.c

sig_talk.c

/* sig_talk.c --- Example of how 2 processes can talk */ /* to each other using kill() and signal() */ /* We will fork() 2 process and let the parent send a few */ /* signals to it`s child */ /* acc sig_talk.c -o sig_talk on SUNS */ /* c89 sig_talk.c -o sig_talk on DECS */ include <stdio.h include <signal.h void sighup(); /* routines child will call upon sigtrap */ void sigint(); void sigquit(); main() { int pid; /* get child process */ if ((pid = fork()) < 0) { perror("fork); exit(1); } if (pid == 0) { /* child */ signal(SIGHUP,sighup); /* set function calls */ signal(SIGINT,sigint); signal(SIGQUIT, sigquit); for(;;); /* loop for ever */ } else /* parent */ { /* pid hold id of child */ printf(\nPARENT: sending SIGHUP\n\n); kill(pid,SIGHUP); sleep(3); /* pause for 3 secs */ printf(\nPARENT: sending SIGINT\n\n); kill(pid,SIGINT); sleep(3); /* pause for 3 secs */ printf(\nPARENT: sending SIGQUIT\n\n); kill(pid,SIGQUIT); sleep(3); } } void sighup() { signal(SIGHUP,sighup); /* reset signal */ printf("CHILD: I have received a SIGHUP\n); } void sigint() { signal(SIGINT,sigint); /* reset signal */ printf("CHILD: I have received a SIGINT\n); } void sigquit() { printf("My DADDY has Killed me!!!\n); exit(0); }


Bhopal news
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

India website designer web development India php ecommerce developer | Web design India, Ecommerce web design | India web hosting website host india | Windows hosting India web hosting | Software development India | Flash web designer india