[Toybox] ps debugging (notes to self)
Rob Landley
rob at landley.net
Wed Oct 14 04:12:19 PDT 2015
To do a manual data dump with slot labels, decimal, and hex values:
cat /proc/$$/stat | xargs -n 1 | \
(X=0; while read i; do \
echo -n "[$X:$i:$(printf %x $i)] "; X=$(($X+1)); done); \
echo && ps -o pid,rss
Use $$ as a stable (per-window) process whose values don't generally
change between invocations. (It's the shell you're running, stays
persistent where /proc/self doesn't. /proc/$PPID is the shell's parent,
I.E. an xterm, which is this crappy horrible thing where /proc/self/maps
goes on for PAGES on ubuntu.)
The slot[] values are in table 1-4 of the kernel's
Documentation/filesystems/proc.txt but the slot[] array entries after
the first are off by 2 because "tcomm" and "state" aren't numerical
values and are stored in variables outside the table. So the above data
dump has rss at 23 when it's slot[21].
Here's a slot[] labeled version of the table:
Table 1-4: Contents of the stat files (as of 2.6.30-rc7)
..............................................................................
Field Content
0 pid process id
tcomm filename of the executable
state state (R is running, S is sleeping, D is sleeping in an
uninterruptible wait, Z is zombie, T is traced/stopped)
1 ppid process id of the parent process
2 pgrp pgrp of the process
3 sid session id
4 tty_nr tty the process uses
5 tty_pgrp pgrp of the tty
6 flags task flags
7 min_flt number of minor faults
8 cmin_flt number of minor faults with child's
9 maj_flt number of major faults
10 cmaj_flt number of major faults with child's
11 utime user mode jiffies
12 stime kernel mode jiffies
13 cutime user mode jiffies with child's
14 cstime kernel mode jiffies with child's
15 priority priority level
16 nice nice level
17 num_threads number of threads
18 it_real_value (obsolete, always 0)
19 start_time time the process started after system boot
20 vsize virtual memory size
21 rss resident set memory size
22 rsslim current limit in bytes on the rss
23 start_code address above which program text can run
24 end_code address below which program text can run
25 start_stack address of the start of the main process stack
26 esp current value of ESP
27 eip current value of EIP
28 pending bitmap of pending signals
29 blocked bitmap of blocked signals
30 sigign bitmap of ignored signals
31 sigcatch bitmap of caught signals
32 wchan address where process went to sleep
33 0 (place holder)
34 0 (place holder)
35 exit_signal signal to send to parent thread on exit
36 task_cpu which CPU the task is scheduled on
37 rt_priority realtime priority
38 policy scheduling policy (man sched_setscheduler)
39 blkio_ticks time spent waiting for block IO
40 gtime guest time of the task in jiffies
41 cgtime guest time of the task children in jiffies
42 start_data address above which program data+bss is placed
43 end_data address below which program data+bss is placed
44 start_brk address above which program heap can be brk() expanded
45 arg_start address above which program command line is placed
46 arg_end address below which program command line is placed
47 env_start address above which program environment is placed
48 env_end address below which program environment is placed
49 exit_code the thread's exit_code in the form reported by waitpid
Unsolved problem: how the HECK do you test things like "rss" when
they'll vary per platform even if you compile your own test.c file to
get a binary to run? Even in a known test image running under qemu, the
tests are inherently unportable. Easy to test by hand, very difficult to
automate unless you're providing your own synthetic /proc/1/stat data
with a --bind mount which is just... ew. I'm going to have to do that,
aren't I? Sigh...
I need to genericize the column alignment code ala "ls -l" and "vmstat".
I have no idea how to do that, but it comes up a lot and I keep having
to hand-code it each time...
Right, don't mind me. As I said, notes to self.
Rob
1444821139.0
More information about the Toybox
mailing list