Make use of newly added libprocstat(3) ability to extract procstat
info from a process core file. So now one can run procstat(1) on a process core e.g. to get a list of files opened by a process when it crashed: root@lisa:/ # procstat -f /root/vi.core PID COMM FD T V FLAGS REF OFFSET PRO NAME 658 vi text v r r-------- - - - /usr/bin/vi 658 vi ctty v c rw------- - - - /dev/pts/0 658 vi cwd v d r-------- - - - /root 658 vi root v d r-------- - - - / 658 vi 0 v c rw------- 11 3208 - /dev/pts/0 658 vi 1 v c rw------- 11 3208 - /dev/pts/0 658 vi 2 v c rw------- 11 3208 - /dev/pts/0 658 vi 3 v r r----n-l- 1 0 - /tmp/vi.0AYKz3Lps7 658 vi 4 v r rw------- 1 0 - /var/tmp/vi.recover/vi.GaGYsz 658 vi 5 v r rw------- 1 0 - - PR: kern/173723 Suggested by: jhb MFC after: 1 month
This commit is contained in:
parent
d86fa0c72c
commit
948baa409b
@ -25,7 +25,7 @@
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd July 11, 2012
|
||||
.Dd April 20, 2013
|
||||
.Dt PROCSTAT 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -38,7 +38,7 @@
|
||||
.Op Fl C
|
||||
.Op Fl w Ar interval
|
||||
.Op Fl b | c | e | f | i | j | k | l | s | t | v | x
|
||||
.Op Fl a | Ar pid ...
|
||||
.Op Fl a | Ar pid | Ar core ...
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
@ -47,6 +47,8 @@ utility displays detailed information about the processes identified by the
|
||||
arguments, or if the
|
||||
.Fl a
|
||||
flag is used, all processes.
|
||||
It can also display information extracted from a process core file, if
|
||||
the core file is specified as the argument.
|
||||
.Pp
|
||||
By default, basic process statistics are printed; one of the following
|
||||
options may be specified in order to select more detailed process information
|
||||
|
@ -50,7 +50,7 @@ usage(void)
|
||||
fprintf(stderr, "usage: procstat [-h] [-C] [-M core] [-N system] "
|
||||
"[-w interval] \n");
|
||||
fprintf(stderr, " [-b | -c | -e | -f | -i | -j | -k | "
|
||||
"-l | -s | -t | -v | -x] [-a | pid ...]\n");
|
||||
"-l | -s | -t | -v | -x] [-a | pid | core ...]\n");
|
||||
exit(EX_USAGE);
|
||||
}
|
||||
|
||||
@ -116,7 +116,7 @@ main(int argc, char *argv[])
|
||||
int ch, interval, tmp;
|
||||
int i;
|
||||
struct kinfo_proc *p;
|
||||
struct procstat *prstat;
|
||||
struct procstat *prstat, *cprstat;
|
||||
long l;
|
||||
pid_t pid;
|
||||
char *dummy;
|
||||
@ -255,19 +255,32 @@ main(int argc, char *argv[])
|
||||
}
|
||||
for (i = 0; i < argc; i++) {
|
||||
l = strtol(argv[i], &dummy, 10);
|
||||
if (*dummy != '\0')
|
||||
usage();
|
||||
if (l < 0)
|
||||
usage();
|
||||
pid = l;
|
||||
|
||||
p = procstat_getprocs(prstat, KERN_PROC_PID, pid, &cnt);
|
||||
if (p == NULL)
|
||||
errx(1, "procstat_getprocs()");
|
||||
if (cnt != 0)
|
||||
procstat(prstat, p);
|
||||
procstat_freeprocs(prstat, p);
|
||||
if (*dummy == '\0') {
|
||||
if (l < 0)
|
||||
usage();
|
||||
pid = l;
|
||||
|
||||
p = procstat_getprocs(prstat, KERN_PROC_PID, pid, &cnt);
|
||||
if (p == NULL)
|
||||
errx(1, "procstat_getprocs()");
|
||||
if (cnt != 0)
|
||||
procstat(prstat, p);
|
||||
procstat_freeprocs(prstat, p);
|
||||
} else {
|
||||
cprstat = procstat_open_core(argv[i]);
|
||||
if (cprstat == NULL) {
|
||||
warnx("procstat_open()");
|
||||
continue;
|
||||
}
|
||||
p = procstat_getprocs(cprstat, KERN_PROC_PID,
|
||||
-1, &cnt);
|
||||
if (p == NULL)
|
||||
errx(1, "procstat_getprocs()");
|
||||
if (cnt != 0)
|
||||
procstat(cprstat, p);
|
||||
procstat_freeprocs(cprstat, p);
|
||||
procstat_close(cprstat);
|
||||
}
|
||||
/* Suppress header after first process. */
|
||||
hflag = 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user