[26] in Pthreads mailing list archive
No subject found in mail header
daemon@ATHENA.MIT.EDU (steven dake)
Mon Jun 26 10:43:10 1995
Date: Tue, 27 Jun 1995 06:22:34 -0700
From: steven dake <scd@broked.org>
To: pthreads@MIT.EDU
Below is a typescript of a test program I wrote which encompasses a
problem/bug/misunderstanding_by_me:) of pthreads. The program is supposed
to fork(), then wait() for the child process to exit. This works fine under
any normal unix, but building with the pthreads library appears to have
problems.
time without pthreads = 5secs, time with pthreads = 0 seconds (more or less).
(.31 for overhead)
The peculiar thing is, the child process appears to exit. Why is the child
exiting with a 1?
Analyzing via strace reveals:
sigaction(SIGCHLD, {0x4a18, [], SA_RESTART}, NULL) = 0
sigaction(SIGCHLD, {SIG_DFL}, {0x4a18, [CHLD], SA_RESTART}) = 0
getpid() = 11366
kill(11366, SIGCHLD) = 0
sigaction(SIGCHLD, {0x4a18, [], SA_INTERRUPT|SA_NOMASK|SA_ONESHOT}, {SIG_DFL}) =
0
sigreturn() = ? (mask now [])
which shows that the parent is being sent a signal (11366 is the parents pid)
of SIGCHLD and this is killing the child. I don't understand the internals
of pthreads to know what is going on, but if anyone has any information, or
can tell me how I can implement this in a pthreads-friendly manner, I'd really
appreciate it.
Also, while I'm on the topic :), user-set signals do not appear to be
functioning properly for me.
PS: during setup, the configure script decided that linux doesn't have alot
of system calls that it really does (such as bind, wait, etc as it is not
defined in syscall.h) so I hacked the config.cache file to make it think the
proper system calls were present. Would doing this have the above effect?
Was hacking the config.cache the right thing to do?
Script started on Tue Jun 27 05:40:19 1995
broked:/usr/local/pthreads> uname -a
Linux broked 1.2.8 #1 Wed Apr 13 12:41:23 MST 1994 i486
broked:~/pthread_test> gcc -g main.c -o nopthread
broked:~/pthread_test> gcc -g main.c -L/usr/local/pthreads/lib -lpthread -o yespthread
broked:~/pthread_test> time nopthread
waiting for process to finish
ready to sleep for 5 seconds
done sleeping
IF EXITED = 1, status = 5
IF SIGNALED = 0
0.000u 0.070s 0:05.31 1.3% 0+0k 0+0io 21pf+0w
broked:~/pthread_test> time yespthread
waiting for process to finish
ready to sleep for 5 seconds
IF EXITED = 1, status = 1
IF SIGNALED = 0
0.030u 0.150s 0:00.31 58.0% 0+0k 0+0io 32pf+0w
broked:~/pthread_test> exit
Script done on Tue Jun 27 05:42:02 1995
program main.c begins
/*
* main.c program to show bug in pthreads 1.60b3 (?)
*
* Copyright (C) 1995
* Steven C. Dake (scd@broked.org)
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
int sd;
int main (void) {
int pid;
int status;
if ((pid = fork ()) < 0) {
perror ("fork failed in main(!)\n");
exit (1);
}
/*
* child process
*/
if (pid == 0) {
printf ("pid = %d\n", getpid());
printf ("ready to sleep for 5 seconds\n");
fflush (stdout);
sleep (5);
printf ("done sleeping\n");
fflush (stdout);
exit (5);
}
sleep (1);
/*
* parent process, wait until child is completed
*/
printf ("waiting for process to finish\n");
if (wait (&status) < 0) {
perror ("wait failed");
exit (1);
}
printf ("IF EXITED = %d, status = %d\n",
WIFEXITED (status), WEXITSTATUS (status));
printf ("IF SIGNALED = %d\n", WIFSIGNALED (status));
}
Thanks for any details on this problem that anyone can offer.
-steve (scd@broked.org)