I am trying to use this example from http://www.cs.cf.ac.uk/Dave/C/node24.html :
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
void sighup();
void sigint();
void sigquit();
main() {
int pid;
if ((pid = fork()) < 0) {
perror("fork");
exit(1);
}
if (pid == 0) {
printf("\nI am the new child!\n\n");
signal(SIGHUP,sighup);
signal(SIGINT,sigint);
signal(SIGQUIT, sigquit);
printf("\nChild going to loop...\n\n");
for(;;);
}
else
{
printf("\nPARENT: sending SIGHUP\n\n");
kill(pid,SIGHUP);
sleep(3);
printf("\nPARENT: sending SIGINT\n\n");
kill(pid,SIGINT);
sleep(3);
printf("\nPARENT: sending SIGQUIT\n\n");
kill(pid,SIGQUIT);
sleep(3);
}
}
void sighup() {
signal(SIGHUP,sighup);
printf("CHILD: I have received a SIGHUP\n");
}
void sigint() {
signal(SIGINT,sigint);
printf("CHILD: I have received a SIGINT\n");
}
void sigquit() {
printf("My DADDY has Killed me!!!\n");
exit(0);
}
But I do not see any output from the child process.
Is this expected behavior? If so; why?
Many thanks!
source
share