Just thought I could make one like this. You can use pstree to get a text-version in tree style:
init-+-acpid
|-agetty
|-at-spi-bus-laun-+-dbus-daemon
| |-{dconf worker}
| |-{gdbus}
| `-{gmain}
|-at-spi2-registr---{gdbus}
|-cdm---xinit-+-X---{X}
| `-dwm
|-cron
|-2*[dbus-daemon]
|-dbus-launch
|-dzen-status-+-dzen2
| `-{threaded-ml}
|-ntpd---ntpd
|-pppd
|-pulseaudio-+-{alsa-sink-STAC9}
| `-{alsa-source-STA}
|-syslog-ng---syslog-ng
|-systemd-udevd
|-tmux-+-bash---vim
| |-bash
| `-bash---pstree
`-urxvtd-+-bash
`-tmux
Here are the codes:
cat /proc/*/status | awk ' BEGIN {printf("graph G {\n")} /Name/ {name = $2} /^Pid/ {pid = $2} /PPid/ { if (PROCINFO["ppid"] != $2) { printf("p%d [label = \"%s\"]\n", pid, name); if ($2 != 0) printf("p%d -- p%d\n", pid, $2); } } END {printf("}")}' | circo -T png -o test.png
It outputs all process except the current processes (cat/awk/circo). You can use if ('$$' != $2) { to replace the checking code, $$ is the current Bash shell’s process ID, which is Awk’s parent process ID. Note that part is actually being processed in Bash not Awk. The Awk code pauses before $$, then continues after.
Next one hide the kernel threads:
cat /proc/*/status | awk ' BEGIN {printf("graph G {\n")} /Name/ {name = $2} /^Pid/ {pid = $2} /PPid/ { if ($2 == 2 || pid == 2) { printf("p%d [label = \"%s\"]\n", pid, name); if ($2 != 0) printf("p%d -- p%d\n", pid, $2); } } END {printf("}")}' | circo -T png -o test.png
I am not sure if all kernel threads are with PID #2, but it works for me. And if those children had children, then this code will work probably.
The last one only show kernel threads:
cat /proc/*/status | awk ' BEGIN {printf("graph G {\n")} /Name/ {name = $2} /^Pid/ {pid = $2} /PPid/ { if ($2 != 2 && pid != 2 && PROCINFO["ppid"] != $2) { printf("p%d [label = \"%s\"]\n", pid, name); if ($2 != 0) printf("p%d -- p%d\n", pid, $2); } } END {printf("}")}' | circo -T png -o test.png



0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.