pfiles

pfiles

This is not a tutorial, just a hint from my toolbox. On customer systems I see the lsof tool quite often. But for a quick check for open files you don’t need it.

There is a small, but extremely useful tool in the collection of the p*-tools: pfiles prints all open files of a process. It takes the PID of the process to specify the process.

# pfiles 214
214:	/usr/lib/inet/in.iked
  Current rlimit: 256 file descriptors
   0: S_IFDIR mode:0755 dev:102,0 ino:2 uid:0 gid:0 size:512
      O_RDONLY|O_LARGEFILE
      /
   1: S_IFDIR mode:0755 dev:102,0 ino:2 uid:0 gid:0 size:512
      O_RDONLY|O_LARGEFILE
      /
   2: S_IFDIR mode:0755 dev:102,0 ino:2 uid:0 gid:0 size:512
      O_RDONLY|O_LARGEFILE
      /
   3: S_IFREG mode:0600 dev:102,0 ino:28994 uid:0 gid:0 size:47372
      O_RDWR|O_APPEND|O_CREAT|O_LARGEFILE
      /var/log/in.iked.log
   4: S_IFSOCK mode:0666 dev:304,0 ino:48934 uid:0 gid:0 size:0
      O_RDWR|O_NONBLOCK
	SOCK_RAW
	SO_SNDBUF(8192),SO_RCVBUF(8192)
	sockname: AF_INET 10.211.55.200  port: 4500
	peername: AF_INET 10.211.55.200  port: 4500
 [..]
  10: S_IFDOOR mode:0777 dev:306,0 ino:0 uid:0 gid:0 size:0
      O_RDWR FD_CLOEXEC  door to in.iked[214]

And with the xargs tool there is an easy way to print out all open files on the system.

# ps -ef -o pid | sort | xargs pfiles  | more</b>
0:	sched
  [system process]
1:	/sbin/init
  Current rlimit: 256 file descriptors
   0: S_IFIFO mode:0600 dev:301,3 ino:448255748 uid:0 gid:0 size:0
      O_RDWR|O_NDELAY
      /var/run/initpipe
 253: S_IFREG mode:0444 dev:298,1 ino:65538 uid:0 gid:0 size:0
      O_RDONLY|O_LARGEFILE FD_CLOEXEC
      /system/contract/process/pbundle
 254: S_IFREG mode:0666 dev:298,1 ino:65539 uid:0 gid:0 size:0
      O_RDWR|O_LARGEFILE FD_CLOEXEC
      /system/contract/process/template
 255: S_IFREG mode:0666 dev:298,1 ino:65539 uid:0 gid:0 size:0
      O_RDWR|O_LARGEFILE FD_CLOEXEC
      /system/contract/process/template
[...]