-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchildtest.c
More file actions
29 lines (26 loc) · 716 Bytes
/
Copy pathchildtest.c
File metadata and controls
29 lines (26 loc) · 716 Bytes
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
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
int main()
{
int i;
pid_t cpid;
pid_t child_pid;
cpid = fork();
switch (cpid) {
case -1: printf("Fork failed; cpid == -1\n");
break;
case 0: child_pid = getpid();
for (i = 0; i < 10; i++) {
printf("%d: this is the child, pid = %d\n", i, child_pid);
sleep(1);
}
exit(0);
default: printf("This is the parent: waiting for %d to finish\n", cpid);
//waitpid(cpid, NULL, 0);
printf("Ttttthat's all, folks\n");
}
return 0;
}