How do you kill all Linux processes that are older

2019-01-08 08:12发布

I have a problem with some zombie-like processes on a certain server that need to be killed every now and then. How can I best identify the ones that have run for longer than an hour or so?

14条回答
成全新的幸福
2楼-- · 2019-01-08 08:53

In this way you can obtain the list of the ten oldest processes:

ps -elf | sort -r -k12 | head -n 10
查看更多
孤傲高冷的网名
3楼-- · 2019-01-08 08:53

I did something similar to the accepted answer but slightly differently since I want to match based on process name and based on the bad process running for more than 100 seconds

kill $(ps -o pid,bsdtime -p $(pgrep bad_process) | awk '{ if ($RN > 1 && $2 > 100) { print $1; }}')
查看更多
登录 后发表回答