What does the FD column of pipes listed by lsof mean?
Asked Answered
A

3

19

I'm using the following command to get a list of pipes:

lsof | grep PIPE 

I want to know what the values of the FD column mean (the 5th one https://i.sstatic.net/zkjCn.png). I think that r and w mean read and write, respectively, but what does the number which follows each of these chars means?


I know that FD means File Descriptor, what I want to figure out is what means the values shown in the column, like the 3r, 16w, 20r, etc.

Assumpsit answered 5/8, 2014 at 14:1 Comment(1)
Reading right now, I've found that w and r really means write and read. But I still don't know what the number means.Assumpsit
F
31

Files are not only opened as streams. Some of those are listed in lsof's manual:

FD    is the File Descriptor number of the file or:

           cwd  current working directory;
           Lnn  library references (AIX);
           err  FD information error (see NAME column);
           jld  jail directory (FreeBSD);
           ltx  shared library text (code and data);
           Mxx  hex memory-mapped type number xx.
           m86  DOS Merge mapped file;
           mem  memory-mapped file;
           mmap memory-mapped device;
           pd   parent directory;
           rtd  root directory;
           tr   kernel trace file (OpenBSD);
           txt  program text (code and data);
           v86  VP/ix mapped file;

      FD  is  followed  by one of these characters, describing the
      mode under which the file is open:

           r for read access;
           w for write access;
           u for read and write access;
           space if mode unknown and no lock
            character follows;
           '-' if mode unknown and lock
            character follows.

      The mode character is followed by one of these lock  charac-
      ters, describing the type of lock applied to the file:

           N for a Solaris NFS lock of unknown type;
           r for read lock on part of the file;
           R for a read lock on the entire file;
           w for a write lock on part of the file;
           W for a write lock on the entire file;
           u for a read and write lock of any length;
           U for a lock of unknown type;
           x  for an SCO OpenServer Xenix lock on part  of the
      file;
           X for an SCO OpenServer Xenix lock on  the   entire
      file;
           space if there is no lock.

      See  the  LOCKS  section  for  more  information on the lock
      information character.

      The FD column contents constitutes a single field for  pars-
      ing in post-processing scripts.
Favata answered 5/8, 2014 at 14:43 Comment(1)
useless answer/Wooley
P
1

That is file descriptor.

More on it:

File descriptor (FD) is an abstract indicator for accessing a file. The term is generally used in POSIX operating systems.

In POSIX, a file descriptor is an integer, specifically of the C type int. There are three standard POSIX file descriptors, corresponding to the three standard streams, which presumably every process (save perhaps a daemon) should expect to have.

Prasad answered 5/8, 2014 at 14:12 Comment(2)
Sorry Igor, maybe I did not expressed myself correctly. I knew that the FD means File Descriptor, but I want to know exactly what the number and the char means. In the wiki it's shown that 0, 1 and 2 are stdin, stdout and stderr, but, what about a 16r?Assumpsit
r means read access, that mean that file was open in readonly mode, and 16 is just a number of the descriptor. It has no special meaning. You can access the file at /proc/PID/fd/FD where PID and FD are pid of the process and number of the descriptor.Prasad
F
0

A file descriptor is a number that uniquely identifies an open file in a computer's operating system. It describes a data resource, and how that resource may be accessed. This max limit for this field specified in the kernel and can be changed to prevent choking (in case the file descriptor limit is reached).

Ferry answered 25/10, 2022 at 10:2 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.