I use ubuntu 14.04 version system for below code. I use below code : (below code is infinite Loop)
#include <stdio.h>
#include <unistd.h>
int flag=0;
int main(void){
printf("program start.\n");
printf("PID=%d\n",getpid());
printf("flag=%d\n",flag);
//-----------I feel weired below do...while... sentences----------//
do{
printf("loop_");
sleep(1);
}while(flag==0);
printf("program exit.\n");
return 0;
}
in the beginning below print result :
root@ubuntu:~/Desktop/my_test_code# ./issue
program start.
PID=3113
flag=0
...........//start waiting here,and don't print "loop_"
then after I waited for long time this program prints a lot of "loop_". I find it very strange, and should print a string "loop_" and then, wait a second, then print a "loop_" again, and so on, why me waiting for a long time, do it start to print a lot of "loop_" ?
anybody has any idea for my issue . thank you in advance.