-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask1.c
More file actions
41 lines (32 loc) · 650 Bytes
/
task1.c
File metadata and controls
41 lines (32 loc) · 650 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
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
void taskA() {
int n = 7;
for (int i = 0; i < n; i++) {
if (fork() == 0) exit(0);
}
for (int i = 0; i < n; i++) {
wait(NULL);
}
}
void taskB() {
int n = 12;
for (int i = 0; i < n; i++) {
if (fork() == 0) {
printf("[Child] pid %d \n", getpid());
exit(0);
}
}
for (int i = 0; i < n; i++) {
wait(NULL);
}
printf("%d child processes have been created\n", n);
}
int main(void) {
taskA();
taskB();
return EXIT_SUCCESS;
}