문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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.

You could have a list of the processes running under current user with ps -u "$USER" or ps -u "$(whoami)".

Try this :

ps -ef | grep <pid>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top