blob: 4c2125e678a3480a3cda63a36c1e1cc173c4724e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
/* ==== 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 %d\n", getpid());
switch(pid = fork()) {
case OK:
exit(OK);
break;
case NOTOK:
printf("fork() FAILED\n");
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 ERROR\n");
printf("test_fork FAILED\n");
exit(1);
break;
}
printf("The stdout fd was set to BLOCKING\n");
printf("child process %d\n", pid);
flags = machdep_sys_fcntl(1, F_GETFL, NULL);
if (flags & (__FD_NONBLOCK | O_NDELAY)) {
printf("The stdout fd was reset to O_NDELAY\n");
} else {
printf("Error: the stdout fd was not reset\n");
printf("test_fork FAILED\n");
exit(1);
}
}
break;
}
printf("test_fork PASSED\n");
pthread_exit(NULL);
}
|