Java process launched from another Java process without & does not work properly

Suppose there are several Java projects whose task is to run other Java processes. The procedure is similar to the following:

String[] command = { "/bin/sh", "-c", "some.sh" + " &"};
Process pro = Runtime.getRuntime().exec(command);
//rest

This first option works because &, and this other one does not work:

String[] command = { "/bin/sh", "some.sh"};
Process pro = Runtime.getRuntime().exec(command);
//rest

Q: What is the meaning of "this does not work"? A: Both options start the process, but in the second case, the child process stops working after a few seconds, however, if I check the running processes ( ps aux | grep some.sh), it is (but does nothing). The first option works fine, it starts the process, and the child performs his task.

I don’t understand why, when I start a child process without a background, it appears as active in the process list ps, but does nothing.

+3
1

Unix & , . , , , , , , , .

, , , , , - ​​ &. , some.sh . , , .

Apache Tomcat , ( Unix daemon). shutdown hookdown, , :

private volatile boolean shutdown = false;

...

Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
        // What to run on shutdown
        shutdown = true;
    }
});

, - ( , , ):

while(!shutdowwn) {
    // Perform action here every 1000 milliseconds.
    Thread.sleep(1000);
}

Apache Tomcat Windows Linux/Unix. , !

+1

All Articles