lsof でファイルオープンのフラグを確認できる

↑ 同僚のエントリを読んで 早速調べものをしていたのだが、8進数で書かれたフラグを理解するのがちょっと大変。 lsof あたりで人間が読みやすくするようにサポートしてないのかな? ... と調べたらあった!

lsof +f g オプション

lsof に +f g って付ける良い。以下は apache2 の lsof をとった内容

$ sudo lsof +f g -p 5087 | tail
apache2 5087 www-data  DEL       REG                    0,5             32893 /dev/zero
apache2 5087 www-data    0r      CHR              LG    1,3      0t0        6 /dev/null
apache2 5087 www-data    1w      CHR            W,LG    1,3      0t0        6 /dev/null
apache2 5087 www-data    2w      REG         W,AP,LG  252,0      739 35389666 /var/log/apache2/error.log
apache2 5087 www-data    3u     IPv4   RW,ND,0x80000  67450      0t0      TCP *:http (LISTEN)
apache2 5087 www-data    4r     FIFO         0x80000   0,10      0t0    32892 pipe
apache2 5087 www-data    5w     FIFO       W,0x80000   0,10      0t0    32892 pipe
apache2 5087 www-data    6w      REG W,AP,LG,0x80000  252,0        0 35389607 /var/log/apache2/other_vhosts_access.log
apache2 5087 www-data    7w      REG W,AP,LG,0x80000  252,0        0 35389605 /var/log/apache2/access.log
apache2 5087 www-data    8u  a_inode      RW,0x80000   0,11        0    12000 [eventpoll]

フラグは略記されており、それぞれの読み方は man に書いてあります

       FILE-FLAG  when  g or G has been specified to +f, this field contains the contents of the f_flag[s] member of the kernel file structure and the kernel's per-process open file flags (if available); `G'
                  causes them to be displayed in hexadecimal; `g', as short-hand names; two lists may be displayed with entries separated by commas, the lists separated by a semicolon (`;'); the  first  list
                  may contain short-hand names for f_flag[s] values from the following table:

                       AIO       asynchronous I/O (e.g., FAIO)
                       AP        append
                       ASYN      asynchronous I/O (e.g., FASYNC)
                       BAS       block, test, and set in use
                       BKIU      block if in use
                       BL        use block offsets
                       BSK       block seek
                       CA        copy avoid
                       CIO       concurrent I/O
                       CLON      clone
                       CLRD      CL read
                       CR        create
                       DF        defer
                       DFI       defer IND
                       DFLU      data flush
                       DIR       direct
                       DLY       delay
                       DOCL      do clone
                       DSYN      data-only integrity
                       DTY       must be a directory
                       EVO       event only
                       EX        open for exec
                       EXCL      exclusive open
                       FSYN      synchronous writes
                       GCDF      defer during unp_gc() (AIX)
                       GCMK      mark during unp_gc() (AIX)
                       GTTY      accessed via /dev/tty
                       HUP       HUP in progress
                       KERN      kernel
                       KIOC      kernel-issued ioctl
                       LCK       has lock
                       LG        large file
                       MBLK      stream message block
                       MK        mark
                       MNT       mount
                       MSYN      multiplex synchronization
                       NATM      don't update atime
                       NB        non-blocking I/O
                       NBDR      no BDRM check
                       NBIO      SYSV non-blocking I/O
                       NBF       n-buffering in effect
                       NC        no cache
                       ND        no delay
                       NDSY      no data synchronization
                       NET       network
                       NFLK      don't follow links
                       NMFS      NM file system
                       NOTO      disable background stop
                       NSH       no share
                       NTTY      no controlling TTY
                       OLRM      OLR mirror
                       PAIO      POSIX asynchronous I/O
                       PP        POSIX pipe
                       R         read
                       RC        file and record locking cache
                       REV       revoked
                       RSH       shared read
                       RSYN      read synchronization
                       RW        read and write access
                       SL        shared lock
                       SNAP      cooked snapshot
                       SOCK      socket
                       SQSH      Sequent shared set on open
                       SQSV      Sequent SVM set on open
                       SQR       Sequent set repair on open
                       SQS1      Sequent full shared open
                       SQS2      Sequent partial shared open
                       STPI      stop I/O
                       SWR       synchronous read
                       SYN       file integrity while writing
                       TCPM      avoid TCP collision
                       TR        truncate
                       W         write
                       WKUP      parallel I/O synchronization
                       WTG       parallel I/O synchronization
                       VH        vhangup pending
                       VTXT      virtual text
                       XL        exclusive lock

                  this  list  of names was derived from F* #define's in dialect header files <fcntl.h>, <linux</fs.h>, <sys/fcntl.c>, <sys/fcntlcom.h>, and <sys/file.h>; see the lsof.h header file for a list
                  showing the correspondence between the above short-hand names and the header file definitions;

                  the second list (after the semicolon) may contain short-hand names for kernel per-process open file flags from this table:

                       ALLC      allocated
                       BR        the file has been read
                       BHUP      activity stopped by SIGHUP
                       BW        the file has been written
                       CLSG      closing
                       CX        close-on-exec (see fcntl(F_SETFD))
                       LCK       lock was applied
                       MP        memory-mapped
                       OPIP      open pending - in progress
                       RSVW      reserved wait
                       SHMT      UF_FSHMAT set (AIX)
                       USE       in use (multi-threaded)