-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexp3fork1.c
36 lines (34 loc) · 924 Bytes
/
exp3fork1.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
36
#include<stdio.h>
#include<unistd.h>
int main()
{
int x;
x = fork();
if(x==0)
{
printf("C1 PID = %d Parent = %d\n ", getpid(), getppid());
x = fork();
if(x==0)
{
printf("C3 PID = %d Parent = %d\n", getpid(), getppid());
}
else if(x>0)
{
x = fork();
if(x==0)
{
printf("C4 PID = %d Parent = %d\n", getpid() , getppid());
}
}
}
else if(x>0)
{
printf("P PID = %d\n ", getpid());
x =fork();
if(x==0)
{
printf("C2 PID = %d Parent = %d\n", getpid(), getppid());
}
}
return 0;
}