-
Notifications
You must be signed in to change notification settings - Fork 0
/
fork.c
38 lines (32 loc) · 886 Bytes
/
fork.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
37
38
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
int main()
{
int id;
printf("BEFORE FORK::\n");
printf("MAIN PROCESS ID::%d\n",getpid());
//printf("MAIN PROCESS PARENT'S ID::%d\n",getppid());
printf("\nBEFORE FORK::\n");
id=fork();
printf("\nID=%d\n",id);
if(id==0)
{
printf("\nCHILD PROCESS RUNNING::\n");
printf("CHILD ID::%d\n",getpid());
printf("CHILD'S PARENT::%d\n",getppid());
printf("CHILD IS SLEEPING\n");
sleep(50);
printf("CHILD WAKE UP\n");
}
else
{
printf("\nPARENT PROCESS IS RUNNING::\n");
printf("PARENT ID::%d\n",getpid());
//printf("PARENT's PARENT ID::%d\n",getppid());
printf("PARENT IS SLEEPING\n");
sleep(50);
printf("\nPARENT WAKE UP\n");
}
printf("\nAFTER FORK::\n");
}