HC: hello from child
Bye
HP: hello from parent
CT: child has terminated
(or)
HP: hello from parent
HC: hello from child
HC: Bye
CT: child has terminated // this sentence does
// not print before HC
// because of wait.
Bye
// C program to demonstrate working of wait()
#include<stdio.h>
#include<sys/wait.h>
#include<unistd.h>
int main()
{
if (fork()== 0)
printf("HC: hello from child
");
else
{
printf("HP: hello from parent
");
wait(NULL);
printf("CT: child has terminated
");
}
printf("Bye
");
return 0;
}