Hi!
When I am trying to execute the following program the child process simply waits for the signal.
Output:Code:#include <stdio.h> #include <unistd.h> #include <signal.h> #include <stdlib.h> #include <sys/types.h> static int alarm_fired = 0; void ding(int sig) { alarm_fired = 1; } int main() { pid_t pid; (void)signal(SIGALRM, ding); printf("alarm application starting.\n"); pid = fork(); switch(pid){ case -1: /* failure */ perror("Fork failed"); exit(1); case 0: /* child */ sleep(1); kill(getpid(), SIGALRM); break; default: exit(0); } printf("waiting for alarm to go off\n"); pause(); if(alarm_fired) printf("Ding!\n"); exit(0); }
linux:~/prog # ./thread
alarm application starting.
linux:~/prog # waiting for alarm to go off
...waits here...
Why can't the child process send the signal to itself?
Regards,
Arun



LinkBack URL
About LinkBacks


