linux signal question
Posted: Fri Jun 12, 2009 2:59 pm
hi
please look at the following piece of code
i don't understand the signalling-logic behind this: when i run this, i can see the child on my console output the ping stuff
when i press ctrl-c, i get the output:
the signal handler was installed only AFTER the fork and only within the parent's address space.
can any of you make sense of that?
thanks
martin
please look at the following piece of code
Code: Select all
pid_t child = 0;
void forward(int signum)
{
if (child != 0) {
printf("sig in parent\n");
} else {
printf("sig in child\n");
}
}
int main(int argc, char *argv[])
{
for(;;) {
pid_t child = fork();
if (child < 0) exit(1);
if (child == 0) {
argv[0] = "ping";
execvp("ping", argv);
}
signal(SIGINT, &forward);
int status;
wait(&status);
printf("child %d dead :-( respawning...\n", child);
}
}
when i press ctrl-c, i get the output:
why?sig in child
the signal handler was installed only AFTER the fork and only within the parent's address space.
can any of you make sense of that?
thanks
martin