Its Saturday morning and thought to work on something good.And I am stuck up with a very small problem but for unknown reason.Please do make my morning cheerful by solving this.
I used sleep function in my program and used a printf statement before invoking sleep function to my surprise the program is sleeping before it invokes printf.Here is the code....
#include<unistd.h>
#include<stdio.h>
#include<sys/types.h>
int main(){
pid_t pt;
printf("ging to while loop");
printf("im sleeping");
sleep(1);
printf("im awoke");
}
Is my computer forsee my sleep function and sleeping before?
Another surprising thing i saw is using newline makes it sleep after invocation of first line.That is its working correctly.
Please explain me such weird behaviour?
Its sleeping before printf invocation.And then printing all the three results at a time.Please do help PS:LINUX(UBUNTU 14.04),GCC COMPILER