程序如下:
linux操作系统下进程的同步、互斥、撤消...
#include<stdio.h>
#include<signal.h>
#include<unistd.h>
#include<stdlib.h>
int wait_mark;
void waiting(),stop();
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();
kill(p1,16);
kill(p2,17);
wait(0);
wait(0);
printf("parents is killed\n");
exit(0);
}
else {
wait_mark=1;
signal(17,stop);
waiting();
lockf(1,1,0);
printf("P2 is killed by parent\n");
lockf(1,0,0);
exit(0);
}
}
else{
wait_mark=1;
signal(16,stop);
waiting();
lockf(1,1,0);
printf("P1 is killed by parent\n");
lockf(1,0,0);
exit(0);
}
}
void waiting()
{
while(wait_mark!=0);
}
void stop()
{
wait_mark=0;
}
请问这个程序是否实现了互斥???如果没有,那么怎么去改啊。。。
lockf(1,1,0);是怎么实现互斥的啊??后面的参数是什么用。。。
帮我解答一下。。。太蒙了