如何杀死 nohup 进程?

发布于 2024-12-13 19:13:32 字数 228 浏览 7 评论 0原文

我现在执行了以下命令,

$ nohup ./tests.run.pl 0 &

当我尝试杀死它(以及从该脚本启动的执行)时,

$ kill -0 <process_id>

但使用它不起作用。如何终止 nohupped 进程以及通过 nohupped 脚本运行的进程?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

喵星人汪星人 2024-12-20 19:13:32

kill -0 确实不会终止进程。它只是检查您是否可以向它发送信号。

只需kill pid,如果这不起作用,请尝试kill -9 pid

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.

天煞孤星 2024-12-20 19:13:32

只需 kill 即可发送 SIGTERM,而 nohup 不会忽略该信号。

您不应该首先发送 SIGKILL,因为这会让进程没有机会恢复;您应该按顺序尝试以下操作:

  • SIGTERM (15)
  • SIGINT (2)
  • SIGKILL (9)

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)
歌入人心 2024-12-20 19:13:32

我会做类似的事情:

jobs

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

kill %1

I would do something like:

jobs

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

kill %1
Hello爱情风 2024-12-20 19:13:32

如果您不知道进程 ID 并且它可能在 shell(或循环)内运行各种命令,您可以运行 jobs -l 来列出作业和 PID,然后 kill他们。

参见示例:

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$

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$
摘星┃星的人 2024-12-20 19:13:32

杀死 nohup 进程

ps aux |grep nohup

grep PID
kill -15 -1 16000(将注销您)并在下次登录 root 时清除

kill nohup process

ps aux |grep nohup

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文