int main()
{
int i,pid;
printf("pid : %d \n",pid);
pid=fork();
printf("pid : %d \n",pid);
printf("\n");
if(pid==0)
{
printf("Child starts\n");
for(i=0;i<5;i++)
{
printf("i : %d\n",i);
printf("\n");
}
printf("Child ends\n");
}
else
{
printf("\nBefore wait\n");
printf("getpid : %d\n",getpid());
pid=wait(0);
printf("\npid : %d\n",pid);
printf("After wait\n");
printf("Parent\n");
printf("getpid : %d\n",getpid());
}
}
Output:
[04mca8@LINTEL pp]$ ./a.out
pid : 8884256
pid : 0
Child starts
i : 0
i : 1
i : 2
i : 3
i : 4
Child ends
pid : 23325
Before wait
getpid : 23324
pid : 23325
After wait
Parent
getpid : 23324