LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-18-2007, 05:57 PM   #1
nuxeon
LQ Newbie
 
Registered: Jul 2007
Posts: 6

Rep: Reputation: 0
Jobs IDs go away on ssh restart


Hi there,
I am trying to start a wget command(remotley using ssh) in background using & and nohup. When I start the command and run the jobs command it shows up as running in the background. When I restart my ssh session and use the job command to get back to it, the job is no longer listed. I just want to check in on the status of the download. Is there any way to get back to that job.
 
Old 10-18-2007, 06:07 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
For the odd occasion where nohup won't work, use screen.


Cheers,
Tink
 
Old 10-18-2007, 06:08 PM   #3
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,125

Rep: Reputation: 164Reputation: 164
Ending the ssh session kills the running subprocesses. You can use the screen or nohup commands to have a task run in the background in between sessions.
 
Old 10-18-2007, 06:46 PM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
When you background things from an shell, they get allocated job IDs which are something internal to that shell. The process ID (pid) is system wide, and should be visible even after the shell terminates.

In the case of bash, when you start a program in the background, it tells you both the shell's job ID and the pid of the process which has been started, like this:
Code:
% sleep 500 &
[1] 6982
In this case, 1 is the job ID and 6982 is the pid.

Many programs which are run in the background in this way will terminate when the user disconnects from the terminal. This is because the system will send the signal HUP (hang up) then the terminal is dis-connected from the shell. The default behaviour of processes which receive this signal is to quit. The purpose of nohup is to intercept this signal and not pass it to the child process. Thus a process may continue to operate even when the user disconnects from the controlling terminal.

In the case where you are using ssh to connect to a machine and run wget with nohup, the process should continue after you disconnect. However, the record of the job ID dies with the interactive shell. When you log in again, a new shell process is started, and it has no information about the jobs of other shells. However, the wget process is probably still running (assuming it didn't terminate because it is finished, or suffered an error). You can check this by looking by process id.

The ps command used with no options will only show information about processes which are connected to the current terminal. To show processes which are connected to other terminals, (or those processes with no associated terminals), you can use some extra options. To see all wget processes on the system, try this:
Code:
ps aux |grep wget
You may see your previously run wget process still running.

There is a small problem however - how do you re-connect to it? Well, using normal shell job control there is no way AFAIK. You can send signals to the process using the kill command, which enabled you to terminate the process, and in the case of some programs instruct it to do other things (such as re-open log and config files).

As mentioned above, the program screen can be used to provide dis-connectible and re-connectible terminal sessions, among other things. It's very useful, but it's not installed everywhere.
 
  


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
Jobs started with nohup aborts after closing ssh awalls Linux - Software 4 09-28-2007 05:26 AM
Viewing Print Jobs using telnet/ssh BFid Linux - Software 1 11-21-2006 11:16 AM
Restart a jobs in CUPS in Slackware 11.0 Slim Backwater Slackware 0 11-07-2006 12:49 PM
GUI to queue and edit jobs to be done over ssh Samsara Linux - Software 1 01-25-2006 04:40 AM
Can't SSH until restart service Da Puff Mandriva 4 09-14-2005 08:51 PM


All times are GMT -5. The time now is 05:55 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration