解决方案

查看运行最久的10个进程

ps -elf | sort -r -k12 | head -n 10

使用perl找出时间过长的进程ID

process.pl

#!/usr/bin/perl -w
use strict;
use Proc::ProcessTable;
my $anHourAgo = time-60*60;
my $t = new Proc::ProcessTable;
foreach my $p ( @{$t->table} ) {
    if ($p->start() < $anHourAgo) {
        print $p->pid, "\n";
    }
}

然后运行perl process.pl

直接使用linux命令杀掉长时间进程

警告:这将发现并杀死长时间运行的进程

ps -eo uid,pid,etime | egrep '^ *user-id' | egrep ' ([0-9]+-)?([0-9]{2}:?){3}' | awk '{print }' | xargs -I{} kill {}

(其中user-id是具有长时间运行进程的特定用户的ID。)

第二个正则表达式匹配一个具有可选天数的时间,后跟一个小时,分钟和第二个部分,因此长度至少为一个小时。

linux如何杀死所有超过一定时间的进程
日期:2020-03-25 09:31:28 来源:oir作者:oir