diff options
author | Mikolaj Golub <trociny@FreeBSD.org> | 2013-04-20 08:22:09 +0000 |
---|---|---|
committer | Mikolaj Golub <trociny@FreeBSD.org> | 2013-04-20 08:22:09 +0000 |
commit | 948baa409b2f0c3ee64159c6e855ad2bd7df73f1 (patch) | |
tree | 5444e750e3a57646ab3171648a53a48e83087e5a /usr.bin | |
parent | d86fa0c72c0c527274aa3209389f4e8107ea5725 (diff) | |
download | src-948baa409b2f0c3ee64159c6e855ad2bd7df73f1.tar.gz src-948baa409b2f0c3ee64159c6e855ad2bd7df73f1.zip |
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
Notes
Notes:
svn path=/head/; revision=249686
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/procstat/procstat.1 | 6 | ||||
-rw-r--r-- | usr.bin/procstat/procstat.c | 43 |
2 files changed, 32 insertions, 17 deletions
diff --git a/usr.bin/procstat/procstat.1 b/usr.bin/procstat/procstat.1 index 38681f8f1c22..faa296c7f935 100644 --- a/usr.bin/procstat/procstat.1 +++ b/usr.bin/procstat/procstat.1 @@ -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 diff --git a/usr.bin/procstat/procstat.c b/usr.bin/procstat/procstat.c index 366c8f1fea75..3c1dafaaeb67 100644 --- a/usr.bin/procstat/procstat.c +++ b/usr.bin/procstat/procstat.c @@ -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; } |