LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Running a process decoupled from SSH connection? (https://www.linuxquestions.org/questions/linux-newbie-8/running-a-process-decoupled-from-ssh-connection-654790/)

tim-f 07-10-2008 03:04 AM

Running a process decoupled from SSH connection?
 
Hello,

I try to run a Java application on a remote Linux machine (debian 2.6.18-5-amd64) using SSH. The problem is that the task takes a lot of time to complete (typically more than 24h), and connection to the server is often lost during this time. I wonder if it is possible to run a process that is decoupled from my SSH session so that loosing the connection wouldn't terminate the process?

I have read about background processes, but this seems to be irrelevant in this case, because it just allows to run several processes in one session.

Thanks for any help!

Mr. C. 07-10-2008 03:13 AM

Run the program with nohup and place in background. See man nohup.

Alterntiavely, you can use screen. See man screen.

matthewg42 07-10-2008 03:14 AM

Running with nohup and putting the procecss in the background will prevent it from dying when you log off your ssh session.

The only problem with this is that you cannot interact with the process again using a terminal. If you need to do that then you can use GNU Screen:
  1. Log in with ssh
  2. Start a screen session by using the command screen
  3. Run your java process
  4. Press 'Control-a' then 'd'. This will detach the screen session from the terminal.
  5. Log off your ssh session
  6. At some later time, log back in with ssh
  7. Enter the command: screen -r to reconnect to the detached screen session
  8. If the process is still going, goto step 5, else continue to the next step.
  9. Have a cup of tea

tim-f 07-10-2008 03:20 AM

Thanks
 
Thanks a lot, it is exactly what I was looking for!

matthewg42 07-10-2008 03:34 AM

Screen is an awesome program. IMO the key bindings are a little quirky and can be difficult to remember at first, but it's still really useful.

You can re-define the keys and change other settings using a .screenrc file in your home directory. For example, you can set a large scrollback buffer by adding this to your .screenrc file:
Code:

defscrollback 5000


All times are GMT -5. The time now is 10:32 PM.