【发布时间】:2011-03-31 10:54:00
【问题描述】:
我在编程过程中经常需要杀死一个进程。
我现在的做法是:
[~]$ ps aux | grep 'python csp_build.py'
user 5124 1.0 0.3 214588 13852 pts/4 Sl+ 11:19 0:00 python csp_build.py
user 5373 0.0 0.0 8096 960 pts/6 S+ 11:20 0:00 grep python csp_build.py
[~]$ kill 5124
如何自动提取进程 ID 并在同一行中将其杀死?
像这样:
[~]$ ps aux | grep 'python csp_build.py' | kill <regex that returns the pid>
【问题讨论】:
-
相信我! :'D 您选择的第一个答案比您在答案中告诉您的解决方案复杂得多。我宁愿选择你的方式。
-
检查进程是否存在的最佳方法:stackoverflow.com/questions/3043978/…