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$ disown
I 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!
Best Answer
In brief
With
&
anddisown
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 theps
(orkill
) command, checking if the program exits with an exit code different from0
(typically1
).Understanding your commands.
Background: when you launch the command with the final
&
you send it in background.This means that:
[1]
and you can refer to it as%1
; (try the commandjobs
).fg
andbg
.It is (still) "owned" by the (linked to the parent) shell: if the shell receives a
SIGHUP
signal, it will send aSIGHUP
signal to the process too.Disown: with the command
disown
you remove the job from the shell's job list, but you do not change its PID.Note the same PPID (the shell still exists).
Now we kill the shell.
There is another
PPID
, the5339
, that with another invocation ofps
,ps -p 5339
, you will discover to be aninit
instance:pstree
: a quicker way.You can see with
pstree
more quickly.Before the
disown
and kill the bash commands:After the
disown
and kill the bash:Note: of course all the PIDs in your case will be different...