-2
pid_t pid=fork();
printf("%d\n",pid);
if(pid==0){
     sleep(3);
     printf("!");
}
else  
{   
   printf("@");
   read_routine(clnt_sock,buf);
}

On my console, I can see two pid and !, but there is no @.

And when I delete the statement read_routine(clnt_sock,buf);, then I can see @ on console.

In read_routine function, there is just some input statement using fgets().

Are there some secrets of printf?

Toby Speight
  • 23,550
  • 47
  • 57
  • 84

2 Answers2

3

Your output is probably buffered. After the printf, you will likely want to fflush(stdout);.

Toby Speight
  • 23,550
  • 47
  • 57
  • 84
2

Add fflush(stdout) after print and try.

user2026753
  • 495
  • 6
  • 7