Skip to content

Commit f183e72

Browse files
committed
add support for -exit.
1 parent f9ddf09 commit f183e72

File tree

5 files changed

+46
-7
lines changed

5 files changed

+46
-7
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
tags
2+
.mk

common/commands.c

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
# include "screen.h"
2121
# include "coldisp.h"
2222
# include "sigdesc.h"
23+
# include <ctype.h>
2324
# include "../include/build.h"
2425

2526
FILE *log_fp;
@@ -112,6 +113,7 @@ extern int proc_id;
112113
int delay_time = 5;
113114

114115
char *chk_strdup(char *);
116+
void refresh(void);
115117

116118
static void
117119
command_switches(int argc, char **argv)

include/build.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# define MAJ_VERSION 2
2-
# define MIN_VERSION 1
2+
# define MIN_VERSION 2
33
int version_build_no = 58;
44
# define VERSION_BUILD_NO 58
55
char version_build_date[] = "Thu Jul 23 22:50:15 2015";

linux/softirqs.c

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ display_softirqs()
3737

3838
if (softirqs_idx < 0)
3939
softirqs_idx = mon_find("softirqs", &width);
40+
if (softirqs_idx < 0) {
41+
print("cannot find softirqs in mmap file.\n");
42+
clear_to_end_of_screen();
43+
return;
44+
}
4045

4146
print("%*s ", width - 9, "");
4247
for (i = 0; i < num_cpus; i++) {

scripts/pidmon.pl

+37-6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ sub main
2626
{
2727
Getopt::Long::Configure('no_ignore_case');
2828
usage() unless GetOptions(\%opts,
29+
'exit',
2930
'help',
3031
'rate=s',
3132
'size',
@@ -94,19 +95,25 @@ sub main
9495
}
9596
}
9697

97-
$pids{$p} = $cmdline;
98-
next if $first;
98+
$pids{$p}{cmd} = $cmdline;
99+
if ($first) {
100+
$pids{$p}{time} = time();
101+
$pids{$p}{user} = $uid;
102+
next;
103+
}
99104

100105
my $user;
101106
if (!defined($old_pids{$p})) {
102-
$user = getpwuid($uid) if $uid;
107+
$pids{$p}{time} = time();
108+
$user = getpwuid($uid) if defined($uid);
103109
$user ||= "(nouid)";
104-
printf time_string() . "New pid : %8s %5d %5s %s\n",
110+
printf time_string() . "New : %8s %5d %5s %s\n",
105111
$user, $p, $ppid, $cmdline;
112+
$pids{$p}{user} = $user;
106113
} elsif ($old_pids{$p} ne $cmdline) {
107-
$user = getpwuid($uid) if $uid;
114+
$user = getpwuid($uid) if defined($uid);
108115
$user ||= "(nouid)";
109-
printf time_string() . "New pid cmd: %8s %5d %5s %s\n",
116+
printf time_string() . "New*: %8s %5d %5s %s\n",
110117
$user, $p, $ppid, $cmdline;
111118
}
112119

@@ -138,6 +145,26 @@ sub main
138145
print " $pid: VSS: $vss RSS: $rss\n";
139146
}
140147
}
148+
149+
###############################################
150+
# Find terminated procs. #
151+
###############################################
152+
if ($opts{exit}) {
153+
foreach my $p (keys(%old_pids)) {
154+
next if defined($pids{$p});
155+
my $t = time() - $old_pids{$p}{time};
156+
if ($t > 3600) {
157+
$t = sprintf("%dm%ds", $t / 60, $t % 60);
158+
} else {
159+
$t = $t . "s";
160+
}
161+
printf time_string() . "Term: %8s %s %s %s\n",
162+
$old_pids{$p}{user},
163+
$p,
164+
"[$t]",
165+
$old_pids{$p}{cmd};
166+
}
167+
}
141168
}
142169
$first = 0;
143170
}
@@ -156,6 +183,7 @@ sub usage
156183
pidmon.pl -- monitor for new processes being created
157184
Usage: pidmon.pl
158185
186+
159187
Description:
160188
161189
This script keeps polling the /proc filesystem to look for new processes
@@ -170,7 +198,10 @@ sub usage
170198
171199
Switches:
172200
201+
-exit Show process termination
173202
-rate NN Number of milliseconds between polling.
203+
-size Show process size.
204+
174205
EOF
175206
exit(1);
176207
}

0 commit comments

Comments
 (0)