-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBS2.c
More file actions
44 lines (33 loc) · 790 Bytes
/
BS2.c
File metadata and controls
44 lines (33 loc) · 790 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main(int argc, char* argv[])
{
pid_t pid;
for(int i = 1; i < 17; i++)
{
pid = fork();
if(pid < 0)
{
perror("Execvp error");
}
if(pid == 0)
{
printf("[%d] I am the child: %d\n", i, getpid());
exit(0);
}
else
{
printf("Waiting for childs to execute...\n");
wait(NULL);
}
}
printf("All 16 childs have been created!\n");
/* The order is always "Waiting" then "child" and this 16 times, where as the child process prints its ID which is increased
by one every time it gets printed on the terminal. */
/* I think the order of the messages can be predicted. */
/* It think it depends on the OS */
return EXIT_SUCCESS;
}