Detailed information on a single process in a greppable format
2
votes
2
answers
285
views
Utilities such as
ps
and top
are good for looking at many processes side-by-side. However, they are inconvenient for examining many fields of a single process and are not amenable to using grep
. For example:
$ ps -o pid,ppid,tname,bsdstart,start_time,start,bsdtime,etime,etimes,c=LIFE%,%cpu,cputime,rss,%mem,stat,class,nice=NICE,thcount,args -p $(pgrep syncthing)
PID PPID TTY START START STARTED TIME ELAPSED ELAPSED LIFE% %CPU TIME RSS %MEM STAT CLS NICE THCNT COMMAND
20149 1836 ? 19:24 19:24 19:24:58 0:24 01:54:12 6852 0 0.3 00:00:24 38428 0.2 Ssl IDL - 13 /usr/bin/syncthing -no-browser -no-restart -logflags=0
There is /proc/$PID/status
:
$ cat /proc/$(pgrep syncthing)/status | head
Name: syncthing
Umask: 0022
State: S (sleeping)
Tgid: 20149
Ngid: 0
Pid: 20149
PPid: 1836
TracerPid: 0
Uid: 1000 1000 1000 1000
Gid: 1000 1000 1000 1000
but this lacks useful fields such as:
- CPU usage percentage
- CPU time
- Resident memory size / resident set size
- Memory percentage
- Out of Memory Score
- Elapsed time
- Nice priority
- I/O priority
The output I desire might look something like this:
Name: syncthing
Process ID: 20149
Parent process ID: 1836
Full command: /usr/bin/syncthing
User: exampleuser
UID: 1000
State: Sleeping (S)
CPU priority: 19 (low)
I/O scheduling class: 2 (best-effort)
I/O priority level: 7 (low)
Start date (ISO): 2020-06-15T21:21:53-04:00
Start date (UTC): Tue Jun 16 01:21:53 UTC 2020
Process age: 01:54:12
Cumulative CPU time: 00:00:24
Cumulative user CPU time: 00:00:24
Cumulative system CPU time: 00:00:24
Out of memory score: 2
Out of memory adjustment factor: 0
Number of threads: 13
Number of child processes: 0
with more fields from e.g. /proc/$PID/stat
and /proc/$PID/statm
.
Does such a utility exist?
Note: this question differs from
[Detailed Per-Process Profiling](https://unix.stackexchange.com/questions/43936/detailed-per-process-profiling)
because I am not looking for performance profiling or monitoring over time,
but rather a snapshot of process information
for the specific fields mentioned above
in a particular format.
Asked by Nathaniel M. Beaver
(1398 rep)
Jun 16, 2020, 01:53 AM
Last activity: Mar 8, 2025, 09:39 AM
Last activity: Mar 8, 2025, 09:39 AM