如何杀死父进程子进程? [英] How to kill a child process by the parent process?

查看:179
本文介绍了如何杀死父进程子进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建使用叉一个子进程()。父进程如何杀死子进程,如果子进程不能在30秒内完成它的执行?我想允许子进程来执行长达30秒。如果时间超过30秒,父进程将杀死它。你有什么想法,这样做吗?

I create a child process using a fork(). How can the parent process kill the child process if the child process cannot complete its execution within 30 seconds? I want to allow the child process to execute up to 30 seconds. If it takes more than 30 seconds, the parent process will kill it. Do you have any idea to do that?

推荐答案

发送SIGTERM或SIGKILL它:

Send a SIGTERM or a SIGKILL to it:

http://en.wikipedia.org/wiki/SIGKILL

http://en.wikipedia.org/wiki/SIGTERM

SIGTERM是礼貌的,让这个过程收拾它去之前,而,SIGKILL是当那个混蛋不听>:)

SIGTERM is polite and lets the process clean up before it goes, whereas, SIGKILL is for when that bastard won't listen >:)

从shell(手册页例如: http://unixhelp.ed.ac.uk/CGI /人-CGI?杀

Example from the shell (man page: http://unixhelp.ed.ac.uk/CGI/man-cgi?kill )

杀-9 PID

在C,可以使用系统调用杀做同样的事情:

In C, you can do the same thing using the kill syscall:

 kill(pid, SIGKILL);

请参阅以下手册页: http://linux.die.net/man/2/kill

这篇关于如何杀死父进程子进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆