3

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?

3 Answers 3

7

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I've been using screen, maybe you can help with the problem. I am trying to send a command to a detatched process, the manual says to use the -X operator but it doesn't seem to be working. If my screen process ID is 123 and I want to send the command "reboot" to my process what would be the syntax? screen -S 123 -X "reboot" doesn't work.
Aha! That works, thanks. I do have one more issue though. if I want to "emulate" me typing something in using -X how could I do that? This program responds to me typing "hello" but "hello" is an unrecognised command. is there a special character I use to emulate typing?
1

Use GNU screen program.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.