- 论坛徽章:
- 0
|
有一源程序:
#include <stdio.h>;
#include <signal.h>;
#include <unistd.h>;
void waiting(),stop();
int wait_mark;
main()
{
int p1,p2;
while((p1=fork())==-1);
if(p1>;0)
{
while((p2=fork())==-1);
if(p2>;0)
{
wait_mark=1;
signal(SIGINT,stop);
waiting(0);
kill(p1,16);
kill(p2,17);
wait(0);
wait(0);
printf("parent process is killed!\n" ;
exit(0);
}
else
{
wait_mark=1;
signal(17,stop);
waiting();
lockf(stdout,1,0);
printf("child process 2 is killed by parent!\n" ;
lockf(stdout,0,0);
exit(0);
}
}
else
{
wait_mark=1;
signal(16,stop);
waiting();
lockf(stdout,1,0);
printf("child process 1 is killed by parent!\n" ;
lockf(stdout,0,0);
exit(0);
}
}
void waiting()
{
while (wait_mark!=0);
}
void stop()
{
wait_mark=0;
}
这个程序是教材上的,我刚学操作系统是个菜鸟,不明白为什么它运行不起来,请高手指教~或许书上哪里错了什么吧~~~ ![](static/image/smiley/default/icon_mrgreen.gif) |
|