分页: 1 / 1

有关进程的问题

发表于 : 2009-03-31 19:14
cihaiwan
#include <stdio.h>
#include<stdlib.h>
#include <unistd.h>
int main(void)
{
pid_t pid;
printf("Process Creation Study\n");
pid = fork();
switch(pid) {
case 0:
// 情况(1) //sleep(3);
printf("Child process is running,CurPid is %d, ParentPid is %d\n", pid, getppid());
情况 (2) //sleep(3);
break;
case -1:
perror("Process creation failed\n");
break;
default:
printf("Parent process is running,ChildPid is %d, ParentPid is %d\n", pid, getpid());
break;
}
exit(0);
}
这个程序为什么条件default不受sleep()这个函数影响 加了情况(1)结果是先输出default中的内容 过3秒输出case 0中内容,按理说先等3秒输出case0中内容 最后才是输出default 加了情况(2)先输出case0中内容马上输出default内容 应该是先等3秒才输出default 先谢了!!!!字体不知道怎么加大 :em09

Re: 有关进程的问题

发表于 : 2009-04-01 19:23
cihaiwan
自己顶下 解释起来麻烦的话请介绍本书 要中文的 英文的看不懂