-   Linux - Newbie (
-   -   Jobs IDs go away on ssh restart (

nuxeon 10-18-2007 06:57 PM

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.

Tinkster 10-18-2007 07:07 PM

For the odd occasion where nohup won't work, use screen.


gilead 10-18-2007 07:08 PM

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.

matthewg42 10-18-2007 07:46 PM

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:

% 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:

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.

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