diff options
author | David Leonard <d@cvs.openbsd.org> | 1999-01-10 22:57:12 +0000 |
---|---|---|
committer | David Leonard <d@cvs.openbsd.org> | 1999-01-10 22:57:12 +0000 |
commit | def0d6c22617b70f7bbe487bbd31c9e3a66c48c8 (patch) | |
tree | e48e5a13d08fc9b1ed5b03a337ca614f0ca6b1d4 /lib/libc_r/TEST/test_fork.c | |
parent | 1eab4be7f1cb7dcddac7544d81551ae75fcb70f8 (diff) |
nice-ify
Diffstat (limited to 'lib/libc_r/TEST/test_fork.c')
-rw-r--r-- | lib/libc_r/TEST/test_fork.c | 70 |
1 files changed, 52 insertions, 18 deletions
diff --git a/lib/libc_r/TEST/test_fork.c b/lib/libc_r/TEST/test_fork.c index 8d44b38c345..efaafb0a7ba 100644 --- a/lib/libc_r/TEST/test_fork.c +++ b/lib/libc_r/TEST/test_fork.c @@ -8,37 +8,71 @@ */ #include <pthread.h> +#include <pthread_np.h> #include <stdio.h> #include <fcntl.h> #include <sys/types.h> #include <unistd.h> +#include <signal.h> +#include <sys/wait.h> #include "test.h" +void * +sleeper(void *arg) +{ + pthread_set_name_np(pthread_self(), "slpr"); + printf("sleeper\n"); + sleep(10); + PANIC("sleeper timed out"); +} + +static void +sigchld(sig) + int sig; +{ + int status; + + ASSERT(sig == SIGCHLD); + CHECKe(wait(&status)); + ASSERT(WIFEXITED(status)); + ASSERT(WEXITSTATUS(status) == 0); + SUCCEED; +} + int main() { int flags; pid_t pid; - extern int _thread_sys_fcntl __P((int, int, ...)); + pthread_t sleeper_thread; - if (((flags = _thread_sys_fcntl(1, F_GETFL, NULL)) >= OK) && - (flags & (O_NONBLOCK | O_NDELAY))) { - _thread_sys_fcntl(1, F_SETFL, flags & ~(O_NONBLOCK | O_NDELAY)); - } - printf("parent process %d\n", getpid()); - - switch(pid = fork()) { - case OK: - exit(OK); - case NOTOK: - printf("fork() FAILED\n"); - exit(2); - default: - printf("child process %d\n", pid); - break; + CHECKe(flags = fcntl(STDOUT_FILENO, F_GETFL)); + if ((flags & (O_NONBLOCK | O_NDELAY))) { + CHECKe(fcntl(STDOUT_FILENO, F_SETFL, + flags & ~(O_NONBLOCK | O_NDELAY))); } - printf("test_fork PASSED\n"); + CHECKr(pthread_create(&sleeper_thread, NULL, sleeper, NULL)); + sleep(1); + + CHECKe(signal(SIGCHLD, sigchld)); - return 0; + printf("forking\n"); + + CHECKe(pid = fork()); + switch(pid) { + case 0: + sleep(1); + printf("child process %d\n", getpid()); + _thread_dump_info(); + printf("\n"); + _exit(0); + PANIC("_exit"); + default: + printf("parent process %d [child %d]\n", getpid(), pid); + _thread_dump_info(); + printf("\n"); + CHECKe(pause()); + PANIC("pause"); + } } |