The procps
manpage states that the flags
field in files in /proc/PID/fdinfo/
is an octal number indicating the file access mode and file status flags.
The open
manpage gives explanations of various flags (O_APPEND
, O_ASYNC
, etc.) but no corresponding octal values.
Are these octal values listed anywhere, or do I have to search through the linux source code? (and if so then where?).
Asked
Active
Viewed 2,393 times
4

Ben
- 315
1 Answers
2
I’m not aware of documentation listing the values of the flag constants, but you don’t need to search through source code or even header files, you can ask the compiler:
echo O_APPEND | gcc -include fcntl.h -E -
Going over all the flags in open(2)
on x86-64 Linux:
$ for flag in APPEND ASYNC CLOEXEC CREAT DIRECT DIRECTORY DSYNC EXCL LARGEFILE NOATIME NOCTTY NOFOLLOW NONBLOCK PATH SYNC TMPFILE TRUNC; do printf '%s: ' O_$flag; echo O_$flag | gcc -D_GNU_SOURCE -include fcntl.h -E - | tail -n 1; done
Flag | Value |
---|---|
O_APPEND |
02000 |
O_ASYNC |
020000 |
O_CLOEXEC |
02000000 |
O_CREAT |
0100 |
O_DIRECT |
040000 |
O_DIRECTORY |
0200000 |
O_DSYNC |
010000 |
O_EXCL |
0200 |
O_LARGEFILE |
0 |
O_NOATIME |
01000000 |
O_NOCTTY |
0400 |
O_NOFOLLOW |
0400000 |
O_NONBLOCK |
04000 |
O_PATH |
010000000 |
O_SYNC |
04010000 |
O_TMPFILE |
(020000000 | 0200000) |
O_TRUNC |
01000 |
(Some of these are architecture-specific; for example O_LARGEFILE
is 0100000 on i386.)

Stephen Kitt
- 434,908
lsof +fg <FD>
to get a list of the fdinfo flags codes, with descriptions listed in thelsof
manpage. From this I figured out that 0100002 = O_LARGEFILE|O_RDRW, which means that O_LARGEFILE = 0100000 even though your one-liner printed it as 0 on my x86_64 system, strange. – Ben Mar 20 '21 at 01:55