I am wondering what happens when a process receives SIGTERM and it has children spawned (e.g. JVM that has /bin/sh commands running).
Is there some sort of automatism or does the parent simply exit and then the children get a SIGTERM too? Do they terminate?

  • Do you mean whatever Linux process (in which case this will depend on how the dev designed the handler) or specifically JVM and its shutdown hooks ?
    – MC68020
    Commented Feb 23 at 16:19

1 Answer 1


What happens when a linux process receives SIGTERM (and, what can incidentally happen to child-processes) is left entirely to the programmer's will.
The process can simply be instructed to ignore (and pursue its business as usual), abruptly die leaving its child-processes orphaned, or execute some in-process built piece of code (the associated software interrupt handler) that can eventually propagate the signal to child-processes or take even greater care.

The Java Virtual Machine has got its own particularities which make so it just cannot stand as an… exempli gratia… ;-)

SIGTERM ? Just ignore ! thanks to the Xrs extra option, other code will handle more appropriately.

Applications embedding the JVM frequently need to trap signals such as SIGINT or SIGTERM, which can lead to interference with the JVM signal handlers. The -Xrs option is available to address this issue. When -Xrs is used, the signal masks for SIGINT, SIGTERM, SIGHUP, and SIGQUIT aren't changed by the JVM, and signal handlers for these signals aren't installed.

What should happen to whatever child ? Well… it'll all depend on the embedding application.

SIGTERM ? Just… shutdown… gracefully !

Any Java Program can attach a shutdown hook to the machine. i.e. code that the JVM should execute before going down. Something as simple as :

public class ShutDownHook 
public static void main(String[] args) 
    Runtime.getRuntime().addShutdownHook(new Thread() 
    public void run() 
        System.out.println("Shutdown Hook is running !"); 
    System.out.println("Application Terminating ..."); 

This enabling the developer to handle ad libitum the termination of whatever child process and even let some of them abruptly die as a consequence of the machine going down.

The JVM (and VMs in general) differ greatly from standard linux processes in that the handling of some signals (and SIGTERM in particular) is likely to be coded (and customized) outside of the virtual's machine internal signal handler. This incidentally enabling this code to run even… if the VM died.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .