forked from mkerrisk/man-pages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproc.5
6862 lines (6862 loc) · 203 KB
/
proc.5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.\" Copyright (C) 1994, 1995 by Daniel Quinlan ([email protected])
.\" and Copyright (C) 2002-2008,2017 Michael Kerrisk <[email protected]>
.\" with networking additions from Alan Cox ([email protected])
.\" and scsi additions from Michael Neuffer ([email protected])
.\" and sysctl additions from Andries Brouwer ([email protected])
.\" and System V IPC (as well as various other) additions from
.\" Michael Kerrisk <[email protected]>
.\"
.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
.\" This is free documentation; you can redistribute it and/or
.\" modify it under the terms of the GNU General Public License as
.\" published by the Free Software Foundation; either version 2 of
.\" the License, or (at your option) any later version.
.\"
.\" The GNU General Public License's references to "object code"
.\" and "executables" are to be interpreted as the output of any
.\" document formatting or typesetting system, including
.\" intermediate and printed output.
.\"
.\" This manual is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public
.\" License along with this manual; if not, see
.\" <http://www.gnu.org/licenses/>.
.\" %%%LICENSE_END
.\"
.\" Modified 1995-05-17 by [email protected]
.\" Minor changes by aeb and Marty Leisner ([email protected]).
.\" Modified 1996-04-13, 1996-07-22 by [email protected]
.\" Modified 2001-12-16 by [email protected]
.\" Modified 2002-07-13 by [email protected]
.\" Modified 2002-07-22, 2003-05-27, 2004-04-06, 2004-05-25
.\" by Michael Kerrisk <[email protected]>
.\" 2004-11-17, mtk -- updated notes on /proc/loadavg
.\" 2004-12-01, mtk, rtsig-max and rtsig-nr went away in 2.6.8
.\" 2004-12-14, mtk, updated 'statm', and fixed error in order of list
.\" 2005-05-12, mtk, updated 'stat'
.\" 2005-07-13, mtk, added /proc/sys/fs/mqueue/*
.\" 2005-09-16, mtk, Added /proc/sys/fs/suid_dumpable
.\" 2005-09-19, mtk, added /proc/zoneinfo
.\" 2005-03-01, mtk, moved /proc/sys/fs/mqueue/* material to mq_overview.7.
.\" 2008-06-05, mtk, Added /proc/[pid]/oom_score, /proc/[pid]/oom_adj,
.\" /proc/[pid]/limits, /proc/[pid]/mountinfo, /proc/[pid]/mountstats,
.\" and /proc/[pid]/fdinfo/*.
.\" 2008-06-19, mtk, Documented /proc/[pid]/status.
.\" 2008-07-15, mtk, added /proc/config.gz
.\"
.\" FIXME cross check against Documentation/filesystems/proc.txt
.\" to see what information could be imported from that file
.\" into this file.
.\"
.TH PROC 5 2021-08-27 "Linux" "Linux Programmer's Manual"
.SH NAME
proc \- process information pseudo-filesystem
.SH DESCRIPTION
The
.B proc
filesystem is a pseudo-filesystem which provides an interface to
kernel data structures.
It is commonly mounted at
.IR /proc .
Typically, it is mounted automatically by the system,
but it can also be mounted manually using a command such as:
.PP
.in +4n
.EX
mount \-t proc proc /proc
.EE
.in
.PP
Most of the files in the
.B proc
filesystem are read-only,
but some files are writable, allowing kernel variables to be changed.
.\"
.SS Mount options
The
.B proc
filesystem supports the following mount options:
.TP
.BR hidepid "=\fIn\fP (since Linux 3.3)"
.\" commit 0499680a42141d86417a8fbaa8c8db806bea1201
This option controls who can access the information in
.IR /proc/[pid]
directories.
The argument,
.IR n ,
is one of the following values:
.RS
.TP 4
0
Everybody may access all
.IR /proc/[pid]
directories.
This is the traditional behavior,
and the default if this mount option is not specified.
.TP
1
Users may not access files and subdirectories inside any
.IR /proc/[pid]
directories but their own (the
.IR /proc/[pid]
directories themselves remain visible).
Sensitive files such as
.IR /proc/[pid]/cmdline
and
.IR /proc/[pid]/status
are now protected against other users.
This makes it impossible to learn whether any user is running a
specific program
(so long as the program doesn't otherwise reveal itself by its behavior).
.\" As an additional bonus, since
.\" .IR /proc/[pid]/cmdline
.\" is inaccessible for other users,
.\" poorly written programs passing sensitive information via
.\" program arguments are now protected against local eavesdroppers.
.TP
2
As for mode 1, but in addition the
.IR /proc/[pid]
directories belonging to other users become invisible.
This means that
.IR /proc/[pid]
entries can no longer be used to discover the PIDs on the system.
This doesn't hide the fact that a process with a specific PID value exists
(it can be learned by other means, for example, by "kill \-0 $PID"),
but it hides a process's UID and GID,
which could otherwise be learned by employing
.BR stat (2)
on a
.IR /proc/[pid]
directory.
This greatly complicates an attacker's task of gathering
information about running processes (e.g., discovering whether
some daemon is running with elevated privileges,
whether another user is running some sensitive program,
whether other users are running any program at all, and so on).
.RE
.TP
.BR gid "=\fIgid\fP (since Linux 3.3)"
.\" commit 0499680a42141d86417a8fbaa8c8db806bea1201
Specifies the ID of a group whose members are authorized to
learn process information otherwise prohibited by
.BR hidepid
(i.e., users in this group behave as though
.I /proc
was mounted with
.IR hidepid=0 ).
This group should be used instead of approaches such as putting
nonroot users into the
.BR sudoers (5)
file.
.\"
.SS Overview
Underneath
.IR /proc ,
there are the following general groups of files and subdirectories:
.TP
.IR /proc/[pid] " subdirectories"
Each one of these subdirectories contains files and subdirectories
exposing information about the process with the corresponding process ID.
.IP
Underneath each of the
.I /proc/[pid]
directories, a
.I task
subdirectory contains subdirectories of the form
.IR task/[tid] ,
which contain corresponding information about each of the threads
in the process, where
.I tid
is the kernel thread ID of the thread.
.IP
The
.I /proc/[pid]
subdirectories are visible when iterating through
.I /proc
with
.BR getdents (2)
(and thus are visible when one uses
.BR ls (1)
to view the contents of
.IR /proc ).
.TP
.IR /proc/[tid] " subdirectories"
Each one of these subdirectories contains files and subdirectories
exposing information about the thread with the corresponding thread ID.
The contents of these directories are the same as the corresponding
.IR /proc/[pid]/task/[tid]
directories.
.IP
The
.I /proc/[tid]
subdirectories are
.I not
visible when iterating through
.I /proc
with
.BR getdents (2)
(and thus are
.I not
visible when one uses
.BR ls (1)
to view the contents of
.IR /proc ).
.TP
.I /proc/self
When a process accesses this magic symbolic link,
it resolves to the process's own
.I /proc/[pid]
directory.
.TP
.I /proc/thread\-self
When a thread accesses this magic symbolic link,
it resolves to the process's own
.I /proc/self/task/[tid]
directory.
.TP
.I /proc/[a\-z]*
Various other files and subdirectories under
.I /proc
expose system-wide information.
.PP
All of the above are described in more detail below.
.\"
.SS Files and directories
The following list provides details of many of the files and directories
under the
.I /proc
hierarchy.
.TP
.I /proc/[pid]
There is a numerical subdirectory for each running process; the
subdirectory is named by the process ID.
Each
.I /proc/[pid]
subdirectory contains the pseudo-files and directories described below.
.IP
The files inside each
.I /proc/[pid]
directory are normally owned by the effective user and
effective group ID of the process.
However, as a security measure, the ownership is made
.IR root:root
if the process's "dumpable" attribute is set to a value other than 1.
.IP
Before Linux 4.11,
.\" commit 68eb94f16227336a5773b83ecfa8290f1d6b78ce
.IR root:root
meant the "global" root user ID and group ID
(i.e., UID 0 and GID 0 in the initial user namespace).
Since Linux 4.11,
if the process is in a noninitial user namespace that has a
valid mapping for user (group) ID 0 inside the namespace, then
the user (group) ownership of the files under
.I /proc/[pid]
is instead made the same as the root user (group) ID of the namespace.
This means that inside a container,
things work as expected for the container "root" user.
.IP
The process's "dumpable" attribute may change for the following reasons:
.RS
.IP * 3
The attribute was explicitly set via the
.BR prctl (2)
.B PR_SET_DUMPABLE
operation.
.IP *
The attribute was reset to the value in the file
.IR /proc/sys/fs/suid_dumpable
(described below), for the reasons described in
.BR prctl (2).
.RE
.IP
Resetting the "dumpable" attribute to 1 reverts the ownership of the
.IR /proc/[pid]/*
files to the process's effective UID and GID.
Note, however, that if the effective UID or GID is subsequently modified,
then the "dumpable" attribute may be reset, as described in
.BR prctl (2).
Therefore, it may be desirable to reset the "dumpable" attribute
.I after
making any desired changes to the process's effective UID or GID.
.TP
.I /proc/[pid]/attr
.\" https://lwn.net/Articles/28222/
.\" From: Stephen Smalley <[email protected]>
.\" To: LKML and others
.\" Subject: [RFC][PATCH] Process Attribute API for Security Modules
.\" Date: 08 Apr 2003 16:17:52 -0400
.\"
.\" http://www.nsa.gov/research/_files/selinux/papers/module/x362.shtml
.\"
The files in this directory provide an API for security modules.
The contents of this directory are files that can be read and written
in order to set security-related attributes.
This directory was added to support SELinux,
but the intention was that the API be general enough to support
other security modules.
For the purpose of explanation,
examples of how SELinux uses these files are provided below.
.IP
This directory is present only if the kernel was configured with
.BR CONFIG_SECURITY .
.TP
.IR /proc/[pid]/attr/current " (since Linux 2.6.0)"
The contents of this file represent the current
security attributes of the process.
.IP
In SELinux, this file is used to get the security context of a process.
Prior to Linux 2.6.11, this file could not be used to set the security
context (a write was always denied), since SELinux limited process security
transitions to
.BR execve (2)
(see the description of
.IR /proc/[pid]/attr/exec ,
below).
Since Linux 2.6.11, SELinux lifted this restriction and began supporting
"set" operations via writes to this node if authorized by policy,
although use of this operation is only suitable for applications that are
trusted to maintain any desired separation between the old and new security
contexts.
.IP
Prior to Linux 2.6.28, SELinux did not allow threads within a
multithreaded process to set their security context via this node
as it would yield an inconsistency among the security contexts of the
threads sharing the same memory space.
Since Linux 2.6.28, SELinux lifted
this restriction and began supporting "set" operations for threads within
a multithreaded process if the new security context is bounded by the old
security context, where the bounded relation is defined in policy and
guarantees that the new security context has a subset of the permissions
of the old security context.
.IP
Other security modules may choose to support "set" operations via
writes to this node.
.TP
.IR /proc/[pid]/attr/exec " (since Linux 2.6.0)"
This file represents the attributes to assign to the
process upon a subsequent
.BR execve (2).
.IP
In SELinux,
this is needed to support role/domain transitions, and
.BR execve (2)
is the preferred point to make such transitions because it offers better
control over the initialization of the process in the new security label
and the inheritance of state.
In SELinux, this attribute is reset on
.BR execve (2)
so that the new program reverts to the default behavior for any
.BR execve (2)
calls that it may make.
In SELinux, a process can set
only its own
.I /proc/[pid]/attr/exec
attribute.
.TP
.IR /proc/[pid]/attr/fscreate " (since Linux 2.6.0)"
This file represents the attributes to assign to files
created by subsequent calls to
.BR open (2),
.BR mkdir (2),
.BR symlink (2),
and
.BR mknod (2)
.IP
SELinux employs this file to support creation of a file
(using the aforementioned system calls)
in a secure state,
so that there is no risk of inappropriate access being obtained
between the time of creation and the time that attributes are set.
In SELinux, this attribute is reset on
.BR execve (2),
so that the new program reverts to the default behavior for
any file creation calls it may make, but the attribute will persist
across multiple file creation calls within a program unless it is
explicitly reset.
In SELinux, a process can set only its own
.IR /proc/[pid]/attr/fscreate
attribute.
.TP
.IR /proc/[pid]/attr/keycreate " (since Linux 2.6.18)"
.\" commit 4eb582cf1fbd7b9e5f466e3718a59c957e75254e
If a process writes a security context into this file,
all subsequently created keys
.RB ( add_key (2))
will be labeled with this context.
For further information, see the kernel source file
.I Documentation/security/keys/core.rst
(or file
.\" commit b68101a1e8f0263dbc7b8375d2a7c57c6216fb76
.I Documentation/security/keys.txt
on Linux between 3.0 and 4.13, or
.\" commit d410fa4ef99112386de5f218dd7df7b4fca910b4
.I Documentation/keys.txt
before Linux 3.0).
.TP
.IR /proc/[pid]/attr/prev " (since Linux 2.6.0)"
This file contains the security context of the process before the last
.BR execve (2);
that is, the previous value of
.IR /proc/[pid]/attr/current .
.TP
.IR /proc/[pid]/attr/socketcreate " (since Linux 2.6.18)"
.\" commit 42c3e03ef6b298813557cdb997bd6db619cd65a2
If a process writes a security context into this file,
all subsequently created sockets will be labeled with this context.
.TP
.IR /proc/[pid]/autogroup " (since Linux 2.6.38)"
.\" commit 5091faa449ee0b7d73bc296a93bca9540fc51d0a
See
.BR sched (7).
.TP
.IR /proc/[pid]/auxv " (since 2.6.0)"
.\" Precisely: Linux 2.6.0-test7
This contains the contents of the ELF interpreter information passed
to the process at exec time.
The format is one \fIunsigned long\fP ID
plus one \fIunsigned long\fP value for each entry.
The last entry contains two zeros.
See also
.BR getauxval (3).
.IP
Permission to access this file is governed by a ptrace access mode
.B PTRACE_MODE_READ_FSCREDS
check; see
.BR ptrace (2).
.TP
.IR /proc/[pid]/cgroup " (since Linux 2.6.24)"
See
.BR cgroups (7).
.TP
.IR /proc/[pid]/clear_refs " (since Linux 2.6.22)"
.\" commit b813e931b4c8235bb42e301096ea97dbdee3e8fe (2.6.22)
.\" commit 398499d5f3613c47f2143b8c54a04efb5d7a6da9 (2.6.32)
.\" commit 040fa02077de01c7e08fa75be6125e4ca5636011 (3.11)
.\"
.\" "Clears page referenced bits shown in smaps output"
.\" write-only, writable only by the owner of the process
.IP
This is a write-only file, writable only by owner of the process.
.IP
The following values may be written to the file:
.RS
.TP
1 (since Linux 2.6.22)
.\" Internally: CLEAR_REFS_ALL
Reset the PG_Referenced and ACCESSED/YOUNG
bits for all the pages associated with the process.
(Before kernel 2.6.32, writing any nonzero value to this file
had this effect.)
.TP
2 (since Linux 2.6.32)
.\" Internally: CLEAR_REFS_ANON
Reset the PG_Referenced and ACCESSED/YOUNG
bits for all anonymous pages associated with the process.
.TP
3 (since Linux 2.6.32)
.\" Internally: CLEAR_REFS_MAPPED
Reset the PG_Referenced and ACCESSED/YOUNG
bits for all file-mapped pages associated with the process.
.RE
.IP
Clearing the PG_Referenced and ACCESSED/YOUNG bits provides a method
to measure approximately how much memory a process is using.
One first inspects the values in the "Referenced" fields
for the VMAs shown in
.IR /proc/[pid]/smaps
to get an idea of the memory footprint of the
process.
One then clears the PG_Referenced and ACCESSED/YOUNG bits
and, after some measured time interval,
once again inspects the values in the "Referenced" fields
to get an idea of the change in memory footprint of the
process during the measured interval.
If one is interested only in inspecting the selected mapping types,
then the value 2 or 3 can be used instead of 1.
.IP
Further values can be written to affect different properties:
.RS
.TP
4 (since Linux 3.11)
Clear the soft-dirty bit for all the pages associated with the process.
.\" Internally: CLEAR_REFS_SOFT_DIRTY
This is used (in conjunction with
.IR /proc/[pid]/pagemap )
by the check-point restore system to discover which pages of a process
have been dirtied since the file
.IR /proc/[pid]/clear_refs
was written to.
.TP
5 (since Linux 4.0)
.\" Internally: CLEAR_REFS_MM_HIWATER_RSS
Reset the peak resident set size ("high water mark") to the process's
current resident set size value.
.RE
.IP
Writing any value to
.IR /proc/[pid]/clear_refs
other than those listed above has no effect.
.IP
The
.IR /proc/[pid]/clear_refs
file is present only if the
.B CONFIG_PROC_PAGE_MONITOR
kernel configuration option is enabled.
.TP
.I /proc/[pid]/cmdline
This read-only file holds the complete command line for the process,
unless the process is a zombie.
.\" In 2.3.26, this also used to be true if the process was swapped out.
In the latter case, there is nothing in this file:
that is, a read on this file will return 0 characters.
The command-line arguments appear in this file as a set of
strings separated by null bytes (\(aq\e0\(aq),
with a further null byte after the last string.
.IP
If, after an
.BR execve (2),
the process modifies its
.I argv
strings, those changes will show up here.
This is not the same thing as modifying the
.I argv
array.
.IP
Furthermore, a process may change the memory location that this file refers via
.BR prctl (2)
operations such as
.BR PR_SET_MM_ARG_START .
.IP
Think of this file as the command line that the process wants you to see.
.TP
.IR /proc/[pid]/comm " (since Linux 2.6.33)"
.\" commit 4614a696bd1c3a9af3a08f0e5874830a85b889d4
This file exposes the process's
.I comm
value\(emthat is, the command name associated with the process.
Different threads in the same process may have different
.I comm
values, accessible via
.IR /proc/[pid]/task/[tid]/comm .
A thread may modify its
.I comm
value, or that of any of other thread in the same thread group (see
the discussion of
.B CLONE_THREAD
in
.BR clone (2)),
by writing to the file
.IR /proc/self/task/[tid]/comm .
Strings longer than
.B TASK_COMM_LEN
(16) characters (including the terminating null byte) are silently truncated.
.IP
This file provides a superset of the
.BR prctl (2)
.B PR_SET_NAME
and
.B PR_GET_NAME
operations, and is employed by
.BR pthread_setname_np (3)
when used to rename threads other than the caller.
The value in this file is used for the
.I %e
specifier in
.IR /proc/sys/kernel/core_pattern ;
see
.BR core (5).
.TP
.IR /proc/[pid]/coredump_filter " (since Linux 2.6.23)"
See
.BR core (5).
.TP
.IR /proc/[pid]/cpuset " (since Linux 2.6.12)"
.\" and/proc/[pid]/task/[tid]/cpuset
See
.BR cpuset (7).
.TP
.I /proc/[pid]/cwd
This is a symbolic link to the current working directory of the process.
To find out the current working directory of process 20,
for instance, you can do this:
.IP
.in +4n
.EX
.RB "$" " cd /proc/20/cwd; pwd \-P"
.EE
.in
.IP
.\" The following was still true as at kernel 2.6.13
In a multithreaded process, the contents of this symbolic link
are not available if the main thread has already terminated
(typically by calling
.BR pthread_exit (3)).
.IP
Permission to dereference or read
.RB ( readlink (2))
this symbolic link is governed by a ptrace access mode
.B PTRACE_MODE_READ_FSCREDS
check; see
.BR ptrace (2).
.TP
.I /proc/[pid]/environ
This file contains the initial environment that was set
when the currently executing program was started via
.BR execve (2).
The entries are separated by null bytes (\(aq\e0\(aq),
and there may be a null byte at the end.
Thus, to print out the environment of process 1, you would do:
.IP
.in +4n
.EX
.RB "$" " cat /proc/1/environ | tr \(aq\e000\(aq \(aq\en\(aq"
.EE
.in
.IP
If, after an
.BR execve (2),
the process modifies its environment
(e.g., by calling functions such as
.BR putenv (3)
or modifying the
.BR environ (7)
variable directly),
this file will
.I not
reflect those changes.
.IP
Furthermore, a process may change the memory location that this file refers via
.BR prctl (2)
operations such as
.BR PR_SET_MM_ENV_START .
.IP
Permission to access this file is governed by a ptrace access mode
.B PTRACE_MODE_READ_FSCREDS
check; see
.BR ptrace (2).
.TP
.I /proc/[pid]/exe
Under Linux 2.2 and later, this file is a symbolic link
containing the actual pathname of the executed command.
This symbolic link can be dereferenced normally; attempting to open
it will open the executable.
You can even type
.I /proc/[pid]/exe
to run another copy of the same executable that is being run by
process [pid].
If the pathname has been unlinked, the symbolic link will contain the
string \(aq(deleted)\(aq appended to the original pathname.
.\" The following was still true as at kernel 2.6.13
In a multithreaded process, the contents of this symbolic link
are not available if the main thread has already terminated
(typically by calling
.BR pthread_exit (3)).
.IP
Permission to dereference or read
.RB ( readlink (2))
this symbolic link is governed by a ptrace access mode
.B PTRACE_MODE_READ_FSCREDS
check; see
.BR ptrace (2).
.IP
Under Linux 2.0 and earlier,
.I /proc/[pid]/exe
is a pointer to the binary which was executed,
and appears as a symbolic link.
A
.BR readlink (2)
call on this file under Linux 2.0 returns a string in the format:
.IP
[device]:inode
.IP
For example, [0301]:1502 would be inode 1502 on device major 03 (IDE,
MFM, etc. drives) minor 01 (first partition on the first drive).
.IP
.BR find (1)
with the
.I \-inum
option can be used to locate the file.
.TP
.I /proc/[pid]/fd/
This is a subdirectory containing one entry for each file which the
process has open, named by its file descriptor, and which is a
symbolic link to the actual file.
Thus, 0 is standard input, 1 standard output, 2 standard error, and so on.
.IP
For file descriptors for pipes and sockets,
the entries will be symbolic links whose content is the
file type with the inode.
A
.BR readlink (2)
call on this file returns a string in the format:
.IP
type:[inode]
.IP
For example,
.I socket:[2248868]
will be a socket and its inode is 2248868.
For sockets, that inode can be used to find more information
in one of the files under
.IR /proc/net/ .
.IP
For file descriptors that have no corresponding inode
(e.g., file descriptors produced by
.BR bpf (2),
.BR epoll_create (2),
.BR eventfd (2),
.BR inotify_init (2),
.BR perf_event_open (2),
.BR signalfd (2),
.BR timerfd_create (2),
and
.BR userfaultfd (2)),
the entry will be a symbolic link with contents of the form
.IP
anon_inode:<file-type>
.IP
In many cases (but not all), the
.I file-type
is surrounded by square brackets.
.IP
For example, an epoll file descriptor will have a symbolic link
whose content is the string
.IR "anon_inode:[eventpoll]" .
.IP
.\"The following was still true as at kernel 2.6.13
In a multithreaded process, the contents of this directory
are not available if the main thread has already terminated
(typically by calling
.BR pthread_exit (3)).
.IP
Programs that take a filename as a command-line argument,
but don't take input from standard input if no argument is supplied,
and programs that write to a file named as a command-line argument,
but don't send their output to standard output
if no argument is supplied, can nevertheless be made to use
standard input or standard output by using
.IR /proc/[pid]/fd
files as command-line arguments.
For example, assuming that
.I \-i
is the flag designating an input file and
.I \-o
is the flag designating an output file:
.IP
.in +4n
.EX
.RB "$" " foobar \-i /proc/self/fd/0 \-o /proc/self/fd/1 ..."
.EE
.in
.IP
and you have a working filter.
.\" The following is not true in my tests (MTK):
.\" Note that this will not work for
.\" programs that seek on their files, as the files in the fd directory
.\" are not seekable.
.IP
.I /proc/self/fd/N
is approximately the same as
.I /dev/fd/N
in some UNIX and UNIX-like systems.
Most Linux MAKEDEV scripts symbolically link
.I /dev/fd
to
.IR /proc/self/fd ,
in fact.
.IP
Most systems provide symbolic links
.IR /dev/stdin ,
.IR /dev/stdout ,
and
.IR /dev/stderr ,
which respectively link to the files
.IR 0 ,
.IR 1 ,
and
.IR 2
in
.IR /proc/self/fd .
Thus the example command above could be written as:
.IP
.in +4n
.EX
.RB "$" " foobar \-i /dev/stdin \-o /dev/stdout ..."
.EE
.in
.IP
Permission to dereference or read
.RB ( readlink (2))
the symbolic links in this directory is governed by a ptrace access mode
.B PTRACE_MODE_READ_FSCREDS
check; see
.BR ptrace (2).
.IP
Note that for file descriptors referring to inodes (pipes and sockets, see above),
those inodes still have permission bits and ownership information
distinct from those of the
.I /proc/[pid]/fd
entry,
and that the owner may differ from the user and group IDs of the process.
An unprivileged process may lack permissions to open them, as in this example:
.IP
.in +4n
.EX
.RB "$" " echo test | sudo \-u nobody cat"
test
.RB "$" " echo test | sudo \-u nobody cat /proc/self/fd/0"
cat: /proc/self/fd/0: Permission denied
.EE
.in
.IP
File descriptor 0 refers to the pipe created by the shell
and owned by that shell's user, which is not
.IR nobody ,
so
.B cat
does not have permission to create a new file descriptor to read from that inode,
even though it can still read from its existing file descriptor 0.
.TP
.IR /proc/[pid]/fdinfo/ " (since Linux 2.6.22)"
This is a subdirectory containing one entry for each file which the
process has open, named by its file descriptor.
The files in this directory are readable only by the owner of the process.
The contents of each file can be read to obtain information
about the corresponding file descriptor.
The content depends on the type of file referred to by the
corresponding file descriptor.
.IP
For regular files and directories, we see something like:
.IP
.in +4n
.EX
.RB "$" " cat /proc/12015/fdinfo/4"
pos: 1000
flags: 01002002
mnt_id: 21
.EE
.in
.IP
The fields are as follows:
.RS
.TP
.I pos
This is a decimal number showing the file offset.
.TP
.I flags
This is an octal number that displays the
file access mode and file status flags (see
.BR open (2)).
If the close-on-exec file descriptor flag is set, then
.I flags
will also include the value
.BR O_CLOEXEC .
.IP
Before Linux 3.1,
.\" commit 1117f72ea0217ba0cc19f05adbbd8b9a397f5ab7
this field incorrectly displayed the setting of
.B O_CLOEXEC
at the time the file was opened,
rather than the current setting of the close-on-exec flag.
.TP
.I
.I mnt_id
This field, present since Linux 3.15,
.\" commit 49d063cb353265c3af701bab215ac438ca7df36d
is the ID of the mount containing this file.
See the description of
.IR /proc/[pid]/mountinfo .
.RE
.IP
For eventfd file descriptors (see
.BR eventfd (2)),
we see (since Linux 3.8)
.\" commit cbac5542d48127b546a23d816380a7926eee1c25
the following fields:
.IP
.in +4n
.EX
pos: 0
flags: 02
mnt_id: 10
eventfd\-count: 40
.EE
.in
.IP
.I eventfd\-count
is the current value of the eventfd counter, in hexadecimal.
.IP
For epoll file descriptors (see
.BR epoll (7)),
we see (since Linux 3.8)
.\" commit 138d22b58696c506799f8de759804083ff9effae
the following fields:
.IP
.in +4n
.EX
pos: 0
flags: 02
mnt_id: 10
tfd: 9 events: 19 data: 74253d2500000009
tfd: 7 events: 19 data: 74253d2500000007
.EE
.in
.IP
Each of the lines beginning
.I tfd
describes one of the file descriptors being monitored via
the epoll file descriptor (see
.BR epoll_ctl (2)
for some details).
The
.IR tfd
field is the number of the file descriptor.
The
.I events
field is a hexadecimal mask of the events being monitored for this file
descriptor.
The
.I data
field is the data value associated with this file descriptor.
.IP
For signalfd file descriptors (see
.BR signalfd (2)),
we see (since Linux 3.8)
.\" commit 138d22b58696c506799f8de759804083ff9effae
the following fields:
.IP
.in +4n
.EX
pos: 0
flags: 02
mnt_id: 10
sigmask: 0000000000000006
.EE
.in
.IP
.I sigmask
is the hexadecimal mask of signals that are accepted via this
signalfd file descriptor.
(In this example, bits 2 and 3 are set, corresponding to the signals
.B SIGINT
and
.BR SIGQUIT ;
see
.BR signal (7).)
.IP
For inotify file descriptors (see
.BR inotify (7)),
we see (since Linux 3.8)
the following fields:
.IP
.in +4n
.EX
pos: 0
flags: 00
mnt_id: 11
inotify wd:2 ino:7ef82a sdev:800001 mask:800afff ignored_mask:0 fhandle\-bytes:8 fhandle\-type:1 f_handle:2af87e00220ffd73
inotify wd:1 ino:192627 sdev:800001 mask:800afff ignored_mask:0 fhandle\-bytes:8 fhandle\-type:1 f_handle:27261900802dfd73
.EE
.in
.IP
Each of the lines beginning with "inotify" displays information about
one file or directory that is being monitored.
The fields in this line are as follows:
.RS
.TP
.I wd
A watch descriptor number (in decimal).
.TP
.I ino
The inode number of the target file (in hexadecimal).
.TP
.I sdev
The ID of the device where the target file resides (in hexadecimal).
.TP
.I mask
The mask of events being monitored for the target file (in hexadecimal).
.RE
.IP
If the kernel was built with exportfs support, the path to the target
file is exposed as a file handle, via three hexadecimal fields:
.IR fhandle\-bytes ,
.IR fhandle\-type ,
and
.IR f_handle .
.IP
For fanotify file descriptors (see
.BR fanotify (7)),
we see (since Linux 3.8)
the following fields:
.IP
.in +4n
.EX
pos: 0
flags: 02