Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Job -l after nohup

Tags:

linux

bash

nohup

How can I monitor a job that is still running (I guess detached?) after I started it with nohup, exited the server and logged back in? Normally, I use jobs -l to see what's running, but this is showing blank.

like image 929
Mittenchops Avatar asked Aug 13 '13 19:08

Mittenchops


People also ask

What is & After nohup?

It essentially returns control to you immediately and allows the command to complete in the background. This is almost always used with nohup because you typically want to exit the shell after starting the command.

Is nohup background process?

SIGHUP is a signal that is sent to a process when the controlling terminal of the process is closed. The nohup command can also be used to run programs in the background after logging off. To run a nohup command in the background, add an & (ampersand) to the end of the command.

How do you escape nohup?

Ending the nohup command with an & makes the command run in the background, even after you exit the shell. To exit the shell in this situation, enter the exit command. nohup ensures that the command does not end when the creating process ends.

Does nohup run forever?

Starting a process using NohupThe jobs will still continue running in the shell and will not get killed upon exiting the shell or terminal.


1 Answers

You need to understand the difference between a process and a job. Jobs are managed by the shell, so when you end your terminal session and start a new one, you are now in a new instance of Bash with its own jobs table. You can't access jobs from the original shell but as the other answers have noted, you can still find and manipulate the processes that were started. For example:

$ nohup sleep 60 &
[1] 27767
# Our job is in the jobs table
$ jobs
[1]+  Running                 nohup sleep 60 &
# And this is the process we started
$ ps -p 27767
  PID TTY          TIME CMD
27767 pts/1    00:00:00 sleep
$ exit # and start a new session
# Now jobs returns nothing because the jobs table is empty
$ jobs
# But our process is still alive and kicking...
$ ps -p 27767
  PID TTY          TIME CMD
27767 pts/1    00:00:00 sleep
# Until we decide to kill it
$ kill 27767
# Now the process is gone
$ ps -p 27767
  PID TTY          TIME CMD
like image 87
ThisSuitIsBlackNot Avatar answered Sep 19 '22 07:09

ThisSuitIsBlackNot