我正在使用一个多用户Ubuntu服务器,需要运行Python的多进程脚本。有时候我需要结束掉其中一些进程。例如:
$ ps -eo pid,comm,cmd,start,etime | grep .py
3457 python python process_to_kill.py - 20:57:28 01:44:09
3458 python python process_to_kill.py - 20:57:28 01:44:09
3459 python python process_to_kill.py - 20:57:28 01:44:09
3460 python python process_to_kill.py - 20:57:28 01:44:09
3461 python python process_to_kill.py - 20:57:28 01:44:09
3462 python python process_to_kill.py - 20:57:28 01:44:09
3463 python python process_to_kill.py - 20:57:28 01:44:09
3464 python python process_to_kill.py - 20:57:28 01:44:09
13465 python python process_not_to_kill.py - 08:57:28 13:44:09
13466 python python process_not_to_kill.py - 08:57:28 13:44:09
需要终止进程3457-3464。目前我只能执行此操作
$ kill 3457 3458 3459 3460 3461 3462 3463 3464
有没有像$ kill 3457-3464
这样的命令,我可以指定起始和结束进程并杀死该范围内的所有进程?
ps -H
命令可以告诉你进程之间的关系;在这种情况下,你可能更喜欢杀死进程组(例如kill -3457
)。 - Toby Speight