Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding filename using lsof

Status
Not open for further replies.

BTon15

Programmer
Nov 21, 2001
29
0
0
GB
I have a large C program running on AIX that seems to be consistently leaving an additional 2 files open after processing its input. There are several calls to tempnam and corresponding calls to unlink to remove the temp files after use. It looks like I've maybe missed a couple of unlinks somewhere, but I haven't been able to track them down.

I've been looking at the lsof command, but this only seems to tell me which filesystem the files are opened on. Is there any way to find out the filenames that are currently opened by my process?

I don't mind if I need to do this via my C program, or from a Unix commmand.

Thanks in advance for any help.
 
BTon15,


lsof -p <pid>

should do the trick.


To list all open files for process <pid>


-jouell
 
This only seems to be showing me the filesystems that the files are open in, not the actual filenames.
 
OK. can you send the output?

Here's mine:

$ ps
PID TTY TIME CMD
1095 pts/22 00:00:00 bash
1108 pts/22 00:00:00 ps

$ lsof -p 1095
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
bash 1095 jouell cwd DIR 3,1 4096 13910017 /home/jouell
bash 1095 jouell rtd DIR 3,1 4096 2 /
bash 1095 jouell txt REG 3,1 625228 20529214 /bin/bash
bash 1095 jouell mem REG 3,1 90248 32785 /lib/ld-2.3.2.so
bash 1095 jouell mem REG 3,1 252592 32871 /lib/libncurses.so.5.4
bash 1095 jouell mem REG 3,1 9872 32816 /lib/tls/libdl-2.3.2.so
bash 1095 jouell mem REG 3,1 1254468 32814 /lib/tls/libc-2.3.2.so
bash 1095 jouell mem REG 3,1 290576 21170498 /usr/lib/locale/locale-archive
bash 1095 jouell mem REG 3,1 5920 21153086 /usr/lib/gconv/ISO8859-1.so
bash 1095 jouell mem REG 3,1 28616 32820 /lib/tls/libnss_compat-2.3.2.so
bash 1095 jouell mem REG 3,1 73304 32819 /lib/tls/libnsl-2.3.2.so
bash 1095 jouell mem REG 3,1 33440 32824 /lib/tls/libnss_nis-2.3.2.so
bash 1095 jouell mem REG 3,1 34748 32822 /lib/tls/libnss_files-2.3.2.so
bash 1095 jouell 0u CHR 136,22 24 /dev/pts/22
bash 1095 jouell 1u CHR 136,22 24 /dev/pts/22
bash 1095 jouell 2u CHR 136,22 24 /dev/pts/22
bash 1095 jouell 255u CHR 136,22 24 /dev/pts/22


I'm running Linux, you can see the files open for my shell, pid 1095. What version of lsof do you have, BTW?


-jouell




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top