[英]How to signal from parent process to the child?
How can i send signal from parent process to the child? 如何从父进程向孩子发送信号? After i write to the pipe i want to send signal to the child process.
写完管道后,我想向子进程发送信号。
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.
}
kill(PID, SIGwhatever);
however this is probably a poor choice; 但是,这可能是一个糟糕的选择。 the better solution is
更好的解决方案是
close(filds[1]);
and handle close of input in the child. 并处理关闭孩子的输入。 I think you're missing a
我想你想念一个
dup2(files[0],0);
in the child path as well. 在子路径中也是如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.