How do I kill a process after detaching it from bash?
Solution 1
nohup
should only affect the hangup signal. So kill
should still work normally. Maybe you are using the wrong pid or process name; compare with pstree -p
or ps -ef
.
If you still suspect nohup
, maybe you could try disown
instead.
$ sleep 1000 &
$ jobs -p
13561
$ disown
$ jobs -p
$ pidof sleep
13561
$ kill 13561
$ pidof sleep
$
Solution 2
If you used nohup
, you can't kill them. The nohup
command specifically prevents those processes from receiving the kill signals. If you simply used &
, you can kill them by sending a kill
or kill -9
to the PID. Well, you can kill them by rebooting the machine, but that might be a bit more extreme than you really want...
Related videos on Youtube
Kookerus
Updated on September 18, 2022Comments
-
Kookerus over 1 year
I have multiple scripts that detach a process from bash using
nohup
and&>/dev/null &
. My question is, how do I kill the process after completely detaching it from bash. usingkillall
orpidof ScriptName
doesn't work. -
Kookerus almost 9 yearsClosing the terminal still kills the process. Is there any way I can keep that from happening?
-
squareborg almost 9 yearsnohup does not make the process immune to kill signals, it makes the process ignore a hup signal, you can kill it with
kill <pid>
and it will die like the rest of them. -
Kookerus almost 9 yearsI'm sorry, let me rephrase. When just using
&
and notnohup
, closing the terminal kills the process. I want to disconnect the job from the terminal, but still be able to kill it if I want. Is there a way to do that?