How do I kill a process after detaching it from bash?

8,070

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...

Share:
8,070

Related videos on Youtube

Kookerus
Author by

Kookerus

Updated on September 18, 2022

Comments

  • Kookerus
    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. using killall or pidof ScriptName doesn't work.

  • Kookerus
    Kookerus almost 9 years
    Closing the terminal still kills the process. Is there any way I can keep that from happening?
  • squareborg
    squareborg almost 9 years
    nohup 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
    Kookerus almost 9 years
    I'm sorry, let me rephrase. When just using & and not nohup, 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?