Proper behaviour for wait()?

Paul Herman pherman at frenchfries.net
Fri May 30 22:01:25 PDT 2003


Just curious,

anyone know what the "proper" behavior for wait() is when SIGCHLD
is ignored?  Is it simply undefined?  Don't see anything mentioned
in the wait(2) manpage one way or tother, and other OSes don't seem
to agree much.

-Paul.

bash$ cat wait.c
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>

int main() {
	int status;
	pid_t pid = fork();

	if (!pid) { sleep(1); _exit(0); }

	signal(SIGCHLD, SIG_IGN);
	printf("waitpid() = %d\n", waitpid(pid, &status, 0));
	signal(SIGCHLD, SIG_DFL);
	return 0;
}
bash$ cc wait.c

[FreeBSD 4.8]
bash$ ./a.out
waitpid() = 7553
bash$

[Linux 2.4.21]
bash$ ./a.out
waitpid() = 24536
bash$

[Darwin 6.6]
bash$ ./a.out
waitpid() = -1
bash$

[Solaris 8]
bash$ ./a.out
waitpid() = -1
bash$

[OpenBSD 3.3]
bash$ ./a.out
...just hangs...



More information about the freebsd-hackers mailing list