After the execution of the below code, the root command line does not appear automatically. If the sleep statements are reversed, then the root command line is displayed.
Why this behavior?
#include<stdio.h>
#include<unistd.h>
int main()
{
if(fork()==0)/*creating fork*/
{
sleep(10);
printf("In child.. %d.\n",getpid());
}
else
{
sleep(5);
printf("In parent.%d ..\n",getpid());
}
}
I wager that the shell prompt does reappear, but before "in child" is written. I suppose the output you see is "In parent", "PROMPT#" and "In child", in that order. – Robᵩ