-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3a.c
More file actions
34 lines (30 loc) · 630 Bytes
/
3a.c
File metadata and controls
34 lines (30 loc) · 630 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
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
int main(void)
{
char cmd[20];
int status;
int a = fork();
if(a == 0)
{
printf("This is child process\n");
printf("Child process id: %d\n", getpid());
printf("Parent process id: %d\n", getppid());
printf("Enter the command: ");
scanf("%s", cmd);
system(cmd);
}
else
{
wait(&status);
printf("This is parent process\n");
printf("Grandparent process id: %d\n", getppid());
printf("Parent process id: %d\n", getpid());
printf("Child status: %d\n", status);
}
return 0;
}