由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Unix版 - FreeBSD: Can't kill child process!
相关主题
A problem about child process.how to fork a subroutine in unix?
kill init process"fork" program question.
Help please! 怎么keep当前还在运行的child processhow to kill a process in emacs?
fork() and execve() in Unixhow to record the process end time in a child process and obtain it in the parent process?
can't run a simple c codehow to kill process?
同时运行sshd和rshd关于nohup的问题
how to kill a login?在UNIX里,怎么stop a set of processes?
求助:ps的参数关于cxterm的问题
相关话题的讨论汇总
话题: child话题: process话题: kill话题: pid话题: 4726
进入Unix版参与讨论
1 (共1页)
n***l
发帖数: 9
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.
T********r
发帖数: 6210
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) {

1 (共1页)
进入Unix版参与讨论
相关主题
关于cxterm的问题can't run a simple c code
怎样在UNIX命令行执行一个perl语句?同时运行sshd和rshd
一个关于命令行的小问题how to kill a login?
[转载] 用cat看到的命令行输入M-BM-7是什么东西?求助:ps的参数
A problem about child process.how to fork a subroutine in unix?
kill init process"fork" program question.
Help please! 怎么keep当前还在运行的child processhow to kill a process in emacs?
fork() and execve() in Unixhow to record the process end time in a child process and obtain it in the parent process?
相关话题的讨论汇总
话题: child话题: process话题: kill话题: pid话题: 4726