How to see actual filename that File Descriptor is pointing to for a given processID?


 
Thread Tools Search this Thread
Operating Systems Solaris How to see actual filename that File Descriptor is pointing to for a given processID?
# 1  
Old 12-07-2010
How to see actual filename that File Descriptor is pointing to for a given processID?

Using lsof command I was able to query all Regular Files opened for write.
A specific processID related output shows some FileDescriptors(FD 45 in second output 45w) pointing to real file. But most of the FDs(1, 2, 5 in first output and 31,29,10 in second output) are pointing to root of the disk itself.

1. I want to know what it means if FDs are not pointing to real files.?
2. We are using Solaris8, is there a way that I can see the real files that all these FDs(1,2,5,31,29,10) are pointing to?
We don't have 'DTrace' or 'procfiles' commands available on Solaris8.


Code:
 
$> lsof -T | awk '$4 ~ /[1-9]*w$/ && $5 ~ /REG/ && /2492/' | more
COMMAND     PID     USER   FD   TYPE        DEVICE   SIZE/OFF      NODE NAME
java       2492  usr1    1w  VREG          85,3    7948151   6190579 /export (/dev/md/dsk/d3)
java       2492  usr1    2w  VREG          85,3    7948151   6190579 /export (/dev/md/dsk/d3)
java       2492  usr1    5w  VREG          85,3    2962640   3441379 /export (/dev/md/dsk/d3)


Code:
 
$> lsof -T -u usr1 | awk '$4 ~ /.*[wu]/ && $5 ~ /REG/'
COMMAND     PID     USER   FD   TYPE        DEVICE   SIZE/OFF      NODE NAME
stcms.exe 26244 usr1   31w  VREG         314,6    33555456   9127033 /export/apps/PATH1 (g1:/vol/vol4/share1)
stcms.exe 26244 usr1   29w  VREG         314,6    33555456   9127028 /export/apps/PATH1 (g1:/vol/vol4/share1)
stcms.exe 26244 usr1   10w  VREG         314,6    33555456   9127021 /export/apps/PATH1 (g1:/vol/vol4/share1)
stcms.exe 26204 usr1   45w  VREG         314,6    33555456   4646191 /export/apps/PATH1/PATH2/file1.dbs

# 2  
Old 12-07-2010
A dir is an inode a process can open to examine using dirent, just like a flat file except for the inode status, inability to shrink and internal structure of int inode# and null term char name[] pairs. I get a ton of hits from fuser $HOME. I does seem a bit sloppy to leave them open, but there it is.
# 3  
Old 12-07-2010
The most common cause of lsof or similar being unable to resolve the real pathname a file descriptor is pointing to is that the file has been removed after being opened, but isn't closed yet.
# 4  
Old 12-07-2010
jlliagre I think you are right. Where can I find reference information that could explain what you said.
If its just waiting to be closed, even after few minutes same File Descriptors that are pointing to base disk location are still there. Its as if they are there for some purpose..

Last edited by kchinnam; 12-07-2010 at 03:26 PM.. Reason: more info
# 5  
Old 12-07-2010
Oh, you think it is the old */lost+found/* or .nsf* file for the one deleted but still open (an open file only needs an inode not a name)! I'd think lsof would find the real residual file, not pretend it was some directory. The man says sometimes you get the mount point not the path:

Man Page for lsof (Linux Section 8) - The UNIX and Linux Forums

Code:
       NODE      is the node number of a local file;
 
          or the inode number of an NFS file in the server host;
 
          or the Internet protocol type - e. g, ``TCP'';
 
          or ``STR'' for a stream;
 
          or ``CCITT'' for an HP-UX x.25 socket;
 
          or the IRQ or inode number of a Linux AX.25 socket device.
 
       NAME      is  the name of the mount point and file system on which the
          file resides;
 
          or the name of a file specified in the names    option    (after
          any symbolic links have been resolved);
 
          or the name of a character special or block special device;
 
          or  the  local  and  remote  Internet addresses of a network
          file; the local host name or IP  number  is  followed  by  a
          colon  (':'),  the  port,  ``->'',  and  the two-part remote
          address; IP addresses may be reported as numbers  or    names,
          depending  on  the +|-M, -n, and -P options; colon-separated
          IPv6    numbers  are  enclosed    in   square   brackets;   IPv4
          INADDR_ANY  and  IPv6 IN6_IS_ADDR_UNSPECIFIED addresses, and
          zero port numbers are represented by an  asterisk  ('*');  a
          UDP  destination  address  may  be followed by the amount of
          time elapsed since the last packet was sent to the  destina-
          tion;  TCP, UDP and UDPLITE remote addresses may be followed
          by  TCP/TPI  information  in    parentheses  -    state    (e.g.,
          ``(ESTABLISHED)'',  ``(Unbound)''),  queue sizes, and window
          sizes (not all dialects) - in a fashion similar to what net-
          stat(1)  reports;  see  the  -T  option  description    or the
          description of the TCP/TPI field in OUTPUT  FOR  OTHER  PRO-
          GRAMS  for more information on state, queue size, and window
          size;
 
          or the address or name of a  UNIX  domain  socket,  possibly
          including a stream clone device name, a file system object's
          path name, local and foreign kernel addresses,  socket  pair
          information, and a bound vnode address;
 
          or the local and remote mount point names of an NFS file;
 
          or ``STR'', followed by the stream name;
 
          or  a  stream  character device name, followed by ``->'' and
          the stream name or a list of stream module names,  separated
          by ``->'';
 
          or ``STR:'' followed by the SCO OpenServer stream device and
          module names, separated by ``->'';
 
          or system directory name, `` -- '', and as  many  components
          of the path name as lsof can find in the kernel's name cache
          for selected dialects (See the KERNEL NAME CACHE section for
          more information.);
 
          or ``PIPE->'', followed by a Solaris kernel pipe destination
          address;
 
          or ``COMMON:'', followed by  the  vnode  device  information
          structure's device name, for a Solaris common vnode;
 
          or  the  address family, followed by a slash (`/'), followed
          by fourteen comma-separated  bytes  of  a  non-Internet  raw
          socket address;
 
          or  the  HP-UX  x.25    local address, followed by the virtual
          connection number (if any), followed by the  remote  address
          (if any);
 
          or ``(dead)'' for disassociated Tru64 UNIX files - typically
          terminal files that have been  flagged  with    the  TIOCNOTTY
          ioctl and closed by daemons;
 
          or ``rd=<offset>'' and ``wr=<offset>'' for the values of the
          read and write offsets of a FIFO;
 
          or ``clone n:/dev/event'' for SCO OpenServer file clones  of
          the /dev/event device, where n is the minor device number of
          the file;
 
          or ``(socketpair: n)'' for a Solaris 2.6, 8, 9  or  10  UNIX
          domain  socket,  created by the socketpair(3N) network func-
          tion;
 
          or ``no PCB'' for socket files that do not have  a  protocol
          block  associated  with  them,  optionally  followed    by ``,
          CANTSENDMORE'' if sending on the socket has  been  disabled,
          or  ``,  CANTRCVMORE''  if  receiving on the socket has been
          disabled (e.g., by the shutdown(2) function);
 
          or the local and remote addresses of a Linux IPX socket file
          in  the  form <net>:[<node>:]<port>, followed in parentheses
          by the transmit and receive queue sizes, and the  connection
          state;
 
          or  ``dgram''  or ``stream'' for the type UnixWare 7.1.1 and
          above in-kernel UNIX domain sockets,    followed  by  a  colon
          (':')  and  the  local path name when available, followed by
          ``->'' and the remote path name or kernel socket address  in
          hexadecimal when available

# 6  
Old 12-07-2010
DGPickett,
I am aware of .nsf 'lost+found' situation. But what I am asking is not specifically about that. If you have Unix/Linx try the following command
Code:
 
$>lsof -u <app_user> -T 2>/dev/null | awk '$4 ~ /[1-9]*[wu]/ && $5 ~ /REG/'

If you see lot of rows in your output look something like below. Then my question is what are all these FileDescriptors [ ex: 11 in 11w] doing? Why are they not pointing to real files? Why are they hanging around forver, as if they are needed by something!

Code:
 
COMMAND     PID     USER   FD   TYPE        DEVICE   SIZE/OFF      NODE NAME
<commad>  4017 <app_user>   11u  VREG          85,3      64521  2590790 /export (/dev/md/dsk/d3)

# 7  
Old 12-07-2010
Quote:
Originally Posted by kchinnam
If its just waiting to be closed, even after few minutes same File Descriptors that are pointing to base disk location are still there.
You misunderstand what I am referring to. A process can remove (unlink) a file while it is still open for reading and/or writing. The file contents stays on disk as long as the process use it. Only the process(es) having the file open before it was unlinked can still access its data. This can be for hours/days or indefinitely.
Quote:
Its as if they are there for some purpose..
Yes, files are almost always used for some purpose Smilie
I don't recall if Solaris 8 already had that feature yet but you can try:
Code:
file /proc/pid#/fd/fd#

with pid# being the process id and fd# the file descriptor number. (eg
26204 and 45 for your sample output)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Actual SQL instead of using a file from within a shell script

I am very noobish to UNIX, our guy is on vacation so I am trying to take up some slack while he is away. Typically when we use sql from within a shell script, we do so from a file containing the sql. Example: $ORACLE_HOME/bin/sqlplus $ORA_DBCU/$ORA_DBCP @${cron_dir}/${report_file}.sql ... (10 Replies)
Discussion started by: biobill
10 Replies

2. Shell Programming and Scripting

redirecting with file descriptor

hello, Someone can help me with redirectors? I am writing this script in bash enviroment on Fedora: exec 4<> /dev/tcp/10.10.11.30/5000 #open socket in input/output strings<&4 >file.txt & I send file descriptor 4 to string command to purge data stream from special char while come from... (3 Replies)
Discussion started by: rattoeur
3 Replies

3. Shell Programming and Scripting

Unlink and copy actual file

Hello, I have a set of directories, which has inside them, symbolic links to some files. What i would like to do is to covert the links into actual files, i.e. remove the link and copy the actual file here... I tried to see unlink command but i think all it does is delete the link, is... (2 Replies)
Discussion started by: prasbala
2 Replies

4. Solaris

Before I delete any file in Unix, How can I check no open file handle is pointing to that file?

I know how to check if any file has a unix process using a file by looking at 'lsof <fullpath/filename>' command. I think using lsof is very expensive. Also to make it accurate we need to inlcude fullpath of the file. Is there another command that can tell if a file has a truely active... (12 Replies)
Discussion started by: kchinnam
12 Replies

5. Shell Programming and Scripting

Open the file and replace the variable with actual value

Hi, i have a sql file named sample.sql. The query is given below. select count(*) from $TABLE_NAME In the main script, i am sourcing this sql. I need to replace the $TABLE_NAME with actual value, before running the query. How can i achieve that? The logic i tried is given below:... (3 Replies)
Discussion started by: bharathappriyan
3 Replies

6. Shell Programming and Scripting

How to create a user interface pointing to a file?

I have to create a user interface in which user can easily update ,delete or insert a new record which is pointing to a file in AIX Server? Using awk,sed ican update ,modify the file. how to create a link to userlike GUI(without using Tomcat,IIS) (3 Replies)
Discussion started by: laknar
3 Replies

7. UNIX for Dummies Questions & Answers

File Descriptor

Hi What the below path contains? /proc/<pid>/fd (1 Reply)
Discussion started by: siba.s.nayak
1 Replies

8. Shell Programming and Scripting

File Descriptor

Hello All, Im opening a file desciptor in perl and sending data using print CMD "$xyz". is there a limit to the length of the string that I can give to this CMD at a time. (3 Replies)
Discussion started by: rimser9
3 Replies

9. UNIX for Dummies Questions & Answers

File Descriptor Help

What is a file descriptor in Unix?? How to find a file descriptor of a file in Unix?? Does it have anything to do with the Inode numbers?? (3 Replies)
Discussion started by: rahulrathod
3 Replies

10. UNIX for Dummies Questions & Answers

file activity (open/closed) file descriptor info using KORN shell scripting

I am trying to find a way to check the current status of a file. Such as some cron job processes are dependent on the completion of others. if a file is currently being accessed / modified or simply open state I will wait until it is done being processed before attempting the next process on that... (3 Replies)
Discussion started by: Gary Dunn
3 Replies
Login or Register to Ask a Question