-
Notifications
You must be signed in to change notification settings - Fork 2
/
xa.c
35 lines (27 loc) · 827 Bytes
/
xa.c
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
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
int main(){
pid_t pid1, pid2, pid3, pid4,pid5;
printf("Parent of all: %d\n",getpid());
pid1 = fork();
if(pid1 == 0){ // A child Process. Lets say B.
printf("Child with id: %d and its Parent id: %d \n", getpid(),getppid());
pid2 = fork();
if(pid2 == 0){ // A child process. Lets say D.
printf("Child with id: %d and its Parent id: %d \n", getpid(),getppid());
}
pid5 = fork();
if(pid5 == 0){ // A child process. Lets say F.
printf("Child with id: %d and its Parent id: %d \n", getpid(),getppid());
}
}
if(pid1 > 0){
pid3 = fork();
if(pid3 == 0){ // A child process. Lets say C.
printf("Child with id: %d and its Parent id: %d \n", getpid(),getppid());
}
}
for(int i=0; i<3; i++)
wait(NULL);
}