Debian Codegraph @

upstream/debian-unstable/man5/proc_pid_root.5

raw
1 .\" Copyright 1994-1995, Daniel Quinlan <[email protected]>
2 .\" Copyright 2002-2017, Michael Kerrisk <[email protected]>
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: GPL-3.0-or-later
6 .\"
7 .TH proc_pid_root 5 2026-02-08 "Linux man-pages 6.18"
8 .SH NAME
9 /proc/pid/root/ \- symbolic link to root directory
10 .SH DESCRIPTION
11 .TP
12 .IR /proc/ pid /root/
13 UNIX and Linux support the idea of a per-process root of the
14 filesystem, set by the
15 .BR chroot (2)
16 system call.
17 This file is a symbolic link that points to the process's
18 root directory, and behaves in the same way as
19 .IR exe ,
20 and
21 .IR fd/* .
22 .IP
23 Note however that this file is not merely a symbolic link.
24 It provides the same view of the filesystem (including namespaces and the
25 set of per-process mounts) as the process itself.
26 An example illustrates this point.
27 In one terminal, we start a shell in new user and mount namespaces,
28 and in that shell we create some new mounts:
29 .IP
30 .in +4n
31 .EX
32 .RB $ " PS1=\[aq]sh1# \[aq] unshare \-Urnm" ;
33 .RB sh1# " mount \-t tmpfs tmpfs /etc" "; # Mount empty tmpfs at /etc"
34 .RB sh1# " mount \-\-bind /usr /dev" "; # Mount /usr at /dev"
35 .RB sh1# " echo $$" ;
36 27123
37 .EE
38 .in
39 .IP
40 In a second terminal window, in the initial mount namespace,
41 we look at the contents of the corresponding mounts in
42 the initial and new namespaces:
43 .IP
44 .in +4n
45 .EX
46 .RB $ " PS1=\[aq]sh2# \[aq] sudo sh" ;
47 .RB sh2# " ls /etc | wc \-l" "; # In initial NS"
48 309
49 .RB sh2# " ls /proc/27123/root/etc | wc \-l" "; # /etc in other NS"
50 0 # The empty tmpfs dir
51 .RB sh2# " ls /dev | wc \-l" "; # In initial NS"
52 205
53 .RB sh2# " ls /proc/27123/root/dev | wc \-l" "; # /dev in other NS"
54 11 # Actually bind
55 # mounted to /usr
56 .RB sh2# " ls /usr | wc \-l" "; # /usr in initial NS"
57 11
58 .EE
59 .in
60 .IP
61 .\" The following was still true as at kernel 2.6.13
62 In a multithreaded process, the contents of the
63 .IR /proc/ pid /root
64 symbolic link are not available if the main thread has already terminated
65 (typically by calling
66 .BR pthread_exit (3)).
67 .IP
68 Permission to dereference or read
69 .RB ( readlink (2))
70 this symbolic link is governed by a ptrace access mode
71 .B PTRACE_MODE_READ_FSCREDS
72 check;
73 see
74 .BR ptrace (2).
75 .SH SEE ALSO
76 .BR proc (5)