LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices



Reply
 
Search this Thread
Old 04-27-2009, 09:57 AM   #1
sploit
LQ Newbie
 
Registered: Dec 2004
Posts: 24

Rep: Reputation: 15
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?
 
Old 04-27-2009, 10:03 AM   #2
SlowCoder
Member
 
Registered: Oct 2004
Location: Southeast, U.S.A.
Distribution: Fedora (Desktop), CentOS (Server), Knoppix (Diags)
Posts: 934

Rep: Reputation: 38
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.
 
Old 04-27-2009, 10:05 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
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).
 
Old 04-27-2009, 10:39 AM   #4
SlowCoder
Member
 
Registered: Oct 2004
Location: Southeast, U.S.A.
Distribution: Fedora (Desktop), CentOS (Server), Knoppix (Diags)
Posts: 934

Rep: Reputation: 38
So, would that mean his command was ended on session disconnect?
 
Old 04-27-2009, 10:48 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
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.
 
Old 04-27-2009, 11:12 AM   #6
CarLost
Member
 
Registered: Jun 2004
Location: Sentado en mi trasero en Chile
Distribution: ArchLinux
Posts: 45

Rep: Reputation: 16
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
 
Old 04-27-2009, 12:09 PM   #7
sploit
LQ Newbie
 
Registered: Dec 2004
Posts: 24

Original Poster
Rep: Reputation: 15
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?
 
Old 04-27-2009, 12:23 PM   #8
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Running a process decoupled from SSH connection? tim-f Linux - Newbie 4 07-10-2008 04:34 AM
Howto get the output of a running process using ssh? agouz Linux - Software 3 12-26-2005 01:11 PM
SSH connection termination during a running process... jayemef Linux - General 1 08-16-2005 12:41 PM
SSH Login - Forcing keys! jackster Linux - Security 5 01-25-2005 09:09 AM
Please help easy questions, how do I stop a process from running in SSH? lexington Linux - Newbie 3 05-01-2004 01:03 PM


All times are GMT -5. The time now is 03:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration