注册 登录
编程论坛 操作系统内核开发

wait隐式函数有什么问题,一直有警告

源哥。。。 发布于 2019-04-27 10:28, 2434 次点击
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>

void waiting(),stop();
int wait_mark;

void main() {
  int p1,p2;
  if (p1=fork()) {                /*创建子进程 p1*/
      if (p2=fork()) {            /*创建子进程 p2*/
         wait_mark=1;
         signal(SIGINT,stop);    /*接收到^c 信号,转 stop*/
         waiting();
         kill(p1,16);            /*向 p1 发软中断信号 16*/
         kill(p2,17);            /*向 p2 发软中断信号 17*/
         wait(0);               /*同步*/
         wait(0);
         printf("Parent process is terminated!\n");
         exit(0);
       }
       else {
           wait_mark=1;   
           signal(SIGINT,stop);
           waiting();
           lockf(1,0,0);
           printf("Child process2 is killed by parent!\n");
           lockf(1,0,0);
           exit(0);
        }
     }
     else  {
         wait_mark=1;
signal(SIGINT,stop);
         waiting();
         lockf(1,0,0);
         printf("Child process1 is killed by parent!\n");
         lockf(1,0,0);
         exit(0);
      }
}
void waiting()  {
while (wait_mark!=0);
}
void stop()  {
wait_mark=0;
}
0 回复
1