This commit is contained in:
Jamie Cameron
2019-07-30 23:05:07 -07:00
parent c6dedff679
commit e581097113
4 changed files with 30 additions and 2 deletions

View File

@@ -16,7 +16,7 @@ foreach $pr (@procs) {
$procmap{$p} = $pr;
$argmap{$p} = $pr->{'args'};
$usermap{$p} = $pr->{'user'};
$stimemap{$p} = $pr->{'_stime'};
$stimemap{$p} = &format_stime($pr);
push(@{$children{$pp}}, $p);
$inlist{$pr->{'pid'}}++;
}

View File

@@ -30,7 +30,7 @@ foreach $u (@users) {
}
push(@cols, $pr->{'cpu'});
if ($info_arg_map{'_stime'}) {
push(@cols, $pr->{'_stime'});
push(@cols, &format_stime($pr));
}
push(@cols, &html_escape(&cut_string($pr->{'args'})));
print &ui_columns_row(\@cols);

View File

@@ -28,6 +28,7 @@ if ($ver >= 2) {
}
open(PS, "ps --cols 2048 -eo user$width,ruser$width,group$width,rgroup$width,pid,ppid,pgid,pcpu,vsz,nice,etime,time,stime,tty,args 2>/dev/null |");
$dummy = <PS>;
my @now = localtime(time());
for($i=0; $line=<PS>; $i++) {
chop($line);
$line =~ s/^\s+//g;
@@ -52,6 +53,17 @@ if ($ver >= 2) {
$plist[$i]->{"bytes"} = $w[8]*1024;
$plist[$i]->{"time"} = $w[11];
$plist[$i]->{"_stime"} = $w[12];
if ($w[12] =~ /^(\d+):(\d+)$/ ||
$w[12] =~ /^(\d+):(\d+):(\d+)$/) {
# Started today
$plist[$i]->{"_stime_unix"} =
timelocal($3 || 0, $2, $1, $now[3], $now[4], $now[5]);
}
elsif ($w[12] =~ /^(\S\S\S)\s*(\d+)$/) {
# Started on some other day
$plist[$i]->{"_stime_unix"} =
timelocal(0, 0, 0, $2, &month_to_number($1), $now[5]);
}
$plist[$i]->{"nice"} = $w[9];
$plist[$i]->{"args"} = @w<15 ? "defunct" : join(' ', @w[14..$#w]);
$plist[$i]->{"_group"} = $w[2];

View File

@@ -641,5 +641,21 @@ else {
}
}
# format_stime(&proc)
# Returns the process start time in human-readable format
sub format_stime
{
my ($p) = @_;
if (!$p->{'_stime_unix'}) {
return $p->{'_stime'}
}
elsif (time() - $p->{'_stime_unix'} > 86400) {
return &make_date($p->{'_stime_unix'}, 1);
}
else {
return &make_date($p->{'_stime_unix'});
}
}
1;