简体   繁体   中英

How to terminate JVM run from shell script?

I have a shell script starting two java processes. How to ensure that when shell script process is killed, all It's children will be killed too? For example when I try to kill It, java processes remain alive:

kill -9 myscriptID

You can check for all java processes by running this:

ps -aux | grep *java*

This looks like it can help as well.

Your kill command only kills your script, not other processes that it has spawned. Best way to kill all child processes has some great answers for killing the whole tree.

That said, it seems that a better design would be to keep track of the PIDs of the child processes, and rather than sending the parent SIGKILL , send it SIGTERM (or have some other way) to trigger it to gracefully kill its children.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM