Integrating the pstree Tool into OpenWrt

Recently, while debugging a user-space program, I suddenly wanted to understand the relationship between a certain process and several child processes, similar to the output below:

ruok@ruok-vm:~$ ps aux | grep smbdroot       1359  0.0  0.2 356712 20596 ?        Ss   16:48   0:00 /usr/sbin/smbd --foreground --no-process-grouproot       1361  0.0  0.0 344968  6036 ?        S    16:48   0:00 /usr/sbin/smbd --foreground --no-process-grouproot       1362  0.0  0.0 344960  4760 ?        S    16:48   0:00 /usr/sbin/smbd --foreground --no-process-grouproot       1363  0.0  0.0 356712  7052 ?        S    16:48   0:00 /usr/sbin/smbd --foreground --no-process-grouproot       2160  0.0  0.0  14432  1060 pts/0    S+   16:50   0:00 grep --color=auto smbd

At this point, I remembered that there is actually a tool called pstree in Linux that can meet my needs. With it, we can find out the relationship between the several smbd processes as follows:

ruok@ruok-vm:~$ pstree -p 1359smbd(1359)─┬─cleanupd(1362)           ├─lpqd(1363)           └─smbd-notifyd(1361)

This way, we can intuitively see the relationships between the various processes.Since pstree is so useful, why not port it to our OpenWrt system? This article will introduce how to add this tool.Compilation Configuration OptionsFirst, we enter the OpenWrt configuration by using make menuconfig to look for information related to pstree. Fortunately, this tool is included in busybox:Integrating the pstree Tool into OpenWrtIt can be seen that it is located under the Base system menu, but upon entering this directory, we can see:Integrating the pstree Tool into OpenWrtThere is no Process Utilities menu found here. However, we can see an option called Customize busybox options. Selecting it, I was surprised to find that there is indeed a Process Utilities submenu:Integrating the pstree Tool into OpenWrtAfter selecting the pstree option, save and exit, then execute the compilation.Executing the CompilationWe can start compiling the entire SDK using the make V=s command, but the compilation process reports an error:

Configuring demo-libubox.Configuring ppp-mod-pppoe.Collected errors: * check_conflicts_for: The following packages conflict with busybox: * check_conflicts_for:  busybox-selinux *  * opkg_install_cmd: Cannot install package busybox.package/Makefile:67: recipe for target 'package/install' failedmake[2]: *** [package/install] Error 255

However, this compilation error message is quite straightforward, indicating that we have selected two versions of busybox that conflict with each other. Therefore, we can only choose between busybox and busybox-selinux. After trying, it was found that busybox could not be deselected due to its dependencies with many packages, so we had to uncheck busybox-selinux.Integrating the pstree Tool into OpenWrtRecompiling again will allow it to complete successfully.Installation TestingWe upgraded the successfully compiled firmware to the device for testing, and it can be seen that it is functioning normally:

root@OpenWrt:/# pstree -pprocd(1)-+-ash(5203)---pstree(5301)         |-blockd(3441)         |-dnsmasq(5240)         |-dropbear(2555)         |-fwdd(2202)         |-ksmbd.mountd(4647)---ksmbd.mountd(4664)         |-logd(2301)         |-mtk_dut(4774)         |-netifd(2736)-+-odhcp6c(2977)         |              `-udhcpc(2976)         |-ntpd(4713)         |-odhcpd(2805)         |-rpcd(2353)         |-ubusd(1143)         |-uhttpd(3186)         |-urngd(1177)         |-wsdd2(5201)         `-xl2tpd(3314)root@OpenWrt:/# pstree -p 2736netifd(2736)-+-odhcp6c(2977)             `-udhcpc(2976)

However, upon checking the help information, it can be found that the version of pstree in busybox only supports a single -p option, making its functionality very limited:

root@OpenWrt:/# pstree --helpBusyBox v1.33.2 (2025-05-27 13:47:58 UTC) multi-call binary.
Usage: pstree [-p] [PID|USER]
Display process tree, optionally start from USER or PID
        -p      Show pids

So, is there a way to port a fully functional version of pstree to the OpenWrt system?

Leave a Comment