lsof-like applet?

Sven Oliver Moll busybox at svol.li
Sun Mar 18 10:56:44 UTC 2012


Hello list,

just a couple of days ago, I noticed that there's no "lsof" applet in 
busybox. Needing such a tool for an embedded system, I hacked up a very 
lightweight version myself.

It scans for /proc/*/fd/* to get the list of open files and generates an 
output like this:
[...]
31801	/bin/bash	/dev/pts/6
31801	/bin/bash	/dev/pts/6
31861	/bin/bash	/dev/pts/9
31861	/bin/bash	/dev/pts/9
31861	/bin/bash	/dev/pts/9
31861	/bin/bash	/dev/pts/9
32669	/usr/bin/ssh	/dev/pts/3
32669	/usr/bin/ssh	/dev/pts/3
32669	/usr/bin/ssh	/dev/pts/3
32669	/usr/bin/ssh	socket:[48026336]
32669	/usr/bin/ssh	/dev/pts/3
[...]
First column is the process id.
Second column is the output of readlink(/proc/<pid>/exe)
Third column is the output of readlink(/proc/<pid>/fd/<fd#>)
The columns are separated by tabs.

I attached my code, please take a look and tell me if that's of any worth to 
you. While keeping small and simple in mind, the code in itself will most
propably not match the standards of the busybox code. As far as I can tell, 
there are four options:

1) There already is an lsof-like applet, that I just didn't see, so there's 
no need for my tool at all.

2) The whole idea of gathering the information doesn't fit the philosophy 
of busybox, then I'll have to keep it as a separate tool.

3) Someone here on the list takes the code, parts of it, or just the idea to 
create an applet.

4) Someone shows me the ropes and I'll try to write the applet myself and 
submit a patch. (By "showing the ropes" I mean something like "There is 
already a function, running a callback for each entry of a directory, so no 
need to implement your own, applet X is a good example. And take a look at 
applet Y to see how memory allocation should be done.").

Either one of these options would be fine with me. Please, let know what you 
think.


Greetings,
SvOlli
-- 
|  _______       |
| (  /\          | If I were a baseball stadium, it would
|__)v\/lli a.k.a.| be time to tear me down.
|Sven Oliver Moll|   -- Drabble by Kevin Fagan, September 22nd 1999
-------------- next part --------------
A non-text attachment was scrubbed...
Name: aslsof.c
Type: text/x-csrc
Size: 2492 bytes
Desc: 
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20120318/f6434ffd/attachment.c>


More information about the busybox mailing list