#include<stdio.h>
#include<unistd.h>
#include <stdlib.h>
int main() {
int n = 3; //How many child process to create from 1 parent?
printf("parent process running, pid of the parent process is
%d\n",getpid());
for(int i=0; i<n; i++) {
pid_t return_value;
return_value = fork();
if(return_value <0){
printf("fork() has failed during child creation");
exit(1);
}
else if(return_value == 0){
printf("Child created successfully,at the instance child process is running on CPU, pid of the child process is %d\n", getpid());
exit(0);
}
}
for(int i=0; i<n; i++){
//Parent process waits for child process to finish execution
int status;
wait(&status);
}
printf("parent process running again after creation of 3 child, pid of the parent process is %d\n", getpid());
return 0;
}
/*>Output
parent process running, pid of the parent process is 732
Child created, pid of the child process is 736
Child created, pid of the child process is 738
Child created, pid of the child process is 737
*/