Thursday, 4 December 2014

Program to implement sleep function in UNIX


#include"myHeader.h"
int pid[3];
main()
{
int status;
if(pid[2]==fork())
{
printf("in parent2..\n");
wait(-1,&status,NULL);
if(pid[1]==fork())
{
printf("in parent1..\n");
if(pid[0]==fork())
printf("in parent0..\n");
else
{
sleep(1);
printf("in child0 process(1sec)...\n");
}
}
else
{
sleep(10);
printf("in child1 process(10sec)...\n");
}
}
else
{
sleep(5);
printf("in child2 process(5sec)...\n");
}
}
OutPut:
madan@madan-Lenovo-G570:~/madan/osconcepts$ cc ex24.c
madan@madan-Lenovo-G570:~/madan/osconcepts$ ./a.out
in parent2..
in parent1..
in parent0..
in child0 process(1sec)...
in child2 process(5sec)...
madan@madan-Lenovo-G570:~/madan/osconcepts$ in child1 process(10sec)...