-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6aZ.c
36 lines (36 loc) · 1019 Bytes
/
6aZ.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 <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
void main()
{
pid_t ppid, mypid, child_pid;
child_pid = fork();
if (child_pid < 0)
{
printf("Fork Failed\n");
exit(0);
}
if (child_pid == 0)
{
mypid = getpid();
ppid = getppid();
printf("[CHILD] Child Executing\n");
printf("[CHILD] My PID = %d\n", mypid);
printf("[CHILD] My Parent PID = %d\n", ppid);
printf("[CHILD] Child Exiting\n");
exit(0);
}
else
{
mypid = getpid();
ppid = getppid();
printf("[PARENT] Parent Executing\n");
printf("[PARENT] My PID = %d\n", mypid);
printf("[PARENT] My Parent PID = %d\n", ppid);
printf("[PARENT] Parent Sleeping for 10 seconds\n");
sleep(10);
printf("[PARENT] Child with PID = %d Exited but its entry is still in Process table\n", child_pid);
execlp("/bin/ps","ps",NULL);
}
}