如何从父进程向孩子发出信号?

时间:2019-06-06 19:07:41

标签: c linux

我如何从父进程向孩子发送信号? 写完管道后,我想向子进程发送信号。

 pid_t pid;
     int filds[2];
     pipe(filds);
     char *args[150] = {"./draw.out", NULL};
     char buff = '\0';

     if ((pid = fork()) < 0) {  // fork a child process/
         printf("*** ERROR: forking child process failed\n");
         exit(1);
     } else if (pid == 0) {
         execvp(args[0], args); // execute the command
     } else {  // for the parent
         char btnPressed = getch();

         while (btnPressed != 'q'){
             btnPressed = getch();
             write(filds[1],buff, BUFF_SIZE); 
             //signal
         }
         // signal finish game.
     }

1 个答案:

答案 0 :(得分:0)

kill(PID, SIGwhatever);

但这可能是一个糟糕的选择;更好的解决方案是

close(filds[1]);

并处理子项中输入的关闭。我想你想念一个

dup2(files[0],0);
在子路径中也是

相关问题