sam
sam

Reputation: 5599

Pass command to running java process?

I have a Java process that I run. If I start the process via SSH and pass commands to it works fine, but if I then terminate the SSH session I lose "control" of the process. How can I regain "control" of that process? It's still running.

I know the process ID. Is this possible or must I restart the process?

Upvotes: 3

Views: 861

Answers (3)

aioobe
aioobe

Reputation: 420951

You probably want to start a screen.

Try typing screen at the prompt. (Install the program if you don't have it.)

Example run:

$ ssh yourserver
Password:

$ screen                         # start the screen
$ java -jar YourApp.jar
output...
more output...
<Ctrl-A D>                       # detach process for later reattach
$ exit                           # exit your ssh session

next day

$ ssh yourserver
Password:

$ screen -x                      # reattach process

$ java -jar YourApp.jar
output...
more output...                   # back to where we were yesterday.

Type man screen for more information.

Upvotes: 7

Stephen C
Stephen C

Reputation: 718788

There is no way to reconnect the standard input / output of a process that has become disconnected like that. This is not specific to Java apps.

To avoid getting into this situation, run your application using the screen utility or something similar.

Upvotes: 0

Use GNU screen program.

Upvotes: 1

Related Questions