-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwait.c
More file actions
29 lines (23 loc) · 649 Bytes
/
wait.c
File metadata and controls
29 lines (23 loc) · 649 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
#include<stdio.h> // fro print statement
#include<unistd.h>//for fork()
#include<stdlib.h>
#include<sys/wait.h>
int main()
{
pid_t pid; //pid_t is a signed integer type which is capable of representing a process ID
pid=fork(); //fork return 0 for child process & return 1 or more for parent process ,-1 for error
int status;
if(pid==0)
{ printf("child process :%d\n",getpid());
sleep(5);
exit(0);
}
else
{
printf("parent process: %d\n",getpid());
wait(&status);
printf("exit status %d",WEXITSTATUS(status));
}
return 0;
}
//parent process runs first then child process