How can I kill the processes matching a grep older than 30 minutes?

此生再无相见时 提交于 2019-12-02 00:01:39

To obtain the list of processes named PROCESS_NAME which are running longer than 30 minutes you can issue the following awkcommand:

ps ax -ocmd,pid,etime | awk '/PROCESS_NAME/{split($(NF),a,":");if(a[1]>30)print}'

To obtain only the pids run

ps ax -ocmd,pid,etime | awk '/PROCESS_NAME/{split($(NF),a,":");if(a[1]>30)print $(NF-1)}'

You can pipe this to xargs kill, like this:

ps ax -ocmd,pid,etime | awk '/PROCESS_NAME/{split($(NF),a,":");if(a[1]>30)print $(NF-1)}' \
| xargs kill 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!