List files opened by a PID

lsof -p 15857
Lis all files opened by a particular process id. "PID"
Sample Output
[root@kxt1 prod]# ps -ef | grep dhcp
root     15857     1  0 Apr15 ?        00:00:01 /usr/sbin/dhcpd eth0
root      9694 29635  0 15:12 pts/11   00:00:00 grep dhcp
[root@kxt1 prod]#
[root@kxt1 prod]# lsof -p 15857
COMMAND   PID USER   FD   TYPE             DEVICE    SIZE      NODE NAME
dhcpd   15857 root  cwd    DIR                8,2    4096         2 /
dhcpd   15857 root  rtd    DIR                8,2    4096         2 /
dhcpd   15857 root  txt    REG                8,2  678400    475389 /usr/sbin/dhcpd
dhcpd   15857 root  mem    REG                8,2  105080   1033986 /lib64/ld-2.3.4.so
dhcpd   15857 root  mem    REG                8,2 1493186   1033987 /lib64/tls/libc-2.3.4.so
dhcpd   15857 root  mem    REG                8,2   56902   1032222 /lib64/libnss_files-2.3.4.so
dhcpd   15857 root    0w   REG               8,17   63282   3287672 /var/lib/dhcp/dhcpd.leases
dhcpd   15857 root    3u  unix 0x0000010110312680         717501116 socket
dhcpd   15857 root    4u   raw                            717501119 00000000:0001->00000000:0000 st=07
dhcpd   15857 root    6u  IPv4          717501138               UDP *:bootps
dhcpd   15857 root    7u  sock                0,4         717501137 can't identify protocol

6
By: d4n3sh
2009-04-17 07:16:03

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: