既然你都知道了lsof和fuser,不如参考下它们的实现。下面是fuser的简单实现(busybox)
http://code.google.com/codesearch#gufiwQeQ0iA/trunk/apps/busybox-1.14.2/procps/fuser.c&ct=rc&cd=2&q=fuser.c&sq=/*
fuser [options] FILEs or PORT/PROTOs
Find processes which use FILEs or PORTs
-m Find processes which use same fs as FILEs
-4 Search only IPv4 space
-6 Search only IPv6 space
-s Silent: just exit with 0 if any processes are found
-k Kill found processes (otherwise display PIDs)
-SIGNAL Signal to send (default: TERM)
*/
我大概扫了下,应该是通过扫描/proc来实现的。。。