lsof列出的管道中FD列代表什么意思?

18

我正在使用以下命令获取管道列表:

lsof | grep PIPE 

我想知道FD列中的值代表什么(第五列,http://i.imgur.com/KHczptf.png)。我认为rw分别表示读取写入,但是这些字符后面跟着的数字是什么意思?


我知道FD代表文件描述符,我想找出列中显示的值的含义,例如3r、16w、20r等。


1
我正在阅读,发现w和r实际上是写入和读取的意思。但我仍然不知道数字代表什么。 - William
3个回答

29

文件不仅可以作为流打开。其中一些在lsof的手册中列出:

文件不只能以流的方式打开,lsof的手册中还列出了一些其他的打开方式:

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.

useless answer/ - Alex

1

那是文件描述符

更多信息:

文件描述符(FD)是访问文件的抽象指示器。该术语通常在POSIX操作系统中使用。

在POSIX中,文件描述符是一个整数,具体为C类型int。有三个标准的POSIX文件描述符,对应于三个标准流,每个进程(除了守护进程)都应该期望拥有这些文件描述符。


抱歉,伊戈尔,也许我没有表达清楚。我知道FD代表文件描述符,但我想确切地知道数字和字符的含义。在维基上显示0、1和2是stdin、stdout和stderr,但是16r呢? - William
5
r表示只读权限,这意味着文件以只读模式打开,而16只是描述符的数量,没有特殊含义。您可以在路径/proc/PID/fd/FD中访问该文件,其中PID和FD分别代表进程的pid和描述符号码。 - Igor Chubin

0
文件描述符是计算机操作系统中唯一标识打开文件的数字。它描述了数据资源以及如何访问该资源。内核指定了此字段的最大限制,并且可以更改以防止阻塞(如果已达到文件描述符限制)。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接