I have started a program in Linux using & and disown.
I wish to see if it is still running and possibly to kill it.
I started the process with commands like these:
(env)bash-4.2$ python manage.py update_rollups &
[1] 29144
(env)bash-4.2$ disownI can no longer find it with ps aux, nor kill it based on the pid 29144.
I want to know if the process is still running (under init?).
I hope you can help!
13 Answers
In brief
With & and disown you do not change the PID [1] of the process.
If you do not see it in the ps -p <YOURPID> output, it is not any more running.
You can over-check it with an additional echo $? [2] after the ps (or kill) command, checking if the program exits with an exit code different from 0 (typically 1).
Understanding your commands.
Background: when you launch the command with the final
&you send it in background.
This means that:- It is present in the job list of your shell (in your example is the number
[1]and you can refer to it as%1; (try the commandjobs). - You can bring it in foreground and in background with
fgandbg. It is (still) "owned" by the (linked to the parent) shell: if the shell receives a
SIGHUPsignal, it will send aSIGHUPsignal to the process too.$ sleep 1h & [1] 10795 $ jobs [1]+ running sleep 1h & $ ps -l -p 10795 F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 0 S 1000 10795 8380 0 80 0 - 3107 hrtime pts/57 00:00:00 sleep
- It is present in the job list of your shell (in your example is the number
Disown: with the command
disownyou remove the job from the shell's job list, but you do not change its PID.$ disown $ jobs # <---- No jobs $ ps -l -p 10795 F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 0 S 1000 10795 8380 0 80 0 - 3107 hrtime pts/57 00:00:00Note the same PPID (the shell still exists).
Now we kill the shell.$ kill 8380 # Here we kill the shell $ ps -l -p 10795 F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 0 S 1000 10795 5339 0 80 0 - 3107 hrtime pts/57 00:00:00 sleepThere is another
PPID, the5339, that with another invocation ofps,ps -p 5339, you will discover to be aninitinstance:$ ps -p 5339 PID TTY TIME CMD 5339 ? 00:02:20 init
pstree: a quicker way.
You can see with pstree more quickly.
Before the disown and kill the bash commands:
$ pstree -s -p 10795
init(1)───lightdm(1199)───lightdm(5259)───bash(8380)───sleep(10795)After the disown and kill the bash:
$ pstree -s -p 10795
init(1)───lightdm(1199)───lightdm(5259)───init(5339)───sleep(10795)Note: of course all the PIDs in your case will be different...
2If it's not in ps auxf, then it's not running. If you run kill 29144 and get "No such process", that also means the process is not running.
Each process has a folder in the /proc filesystem with it's pid. If the folder doesn't exist, the process isn't running.
For example
/proc/29144/you can view the process commandline
cat /proc/29144/cmdlineexample output:
/usr/sbin/smbd
or check the process file status
stat /proc/29144/exeexample output:
File: /proc/29144/exe -> /usr/sbin/smbd Size: 0 Blocks: 0 IO Block: 1024 symbolic link
Device: 3h/3d Inode: 78497 Links: 1
Access: (0777/lrwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2017-04-07 12:18:01.719011505 +0200
Modify: 2017-04-07 12:18:01.369010535 +0200
Change: 2017-04-07 12:18:01.369010535 +0200 Birth: -