Redian新闻
>
FreeBSD: Can't kill child process!
avatar
FreeBSD: Can't kill child process!# Unix - 噫吁兮,危乎高哉
n*l
1
我有下面简单的code
pid = fork();
if (pid == 0) {
printf("Child process running\n");
} else if (pid < 0) {
printf("Failed on fork()\n");
exit(0);
} else {
... ...
if (kill(pid, SIGKILL) < 0) {
perror("Failed on kill()");
}
while(1){ ... ... };
}
运行后发现kill失败了。比如Child process的PID是4726,
在命令行“ps 4726”,结果是空的。但是用“ps”可以看到
child process。在命令行用“kill -9 4726”,系统报
错:No such process。
谁知道这到底是怎么会事?Thanks.
avatar
T*r
2
What's the code after that else {/*parent process*/}? If there's no
code after that, the child process will exit and become zombie after
the printf statement. You cannot kill the child process any more. To
exit the child process cleanly, you should call wait() in parent
process. To kill the child process, you should let child alive, i.e.
sleep infinitely.

【在 n***l 的大作中提到】
: 我有下面简单的code
: pid = fork();
: if (pid == 0) {
: printf("Child process running\n");
: } else if (pid < 0) {
: printf("Failed on fork()\n");
: exit(0);
: } else {
: ... ...
: if (kill(pid, SIGKILL) < 0) {

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。