ProcessTreeKiller

This feature is available since 1.260

To reliably kill processes spawned by a job during a build, Hudson contains a bit of native code to list up such processes and kill them. This is tested on several platforms and architectures, but if you find a show-stopper problem because of this, you can disable this feature by setting a Java property named "hudson.util.ProcessTreeKiller.disable" to the value "true".

This can be done as a parameter to the "java" binary when starting Hudson:

 java -Dhudson.util.ProcessTreeKiller.disable=true -jar hudson.war

Depending on how you run your container, this can be different. In the distributed build environment, this system property needs to be set on slave JVMs.

How it works

The ProcessTreeKiller takes advantage of the fact that by default a new process gets a copy of the environment variables of its spawning/creating process.

It sets a specific environment variable in the process executing the build job. Later, when the user requests to stop the build job's process it gets a list of all processes running on the computer and their environment variables, and looks for the environment variable that it initially set for the build job's process.

Every job with that environment variable in its environment is then terminated.

If your build wants to leave a daemon running behind...

A convenient way to achieve that is to change the environment variable BUILD_ID which Hudson's ProcessTreeKiller is looking for. This will cause Hudson to assume that your daemon is not spawned by the Hudson build. For example:

BUILD_ID=dontKillMe /usr/apache/bin/httpd

Labels:

Enter labels to add to this page:
Wait Image 
Looking for a label? Just start typing.
  1. Jan 22, 2009

    David Cate says:

    Does this work if there are multiple Hudson Servers installed on the same machin...

    Does this work if there are multiple Hudson Servers installed on the same machine?

    1. Jan 23, 2009

      Kohsuke Kawaguchi says:

      Yes

      Yes

  2. Mar 25, 2009

    Chad Lyon says:

    Could you provide more details about how this works. For example what is the nam...

    Could you provide more details about how this works. For example what is the name of the shell environment variable that the job process sets? Also, what signal is sent to the process to kill it (on Unix)?

    Suggestion:
    It would be nice to be able to configure the disable property through a context param. For example, I run Hudson through Tomcat and I would like to specify my hudson context like so:

    <Context path="/" docBase="/opt/hudson">
      <Parameter name="hudson.util.ProcessTreeKiller.disable" value="true"/>
    </Context>
    

    BTW, thank you for Hudson