LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Forcing SSH Process to continue running (https://www.linuxquestions.org/questions/linux-networking-3/forcing-ssh-process-to-continue-running-721990/)

sploit 04-27-2009 08:57 AM

Forcing SSH Process to continue running
 
I hope this is the right forum.
I was running a large program on a remote SSH server the other day when I was disconnected. This is a large program, ~48 hours to complete, and I was disconnected around hour 40. I have restarted the program using the following (Note: I am already ssh'd into the server)
./20090427_9crossing > 20090427_9crossing.out &

Now, I believe this will run the program in the background and output to the file. So, if I get disconnected again will it continue to run? If not, is there a way that I can get it to keep running?

SlowCoder 04-27-2009 09:03 AM

I believe you've detached the command from your terminal with the ampersand (&), so I think you should be fine. You can log back into the machine and check to see if your process is still running with the ps command.

druuna 04-27-2009 09:05 AM

Hi,

The ampersand puts your command in the background, it doesn't detach it from the terminal. Use nohup to accomplish that.

nohup command &

Output that is created by the command is written to a file (in the dir you started the command).

SlowCoder 04-27-2009 09:39 AM

So, would that mean his command was ended on session disconnect?

druuna 04-27-2009 09:48 AM

Hi,

The OP did not give any details, there could be a lot of (deliberate: security!) reasons why the session was closed: A time limit on idle ssh sessions or idle logins are at the top of my 'probably' list ;)

The command I gave (nohup command &) will avoid stopping the program from running when the shell is detached, not the disconnect itself. After the nohup command you can log out and the command will keep running until it is done.

CarLost 04-27-2009 10:12 AM

Hi...
Also you can run "screen" to manage severals shells.
"screen" to start it
[ctl] (a , c) to create a new shell (sequence)
[ctl] (a , n) to go the next shell
[ctl] (a , d) to detach

"screen -rd" to retake the last (n) session(s)

regards

sploit 04-27-2009 11:09 AM

To clarify: there is not a time limit or idle close, as these boxes are dedicated to running large programs. When using nohup, it seems that if I close the shell and then reopen it the command has stopped. My problem is when my network (at home) goes down, as my ISP sucks, is there a way to keep the program going?

druuna 04-27-2009 11:23 AM

Hi,

The nohup command does what you want:

After logging in remotely start your command with: nohup whatever.the.command &
You should get the prompt back and a message from nohup, something like this:
Quote:

[1] 20299
nohup: appending output to `nohup.out'
After logging out and back in again the program should still run (if it hasn't finished).
Check with ps -ef | grep whatever.the.command. You can also check the nohup.out file in real time (if your program outputs anything that is) with tail -f nohup.out

This solution solves your connection problem as well.


All times are GMT -5. The time now is 08:44 PM.