开发者

Background java process not exiting

I'm starting a java program in background with java what.ever.Class &. It throws an exception in the first line and prints out the stack.

I'd expect the java process to exit at that point, but for some reason it stays there waiting (no code running, not threads spawned, etc.). It's not a zombie, because it exits properly on the first SIGTERM. What might be the reason it doesn't exit immediately?

Added:

Actually that doesn't happen every time. If I run the command from the command line - it exits just fine. If the same command is run from a script (the script is just #!/bin/sh / java what.ever.Class &) then it stays in the background.

nohup and redirections don't wor开发者_如何学运维k.

Using Debian, OpenJDK Runtime Environment (IcedTea6 1.6.1) (6b16-1.6.1-2) / OpenJDK 64-Bit Server VM (build 14.0-b16, mixed mode). The sh is actually dash.


Can you check whether it is in a stopped state waiting for input or output?

If yes, then try redirecting input, output, and errors if you don't need them:

java what.ever.Class </dev/null &>/dev/null &

or into a file if you need them:

java what.ever.Class </dev/null &>outputfile &

or via nohup if you need the outputs and want the process to keep running even after you log out:

nohup java what.ever.Class </dev/null &
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜