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.
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.
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.
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.
Starting a process using NohupThe jobs will still continue running in the shell and will not get killed upon exiting the shell or terminal.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With