test_fork.c
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:1k
- /* ==== test_fork.c ============================================================
- * Copyright (c) 1994 by Chris Provenzano, proven@athena.mit.edu
- *
- * Description : Test fork() and dup2() calls.
- *
- * 1.00 94/04/29 proven
- * -Started coding this file.
- */
- #define PTHREAD_KERNEL
- #include <pthread.h>
- #include <stdio.h>
- #include <fcntl.h>
- main()
- {
- pthread_t thread;
- int flags, pid;
- pthread_init();
- if (((flags = machdep_sys_fcntl(1, F_GETFL, NULL)) >= OK) &&
- (flags & __FD_NONBLOCK | O_NDELAY)) {
- machdep_sys_fcntl(1, F_SETFL, flags & (~__FD_NONBLOCK | O_NDELAY));
- }
- printf("parent process %dn", getpid());
- switch(pid = fork()) {
- case OK:
- exit(OK);
- break;
- case NOTOK:
- printf("fork() FAILEDn");
- exit(2);
- break;
- default:
- if ((flags = machdep_sys_fcntl(1, F_GETFL, NULL)) >= OK) {
- if (flags & (__FD_NONBLOCK | O_NDELAY)) {
- printf("fd flags not set to BLOCKING ERRORn");
- printf("test_fork FAILEDn");
- exit(1);
- break;
- }
- printf("The stdout fd was set to BLOCKINGn");
- printf("child process %dn", pid);
- flags = machdep_sys_fcntl(1, F_GETFL, NULL);
- if (flags & (__FD_NONBLOCK | O_NDELAY)) {
- printf("The stdout fd was reset to O_NDELAYn");
- } else {
- printf("Error: the stdout fd was not resetn");
- printf("test_fork FAILEDn");
- exit(1);
- }
- }
- break;
- }
- printf("test_fork PASSEDn");
- pthread_exit(NULL);
- }