Hi,
I see that SIGCHLD which was sent before calling sigaction() for
SIGCHLD is delivered to the handler when program is linked to
libpthread.so. However, this behavior doesn't occur when program
isn't linked to libpthread.so.
I feel the behavior of SIGCHLD when linked to libpthread.so
is strange, but I don't know whether the behavior is correct
or not.
Can anyone tell me what happened?
Best Regards,
Jun Kawai
------------------------------------------------------------------
% dmesg | head -2
OpenBSD 4.6-stable (GENERIC.MP) #0: Sat Dec 5 10:35:10 JST 2009
kwj@cask.komos.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP
% cat SIGCHLD-test.c
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
void trap(int);
void puts_curtime(void);
int
main(int argc, char *argv[])
{
pid_t pid;
struct sigaction act, oact;
puts_curtime();
pid = fork();
if (pid == 0) {
sleep(1);
_exit(0);
} else if (pid == -1) {
exit(1);
} else {
int status;
waitpid(pid, &status, 0);
}
puts_curtime();
sleep(5);
puts_curtime();
sigemptyset(&act.sa_mask);
act.sa_handler = trap;
act.sa_flags = 0;
if (sigaction(SIGCHLD, &act, &oact) != 0) {
exit(1);
}
sleep(5);
if (sigaction(SIGCHLD, &oact, (struct sigaction *) 0) != 0) {
exit(1);
}
puts_curtime();
exit(0);
}
void
trap(int sig)
{
printf("Received SIGCHLD - ");
puts_curtime();
return;
}
void
puts_curtime(void)
{
time_t tloc;
time(&tloc);
puts(ctime(&tloc));
return;
}
% cc -Wall -o SIGCHLD-test SIGCHLD-test.c
% cc -Wall -pthread -o SIGCHLD-test-thread SIGCHLD-test.c
% ldd ./SIGCHLD-test ./SIGCHLD-test-thread
./SIGCHLD-test:
Start End Type Open Ref GrpRef Name
0000000000400000 0000000000802000 exe 1 0 0 ./SIGCHLD-test
000000020d2b6000 000000020d795000 rlib 0 1 0 /usr/lib/libc.so.51.0
0000000201c00000 ...