Just thought I could make one like this. You can use
pstree
to get a text-version in tree style.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