7 static pthread_t tid
[2];
9 static void *startproc(void *arg
)
12 char *argv
[] = { "/bin/ls", "/bin/ls", NULL
};
14 if ((pid
= fork()) == -1) {
16 } else if (pid
== 0) {
17 dup2(2, 1); // redirect stdout to stderr
18 execv(argv
[0], argv
); // child
24 int main(int argc
, char **argv
)
26 // No arguments means serialize the fork() calls. One argument means perform
27 // both fork() calls concurrently.
28 int serialize_fork
= argc
== 1;
32 for (i
= 0; i
< 2; i
++) {
33 err
= pthread_create(&tid
[i
], NULL
, &startproc
, NULL
);
35 perror("pthread_create()");
37 pthread_join(tid
[i
], NULL
);
39 if (!serialize_fork
) {
40 for (i
= 0; i
< 2; i
++)
42 pthread_join(tid
[i
], NULL
);