Re: sigaction, fork, malloc, and futex

From: Edgar Toernig
Date: Tue May 04 2004 - 19:40:09 EST


Steve Beaty wrote:
>
>... the signal handler fork another child.

Uhh... just read that POSIX actually allows that. Evil!
I guess you're entering undiscovered land...

> void sig_handler (int signum)
> {
> int child;
>
> fprintf (stderr, "Process %d received a SIGALRM signal\n", getpid());
> if ((child = fork ()) == 0)
> {
> fprintf (stderr, "%d exiting\n", getpid());
> exit (0);
> }
> fprintf (stderr, "%d waiting for %d\n", getpid(), child);
> waitpid (child, NULL, 0);
> }

No fprintf and exit in a signal handler! Use write and _exit instead.

> if ((child = fork ()) == 0)
> {
> fprintf (stderr, "%d sending SIGALRM to %d\n", getpid(), parent);
> if (kill (parent, SIGALRM) == -1) perror ("kill 1");
> fprintf (stderr, "%d exiting\n", getpid());
> exit (0);
> }

This exit is dubious too. _exit is better.

Good luck, you may need it - ET.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/