1PROC(5) Linux Programmer's Manual PROC(5)
2
3
4
6 proc - process information pseudo-file system
7
9 The proc file system is a pseudo-file system which is used as an inter‐
10 face to kernel data structures. It is commonly mounted at /proc. Most
11 of it is read-only, but some files allow kernel variables to be
12 changed.
13
14 The following outline gives a quick tour through the /proc hierarchy.
15
16 /proc/[pid]
17 There is a numerical subdirectory for each running process; the
18 subdirectory is named by the process ID. Each such subdirectory
19 contains the following pseudo-files and directories.
20
21 /proc/[pid]/auxv (since 2.6.0-test7)
22 This contains the contents of the ELF interpreter information
23 passed to the process at exec time. The format is one unsigned
24 long ID plus one unsigned long value for each entry. The last
25 entry contains two zeros.
26
27 /proc/[pid]/cmdline
28 This holds the complete command line for the process, unless the
29 process is a zombie. In the latter case, there is nothing in
30 this file: that is, a read on this file will return 0 charac‐
31 ters. The command-line arguments appear in this file as a set
32 of null-separated strings, with a further null byte ('\0') after
33 the last string.
34
35 /proc/[pid]/coredump_filter (since kernel 2.6.23)
36 See core(5).
37
38 /proc/[pid]/cpuset (since kernel 2.6.12)
39 See cpuset(7).
40
41 /proc/[pid]/cwd
42 This is a symbolic link to the current working directory of the
43 process. To find out the current working directory of process
44 20, for instance, you can do this:
45
46 $ cd /proc/20/cwd; /bin/pwd
47
48 Note that the pwd command is often a shell built-in, and might
49 not work properly. In bash(1), you may use pwd -P.
50
51 In a multithreaded process, the contents of this symbolic link
52 are not available if the main thread has already terminated
53 (typically by calling pthread_exit(3)).
54
55 /proc/[pid]/environ
56 This file contains the environment for the process. The entries
57 are separated by null bytes ('\0'), and there may be a null byte
58 at the end. Thus, to print out the environment of process 1,
59 you would do:
60
61 $ (cat /proc/1/environ; echo) | tr '\000' '\n'
62
63 /proc/[pid]/exe
64 Under Linux 2.2 and later, this file is a symbolic link contain‐
65 ing the actual pathname of the executed command. This symbolic
66 link can be dereferenced normally; attempting to open it will
67 open the executable. You can even type /proc/[pid]/exe to run
68 another copy of the same executable as is being run by process
69 [pid]. In a multithreaded process, the contents of this sym‐
70 bolic link are not available if the main thread has already ter‐
71 minated (typically by calling pthread_exit(3)).
72
73 Under Linux 2.0 and earlier /proc/[pid]/exe is a pointer to the
74 binary which was executed, and appears as a symbolic link. A
75 readlink(2) call on this file under Linux 2.0 returns a string
76 in the format:
77
78 [device]:inode
79
80 For example, [0301]:1502 would be inode 1502 on device major 03
81 (IDE, MFM, etc. drives) minor 01 (first partition on the first
82 drive).
83
84 find(1) with the -inum option can be used to locate the file.
85
86 /proc/[pid]/fd
87 This is a subdirectory containing one entry for each file which
88 the process has open, named by its file descriptor, and which is
89 a symbolic link to the actual file. Thus, 0 is standard input,
90 1 standard output, 2 standard error, etc.
91
92 In a multithreaded process, the contents of this directory are
93 not available if the main thread has already terminated (typi‐
94 cally by calling pthread_exit(3)).
95
96 Programs that will take a filename as a command-line argument,
97 but will not take input from standard input if no argument is
98 supplied, or that write to a file named as a command-line argu‐
99 ment, but will not send their output to standard output if no
100 argument is supplied, can nevertheless be made to use standard
101 input or standard out using /proc/[pid]/fd. For example, assum‐
102 ing that -i is the flag designating an input file and -o is the
103 flag designating an output file:
104
105 $ foobar -i /proc/self/fd/0 -o /proc/self/fd/1 ...
106
107 and you have a working filter.
108
109 /proc/self/fd/N is approximately the same as /dev/fd/N in some
110 Unix and Unix-like systems. Most Linux MAKEDEV scripts symboli‐
111 cally link /dev/fd to /proc/self/fd, in fact.
112
113 Most systems provide symbolic links /dev/stdin, /dev/stdout, and
114 /dev/stderr, which respectively link to the files 0, 1, and 2 in
115 /proc/self/fd. Thus the example command above could be written
116 as:
117
118 $ foobar -i /dev/stdin -o /dev/stdout ...
119
120 /proc/[pid]/fdinfo/ (since kernel 2.6.22)
121 This is a subdirectory containing one entry for each file which
122 the process has open, named by its file descriptor. The con‐
123 tents of each file can be read to obtain information about the
124 corresponding file descriptor, for example:
125
<