How to kill a child process by the parent process?

前端 未结 3 1929
野的像风
野的像风 2020-12-08 04:32

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?

3条回答
  •  鱼传尺愫
    2020-12-08 05:09

    Send a SIGTERM or a SIGKILL to it:

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

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

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

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

    kill -9 pid

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

    kill(pid, SIGKILL);
    

    See the following man page: http://linux.die.net/man/2/kill

提交回复
热议问题