浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Kill the undesired UNIX processes in one go

Kill the undesired UNIX processes in one go

Contributor Icon Contributed by roshi  
Tag Icon Tagged: UNIX  

This recipe is useful when one wants to kill all the processes belonging to one user or having a particular regular expression in the process name.
One can use different options of “ps” and “grep” to kill the undesired process(es).


The following is the general syntax of this recipe

ps -u | grep
| awk '{print $1}' | xargs kill -9

ps -u will find all the processes of the user username.
This output is then greped for processname_pattern which is then piped to awk.
awk ‘{print $1}’ will print only the first column of the output (the process-id, in this case).
This is then xargd to the kill with sure kill -9 signal.

As a result,all the undesired processes will be killed.

Note : One should give the processname_pattern carefully as an incorrect
regular expression may lead to even desired processes being killed.

posted on 2012-04-13 07:22  lexus  阅读(196)  评论(0编辑  收藏  举报