|

楼主 |
发表于 2004-5-15 10:29:53
|
显示全部楼层
我看了好多的书,都是如下写的:
____________________________________
void main()
{
int i;
if ( fork() == 0 ) {
/* 子进程程序 */
for ( i = 1; i <1000; i ++ )
printf("This is child process\n");
}
else {
/* 父进程程序*/
for ( i = 1; i <1000; i ++ )
printf("This is process process\n");
}
}
程序运行后,你就能看到屏幕上交替出现子进程与父进程各打印出的一千条信息了。如果程序还在运行中,你用ps命令就能看到系统中有两个它在运行了。
_____________________________________
但是,我在编译这个程序的时候出现如下警告错误:
──────────────────────
ttr.c: In function `main':
ttr.c:2: warning: return type of `main' is not `int'
──────────────────────
然后,运行结果也不是象书上所说的,
而是先打印出999行“This is child process”
再打印出999行“This is process process”
或者先打印出999行“This is process process”
再打印出999行“This is child process”
哪位能给我解决一下这个问题,我先谢谢了!! |
|