views:

248

answers:

1

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 work.

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.

+1  A: 

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 &
Bandi-T
Unfortunately none of them work. I added more info to the question.
viraptor
@viraptor: Just to make sure it is not the Java implementation, could you try again on another Java implementation?
Bandi-T