Pregunta

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

¿Fue útil?

Solución

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.

Otros consejos

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)

I would do something like:

jobs

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

kill %1

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$

kill nohup process

ps aux |grep nohup

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top