Reputation: 19724
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.
Upvotes: 6
Views: 3276
Reputation: 24083
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
Upvotes: 9
Reputation: 75588
You could have a list of the processes running under current user with ps -u "$USER"
or ps -u "$(whoami)"
.
Upvotes: 2
Reputation: 5063
You can monitor if the proceses if still running using
ps -p <pid>
, where is the ID of the process you get after using the nohup
command.
If you see valid entries you process is probably alive.
Upvotes: 2