38

I executed the following command

$ nohup ./tests.run.pl 0 &

now when I try to kill it (and the executions that are started from this script) using

$ kill -0 <process_id>

it does not work. How can I kill a nohupped process and the processes that runs via the nohupped script?

Thanks

polerto
  • 1,750
  • 5
  • 29
  • 50

5 Answers5

47

kill -0 does not kill the process. It just checks if you could send a signal to it.

Simply kill pid, and if that doesn't work, try kill -9 pid.

Mat
  • 202,337
  • 40
  • 393
  • 406
  • 2
    @Mat, Do I need to get the process id first? What if I run multiple processes and wish to kill them all at once? I did parallel computing using multiple cores, so there are, say 10 processes invoked by "nohup". I wish to kill them all. Could you please instruct me here? Thanks. – SixSigma Jan 17 '15 at 22:14
  • i have killed a nohup process with kill -9,but still when i run command tail f nohup.out i m getting logs continuously...this means my process is running..what to do?? – lone_worrior Jan 06 '18 at 13:15
29

Simply kill <pid> which will send a SIGTERM, which nohup won't ignore.

You should not send a SIGKILL first as that gives the process no chance to recover; you should try the following, in order:

  • SIGTERM (15)
  • SIGINT (2)
  • SIGKILL (9)
trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • 3
    Absolutely true. A SIGKILL (kill -9) can't be caught by a process's signal handlers. This means that you can't write any epilog code to remove temporary files and/or detach any shared memory segments allocated. Failure to cleanup shared memory means less overall memory is available for new processes -- a nasty thing. – JRFerguson Nov 04 '11 at 14:49
13

I would do something like:

jobs

[1] + Running nohup ./tests.run.pl

kill %1
Grey
  • 877
  • 9
  • 29
user7321649
  • 131
  • 1
  • 2
6

If you don't know the process ids and it might run various commands within a shell (or a loop), you can run jobs -l to list jobs and PIDs, then kill them.

See example:

ubuntu@app2:/usr/share/etlservice/bin$ jobs -l
[1]  27398 Running                 nohup ./extract_assessor_01.sh > job1.log &
[2]  27474 Running                 nohup ./extract_assessor_02.sh > job2.log &
[3]  27478 Running                 nohup ./extract_assessor_03.sh > job3.log &
[4]- 27481 Running                 nohup ./extract_assessor_04.sh > job4.log &
[5]+ 28664 Running                 nohup ./extract_assessor_01.sh > job1.log &
ubuntu@app2:/usr/share/etlservice/bin$ sudo kill 27398
sudo kill 27474[1]   Terminated              nohup ./extract_assessor_01.sh > job1.log
ubuntu@app2:/usr/share/etlservice/bin$ sudo kill 27474
[2]   Terminated              nohup ./extract_assessor_02.sh > job2.log
ubuntu@app2:/usr/share/etlservice/bin$ sudo kill 27478
[3]   Terminated              nohup ./extract_assessor_03.sh > job3.log
ubuntu@app2:/usr/share/etlservice/bin$ sudo kill 27481
[4]-  Terminated              nohup ./extract_assessor_04.sh > job4.log
ubuntu@app2:/usr/share/etlservice/bin$ sudo kill 28664
[5]+  Terminated              nohup ./extract_assessor_01.sh > job1.log
ubuntu@app2:/usr/share/etlservice/bin$
Mike S.
  • 4,806
  • 1
  • 33
  • 35
3

kill nohup process

ps aux |grep nohup

grep that PID kill -15 -1 16000 (will logout you) and clean on next login root

Dawny33
  • 10,543
  • 21
  • 82
  • 134