I have an ultra old (don't ask why) BusyBox (BusyBox v1.01 (2008.12.19-21:31+0000) Built-in shell (ash)) on my DreamBox. I would like to find out which process opened which connection using netstat. But I found out that BusyBox's netstat doesn't contain the -p option. What other possibilites do I have to find out which process has opened (and is using) the corresponding socket?
You can find the equivalent information in slightly uglier form (a.k.a. hexadecimal) in
/proc/net/tcp
. There, you can find the inode of the connection, which you can look up under/proc/$pid/fd/
.For example:
(In normal netstat, but not in busybox netstat, the
-e
option also gives you that extra information.)You can find the process which corresponds to the inode with the following command:
You need root access for the second step.
Not as convenient as the
-p
option, obviously, but works in a bind. Could be scripted, if necessary.This may not help, if you don't have the opportunity to rebuild Busybox, but in case it helps anyone...
Busybox does have a configuration option to support the
-p
switch of Busyboxnetstat
. See optionCONFIG_FEATURE_NETSTAT_PRG
, selected in busybox menuconfig via Networking Utilities → netstat → Enable PID/Program name output.If you have or can get
ss
on your device it can show you the PID too:A slight variant that might be easier for some:
This should return a line similar to: lrwx------ 1 root root 64 May 22 20:02 /proc/1148/fd/26 -> socket:[4520]
Telling you that PID 1148 has a socket open on inode 4520
Example: Looking for the SSDP process on a Philips Hue Bridge V2.x:
So we identified process PID=1148 as the listener:
So now I know that the ipbridge daemon controls the SSDP listener among the many other things it controls on the Hue Bridge.
Here's a complete awk script for it. It's ugly but it works.