Assignment 2 os
Assignment 2 os
3. wait() : This causes the parent process to block until the child
process terminates. The argument “NULL” means we don’t care
about the exit states of the child. For wait() we need to include
<sys/wait.h> header file.
Program:
#include<stdio.h>
#include<unistd.h>
#include<sys/wait.h>
#include<stdlib.h>
if(pid ==0)
{
printf("Hello from child process=%d\n", getpid());
sleep(2);
execvp(argv[1],&argv[1]);
perror("execvp failed");
sleep(2);
exit(1);
printf("\nChild process completed");
}
else
{
printf("\nHello from child process=%d", getpid());
printf("\nWaiting for child process to complete");
wait(NULL);
printf("\nChild process is completed");
}
}
Output: