FAQ
I use exec.Command() to start a child process. After the father process is
killed by "kill -9", the child process still running.

Is there anyway to shutdown child process immediately after father process
die?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Ian Lance Taylor at Apr 15, 2016 at 5:05 am

    On Thu, Apr 14, 2016 at 7:33 PM, Yulei Xiao wrote:
    I use exec.Command() to start a child process. After the father process is
    killed by "kill -9", the child process still running.

    Is there anyway to shutdown child process immediately after father process
    die?
    If you are using GNU/Linux, set the Pdeathsig field of the SysProcAttr struct.

    Otherwise, as far as I know, there is no way.

    Ian

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Konstantin Khomoutov at Apr 15, 2016 at 6:59 pm

    On Thu, 14 Apr 2016 19:33:31 -0700 (PDT) Yulei Xiao wrote:

    I use exec.Command() to start a child process. After the father
    process is killed by "kill -9", the child process still running.

    Is there anyway to shutdown child process immediately after father
    process die?
    In addition to what Ian said, you might consider doing this in some
    other way. First, POSIX defines the concept of "process groups", which
    are used to control processes in groups. Say, shells place all
    processes participating in a pipeline, in the same process groups.
    Each job started by a shell is in its own process group. The main
    feature of a process group is that you're able to send a singal to the
    whole PG. If interested, please check out setpgid(2) and killpg(2)
    manual pages.

    Another, Linux-specific, approach is cgroups (which are gaining
    momentum along with light-weight virtualization, like LXC).
    I have no experience with them but one of their much-touted feature is
    that bringing down a specific cgroup is guaranteed to kill all the
    processes associated with it, and there's no way for a process to
    escape this (as is the case with process groups).

    Of course, all of the above assumes you yourself want to explicitly
    bring the whole hierarchy of the processes you have started. If the
    question was really about taking down the child processes of a process
    someone else killed, then there's no generic solution, I'm afraid.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedApr 15, '16 at 2:33a
activeApr 15, '16 at 6:59p
posts3
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase