sigaction, fork, malloc, and futex
anyone have a clue on this one? we set up a signal handler, create a child that sends that signal, and have the signal handler fork another child. if there is a malloc(), the second child gets stuck in a futex(); without the malloc(), no problem. 2.4.20-30.9 kernel. straces at the end. any help would be appreciated. thanks!
===========================================================================
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <assert.h>
/* comment out the following to show the problem */ #define WORKS
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);
}int
main (int argc, char **argv)
{
int parent = getpid();
int child;
struct sigaction action;
sigemptyset (&action.sa_mask);
action.sa_handler = sig_handler;#ifndef WORKS malloc (sizeof (int));
#endif
assert (sigaction (SIGALRM, &action, NULL) == 0);
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);
}
fprintf (stderr, "%d waiting for %d\n", getpid(), child);
waitpid (child, NULL, 0);
}/*
** if WORKS defined:
$ ./a.out 9106 sending SIGALRM to 9105 9106 exiting Process 9105 received a SIGALRM signal 9107 exiting 9105 waiting for 9107 9105 waiting for 9106
** if WORKS undefined:
$ ./a.out 9095 sending SIGALRM to 9094 9095 exiting Process 9094 received a SIGALRM signal
$ sh /usr/src/linux-2.4.20-30.9/scripts/ver_linux If some fields are empty or look unusual you may have an old version. Compare to the current minimal requirements in Documentation/Changes.
Linux emess0.mscd.edu 2.4.20-30.9 #1 Wed Feb 4 20:44:26 EST 2004 i686 i686 i386 GNU/Linux
Gnu C 3.2.2 Gnu make 3.79.1 util-linux 2.11y mount 2.11y modutils 2.4.22 e2fsprogs 1.32 jfsutils 1.0.17 reiserfsprogs 3.6.4 pcmcia-cs 3.1.31 PPP 2.4.1 isdn4k-utils 3.1pre4 Linux C Library 2.3.2 Dynamic linker (ldd) 2.3.2 Procps 2.0.11 Net-tools 1.60 Kbd 1.08 Sh-utils 4.5.3 Modules Loaded ieee1394 ide-cd cdrom i810_audio ac97_codec
soundcore mga agpgart binfmt_misc autofs e100 ipchains loop lvm-mod keybdev mousedev hid input usb-uhci usbcore ext3 jbd
*/
#if 0
BAD:
---------------------------------------------------------------------------
$ strace ./a.out
execve("./a.out", ["./a.out"], [/* 42 vars */]) = 0
uname({sys="Linux", node="emess.mscd.edu", ...}) = 0
brk(0) = 0x80499fc
open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or
directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=105716, ...}) = 0
old_mmap(NULL, 105716, PROT_READ, MAP_PRIVATE, 3, 0) = 0x40016000
close(3) = 0
open("/lib/tls/libc.so.6", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\360W\1"..., 512) =
512
fstat64(3, {st_mode=S_IFREG|0755, st_size=1539996, ...}) = 0
old_mmap(0x42000000, 1267276, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) =
0x42000000
old_mmap(0x42130000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3,
0x130000) = 0x42130000
old_mmap(0x42133000, 9804, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x42133000
close(3) = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0x40030000
set_thread_area({entry_number:-1 -> 6, base_addr:0x400304a0, limit:1048575,
seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1,
seg_not_present:0, useable:1}) = 0
munmap(0x40016000, 105716) = 0
getpid() = 9059
brk(0) = 0x80499fc
brk(0x804a9fc) = 0x804a9fc
brk(0) = 0x804a9fc
brk(0x804b000) = 0x804b000
rt_sigaction(SIGALRM, {0x8048568, [],
SA_RESTORER|SA_NOMASK|SA_SIGINFO|0x21328d0, 0x420277b0}, NULL, 8) = 0
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|0x11,
<ignored>, <ignored>, 0x400304e8) = 9060
9060 sending SIGALRM to 9059
9060 exiting
--- SIGALRM (Alarm clock) @ 0 (0) ---
getpid() = 9059
--- SIGCHLD (Child exited) @ 0 (0) ---
write(2, "Process 9059 received a SIGALRM "..., 39Process 9059 received a
SIGALRM signal
) = 39
futex(0x421336d0, FUTEX_WAIT, 2, NULL
[control-c]
---------------------------------------------------------------------------GOOD
---------------------------------------------------------------------------
$ strace ./a.out
execve("./a.out", ["./a.out"], [/* 42 vars */]) = 0
uname({sys="Linux", node="emess.mscd.edu", ...}) = 0
brk(0) = 0x80499b8
open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or
directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=105716, ...}) = 0
old_mmap(NULL, 105716, PROT_READ, MAP_PRIVATE, 3, 0) = 0x40016000
close(3) = 0
open("/lib/tls/libc.so.6", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\360W\1"..., 512) =
512
fstat64(3, {st_mode=S_IFREG|0755, st_size=1539996, ...}) = 0
old_mmap(0x42000000, 1267276, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) =
0x42000000
old_mmap(0x42130000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3,
0x130000) = 0x42130000
old_mmap(0x42133000, 9804, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x42133000
close(3) = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0x40030000
set_thread_area({entry_number:-1 -> 6, base_addr:0x400304a0, limit:1048575,
seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1,
seg_not_present:0, useable:1}) = 0
munmap(0x40016000, 105716) = 0
getpid() = 9087
rt_sigaction(SIGALRM, {0x8048534, [],
SA_RESTORER|SA_NOMASK|SA_SIGINFO|0x21328d0, 0x420277b0}, NULL, 8) = 0
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|0x11,
<ignored>, <ignored>, 0x400304e8) = 9088
9088 sending SIGALRM to 9087
9088 exiting
--- SIGALRM (Alarm clock) @ 0 (0) ---
getpid() = 9087
--- SIGCHLD (Child exited) @ 0 (0) ---
write(2, "Process 9087 received a SIGALRM "..., 39Process 9087 received a
SIGALRM signal
) = 39
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|0x11,
<ignored>, <ignored>, 0x400304e8) = 9089
getpid() = 9087
write(2, "9087 waiting for 9089\n", 229087 waiting for 9089
) = 22
wait4(9089, 9089 exiting
NULL, 0, NULL) = 9089
rt_sigreturn(0x1200011) = 9088
getpid() = 9087
write(2, "9087 waiting for 9088\n", 229087 waiting for 9088
) = 22
wait4(9088, NULL, 0, NULL) = 9088
exit_group(0) = ?
---------------------------------------------------------------------------
#endif
===========================================================================Signature · 4 lines
Dr. Steve Beaty (B80) Associate Professor Metro State College of Denver [email protected] VOX: (303) 556-5321 Science Building 134C FAX: (303) 556-5381 http://clem.mscd.edu/~beatys/
Hi-
Quoted 7 lines · Steve Beaty
anyone have a clue on this one? we set up a signal handler, create a child that sends that signal, and have the signal handler fork another child. if there is a
malloc(), the second child gets stuck in afutex(); without themalloc(), no problem. 2.4.20-30.9 kernel. straces at the end. any help would be appreciated. thanks!
Your signal handler function is illegally calling non-reentrant functions. The *printf() family of functions are going to need to call malloc() to allocate buffers. malloc() cannot be re-entered.
So specifically your deadlock sequence is:
Parent:fork()fprintf()
-> malloc()
-> take a malloc() lock
(Child schedules and sends SIGALRM at this point)
SIGALRM:fprintf()
-> malloc()
-> try to take a malloc() lock
-> deadlock, lock is already taken and will never be released!
Modern glibc / kernel combinations which use futexes in the malloc code really seem to expose this race.
Cheers
Chris
Quoted 28 lines · On Tue, 2004-05-04 at 16:30, [email protected] wrote:
Hi-
Quoted 7 lines · Steve Beaty
anyone have a clue on this one? we set up a signal handler, create a child that sends that signal, and have the signal handler fork another child. if there is a
malloc(), the second child gets stuck in afutex(); without themalloc(), no problem. 2.4.20-30.9 kernel. straces at the end. any help would be appreciated. thanks!Your signal handler function is illegally calling non-reentrant functions. The
*printf()family of functions are going to need to callmalloc()to allocate buffers.malloc()cannot be re-entered.So specifically your deadlock sequence is:
Parent:
fork()fprintf()
->malloc()
-> take amalloc()lock
(Child schedules and sends SIGALRM at this point)
SIGALRM:fprintf()
->malloc()
-> try to take amalloc()lock
Quoted 7 lines
-> deadlock, lock is already taken and will never be released!Modern glibc / kernel combinations which use futexes in the malloc code really seem to expose this race.
Cheers
Chris
No, it's nothing to do with the fprintf. I tried the program without any fprints at all and got the same result.
I'm pretty sure the problem is in glibc. Look at malloc_atfork and free_atfork in glibc's malloc/arena.c. I think the reason you are only seeing it happen when you malloc is that glibc only initializes the malloc system when you first use it.
I am not sure it is really a problem though. I don't think you should be allowed to fork inside a signal handler. That seems very wrong.
Signature · 1 line
Zan Lynx <[email protected]>
Quoted 2 lines · Zan Lynx
I am not sure it is really a problem though. I don't think you should be allowed to fork inside a signal handler. That seems very wrong.
fork is marked async-signal-safe, provided that all atfork handlers are async-signal-safe.
Andreas.
Signature · 4 lines
Andreas Schwab, SuSE Labs, [email protected] SuSE Linux AG, Maxfeldstraße 5, 90409 Nürnberg, Germany Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
Quoted 2 lines
I am not sure it is really a problem though. I don't think you should be allowed to fork inside a signal handler. That seems very wrong.
i can't disagree :-) but fork() is supposed to be reentrant...
Signature · 4 lines
Dr. Steve Beaty (B80) Associate Professor Metro State College of Denver [email protected] VOX: (303) 556-5321 Science Building 134C FAX: (303) 556-5381 http://clem.mscd.edu/~beatys/
Quoted 4 lines · Steve Beaty
Quoted 2 lines
I am not sure it is really a problem though. I don't think you should be allowed to fork inside a signal handler. That seems very wrong.
i can't disagree :-) but
fork()is supposed to be reentrant...
In your test program, I just tried using sys_clone to fork the process directly. It works. The problem really is inside glibc. If glibc is not POSIX compliant in this instance, I suppose you will have to file a bug with them.
Signature · 1 line
Zan Lynx <[email protected]>
Quoted 3 lines
Your signal handler function is illegally calling non-reentrant functions. The
*printf()family of functions are going to need to callmalloc()to allocate buffers.malloc()cannot be re-entered.
it deadlocks even with no calls in the client... weird.
thanks,
Signature · 4 lines
Dr. Steve Beaty (B80) Associate Professor Metro State College of Denver [email protected] VOX: (303) 556-5321 Science Building 134C FAX: (303) 556-5381 http://clem.mscd.edu/~beatys/
Quoted 7 lines · Steve Beaty
anyone have a clue on this one? we set up a signal handler, create a child that sends that signal, and have the signal handler fork another child. if there is a
malloc(), the second child gets stuck in afutex(); without themalloc(), no problem. 2.4.20-30.9 kernel. straces at the end. any help would be appreciated. thanks!
Sure buggy code. There are only a few things you can do from a signal handler and I'm fairly sure fork() isn't one of them. Did you just invent this as a way of concatenating system calls to see what works? Surely you don't have a program that does this do you? The signal handler executes on its own signal stack, it can't reach anything thats located on the main program stack. The malloc() stuff is in the heap, above the main program stack. Once you do something that requires access to the heap or the main program stack, in the signal handler, all bets are off.
So, just don't dooooo this!
Quoted 213 lines
===========================================================================
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <assert.h>/* comment out the following to show the problem */ #define WORKS
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); }int
main (int argc, char **argv){ int parent = getpid(); int child; struct sigaction action; sigemptyset (&action.sa_mask); action.sa_handler = sig_handler;#ifndef WORKS malloc (sizeof (int));#endif
assert (sigaction (SIGALRM, &action, NULL) == 0); 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); } fprintf (stderr, "%d waiting for %d\n", getpid(), child); waitpid (child, NULL, 0); }/*
** if WORKS defined:$ ./a.out 9106 sending SIGALRM to 9105 9106 exiting Process 9105 received a SIGALRM signal 9107 exiting 9105 waiting for 9107 9105 waiting for 9106** if WORKS undefined:
$ ./a.out 9095 sending SIGALRM to 9094 9095 exiting Process 9094 received a SIGALRM signal$ sh /usr/src/linux-2.4.20-30.9/scripts/ver_linux If some fields are empty or look unusual you may have an old version. Compare to the current minimal requirements in Documentation/Changes.Linux emess0.mscd.edu 2.4.20-30.9 #1 Wed Feb 4 20:44:26 EST 2004 i686 i686 i386 GNU/Linux
Gnu C 3.2.2 Gnu make 3.79.1 util-linux 2.11y mount 2.11y modutils 2.4.22 e2fsprogs 1.32 jfsutils 1.0.17 reiserfsprogs 3.6.4 pcmcia-cs 3.1.31 PPP 2.4.1 isdn4k-utils 3.1pre4 Linux C Library 2.3.2 Dynamic linker (ldd) 2.3.2 Procps 2.0.11 Net-tools 1.60 Kbd 1.08 Sh-utils 4.5.3 Modules Loaded ieee1394 ide-cd cdrom i810_audio ac97_codecsoundcore mga agpgart
binfmt_miscautofs e100 ipchains loop lvm-mod keybdev mousedev hid input usb-uhci usbcore ext3 jbd*/
#if 0
BAD:
---------------------------------------------------------------------------$ strace ./a.out execve("./a.out", ["./a.out"], [/* 42 vars */]) = 0 uname({sys="Linux", node="emess.mscd.edu", ...}) = 0 brk(0) = 0x80499fc open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or directory) open("/etc/ld.so.cache", O_RDONLY) = 3 fstat64(3, {st_mode=S_IFREG|0644, st_size=105716, ...}) = 0 old_mmap(NULL, 105716, PROT_READ, MAP_PRIVATE, 3, 0) = 0x40016000 close(3) = 0 open("/lib/tls/libc.so.6", O_RDONLY) = 3 read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\360W\1"..., 512) = 512 fstat64(3, {st_mode=S_IFREG|0755, st_size=1539996, ...}) = 0 old_mmap(0x42000000, 1267276, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0x42000000 old_mmap(0x42130000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x130000) = 0x42130000 old_mmap(0x42133000, 9804, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x42133000 close(3) = 0 old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40030000 set_thread_area({entry_number:-1 -> 6, base_addr:0x400304a0, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0 munmap(0x40016000, 105716) = 0 getpid() = 9059 brk(0) = 0x80499fc brk(0x804a9fc) = 0x804a9fc brk(0) = 0x804a9fc brk(0x804b000) = 0x804b000 rt_sigaction(SIGALRM, {0x8048568, [], SA_RESTORER|SA_NOMASK|SA_SIGINFO|0x21328d0, 0x420277b0}, NULL, 8) = 0 clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|0x11, <ignored>, <ignored>, 0x400304e8) = 9060 9060 sending SIGALRM to 9059 9060 exiting --- SIGALRM (Alarm clock) @ 0 (0) --- getpid() = 9059 --- SIGCHLD (Child exited) @ 0 (0) --- write(2, "Process 9059 received a SIGALRM "..., 39Process 9059 received a SIGALRM signal ) = 39 futex(0x421336d0, FUTEX_WAIT, 2, NULL [control-c] ---------------------------------------------------------------------------GOOD
---------------------------------------------------------------------------
$ strace ./a.out execve("./a.out", ["./a.out"], [/* 42 vars */]) = 0 uname({sys="Linux", node="emess.mscd.edu", ...}) = 0 brk(0) = 0x80499b8 open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or directory) open("/etc/ld.so.cache", O_RDONLY) = 3 fstat64(3, {st_mode=S_IFREG|0644, st_size=105716, ...}) = 0 old_mmap(NULL, 105716, PROT_READ, MAP_PRIVATE, 3, 0) = 0x40016000 close(3) = 0 open("/lib/tls/libc.so.6", O_RDONLY) = 3 read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\360W\1"..., 512) = 512 fstat64(3, {st_mode=S_IFREG|0755, st_size=1539996, ...}) = 0 old_mmap(0x42000000, 1267276, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0x42000000 old_mmap(0x42130000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x130000) = 0x42130000 old_mmap(0x42133000, 9804, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x42133000 close(3) = 0 old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40030000 set_thread_area({entry_number:-1 -> 6, base_addr:0x400304a0, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0 munmap(0x40016000, 105716) = 0 getpid() = 9087 rt_sigaction(SIGALRM, {0x8048534, [], SA_RESTORER|SA_NOMASK|SA_SIGINFO|0x21328d0, 0x420277b0}, NULL, 8) = 0 clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|0x11, <ignored>, <ignored>, 0x400304e8) = 9088 9088 sending SIGALRM to 9087 9088 exiting --- SIGALRM (Alarm clock) @ 0 (0) --- getpid() = 9087 --- SIGCHLD (Child exited) @ 0 (0) --- write(2, "Process 9087 received a SIGALRM "..., 39Process 9087 received a SIGALRM signal ) = 39 clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|0x11, <ignored>, <ignored>, 0x400304e8) = 9089 getpid() = 9087 write(2, "9087 waiting for 9089\n", 229087 waiting for 9089 ) = 22 wait4(9089, 9089 exiting NULL, 0, NULL) = 9089 rt_sigreturn(0x1200011) = 9088 getpid() = 9087 write(2, "9087 waiting for 9088\n", 229087 waiting for 9088 ) = 22 wait4(9088, NULL, 0, NULL) = 9088 exit_group(0) = ? --------------------------------------------------------------------------- #endif ===========================================================================
Quoted 11 lines
--
Dr. Steve Beaty (B80) Associate Professor
Metro State College of Denver [email protected]
VOX: (303) 556-5321 Science Building 134C
FAX: (303) 556-5381 http://clem.mscd.edu/~beatys/
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Cheers,
Dick Johnson
Penguin : Linux version 2.4.26 on an i686 machine (5557.45 BogoMips).
Note 96.31% of all statistics are fiction.
Quoted 2 lines
Sure buggy code. There are only a few things you can do from a signal handler and I'm fairly sure
fork()isn't one of them.
well, one should only set values and deal with them somewhere in signal handlers, but...
Quoted 3 lines
Did you just invent this as a way of concatenating system calls to see what works? Surely you don't have a program that does this do you?
well, yes, but it is a classroom assignment so not "real" code. the assignment is to create a simulated disk drive (a process) via a "system call" that signals a "kernel". perhaps we should really fork and exec...
Signature · 4 lines
Dr. Steve Beaty (B80) Associate Professor Metro State College of Denver [email protected] VOX: (303) 556-5321 Science Building 134C FAX: (303) 556-5381 http://clem.mscd.edu/~beatys/
Quoted 2 lines · Steve Beaty
... the signal handler fork another child.
Uhh... just read that POSIX actually allows that. Evil! I guess you're entering undiscovered land...
Quoted 13 lines
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.
Quoted 7 lines
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.
Quoted 2 lines
Uhh... just read that POSIX actually allows that. Evil! I guess you're entering undiscovered land...
it's funny how often i am there :-) :-)
Quoted 1 line
No fprintf and exit in a signal handler! Use write and
_exitinstead.
doesn't seem to matter...
Quoted 1 line
This exit is dubious too.
_exitis better.
nor does this... i know better than to use *printf and exit; i was eager to get other's views on this...
Quoted 1 line
Good luck, you may need it - ET.
i do! :-) the code seems to work on Ultrix, Solaris, and OSX. this doesn't imply that it should :-)
Signature · 4 lines
Dr. Steve Beaty (B80) Associate Professor Metro State College of Denver [email protected] VOX: (303) 556-5321 Science Building 134C FAX: (303) 556-5381 http://clem.mscd.edu/~beatys/