fork程序问题
最近在学习linux的进程编程,做了个小程序,程序如下:
----------------
void main(){
int i;
printf("This is header!\n");
if ( fork() == 0 ) {
/* 子进程程序 */
for ( i = 1; i < 3; i ++ )
printf("This is child process\n");
}
else {
/* 父进程程序*/
for ( i = 1; i < 4; i ++ )
printf("This is process process\n");
}
}
-------------
结果如下:
This is header!
This is child process!
This is header!
This is father process!
This is father process!
This is child process!
This is father process!
This is child process!
--------------------------
不知道为什么?执行过程到底是怎样的啊?
第一行的This is header!是在父进程中执行的还是在子进程?
-----------------
还请各位高手不吝赐教!