1PRCTL(2) Linux Programmer's Manual PRCTL(2)
2
3
4
6 prctl - operations on a process or thread
7
9 #include <sys/prctl.h>
10
11 int prctl(int option, unsigned long arg2, unsigned long arg3,
12 unsigned long arg4, unsigned long arg5);
13
15 prctl() manipulates various aspects of the behavior of the calling
16 thread or process.
17
18 Note that careless use of some prctl() operations can confuse the user-
19 space run-time environment, so these operations should be used with
20 care.
21
22 prctl() is called with a first argument describing what to do (with
23 values defined in <linux/prctl.h>), and further arguments with a sig‐
24 nificance depending on the first one. The first argument can be:
25
26 PR_CAP_AMBIENT (since Linux 4.3)
27 Reads or changes the ambient capability set of the calling
28 thread, according to the value of arg2, which must be one of the
29 following:
30
31 PR_CAP_AMBIENT_RAISE
32 The capability specified in arg3 is added to the ambient
33 set. The specified capability must already be present in
34 both the permitted and the inheritable sets of the
35 process. This operation is not permitted if the
36 SECBIT_NO_CAP_AMBIENT_RAISE securebit is set.
37
38 PR_CAP_AMBIENT_LOWER
39 The capability specified in arg3 is removed from the am‐
40 bient set.
41
42 PR_CAP_AMBIENT_IS_SET
43 The prctl() call returns 1 if the capability in arg3 is
44 in the ambient set and 0 if it is not.
45
46 PR_CAP_AMBIENT_CLEAR_ALL
47 All capabilities will be removed from the ambient set.
48 This operation requires setting arg3 to zero.
49
50 In all of the above operations, arg4 and arg5 must be specified
51 as 0.
52
53 Higher-level interfaces layered on top of the above operations
54 are provided in the libcap(3) library in the form of cap_get_am‐
55 bient(3), cap_set_ambient(3), and cap_reset_ambient(3).
56
57 PR_CAPBSET_READ (since Linux 2.6.25)
58 Return (as the function result) 1 if the capability specified in
59 arg2 is in the calling thread's capability bounding set, or 0 if
60 it is not. (The capability constants are defined in <linux/ca‐
61 pability.h>.) The capability bounding set dictates whether the
62 process can receive the capability through a file's permitted
63 capability set on a subsequent call to execve(2).
64
65 If the capability specified in arg2 is not valid, then the call
66 fails with the error EINVAL.
67
68 A higher-level interface layered on top of this operation is
69 provided in the libcap(3) library in the form of
70 cap_get_bound(3).
71
72 PR_CAPBSET_DROP (since Linux 2.6.25)
73 If the calling thread has the CAP_SETPCAP capability within its
74 user namespace, then drop the capability specified by arg2 from
75 the calling thread's capability bounding set. Any children of
76 the calling thread will inherit the newly reduced bounding set.
77
78 The call fails with the error: EPERM if the calling thread does
79 not have the CAP_SETPCAP; EINVAL if arg2 does not represent a
80 valid capability; or EINVAL if file capabilities are not enabled
81 in the kernel, in which case bounding sets are not supported.
82
83 A higher-level interface layered on top of this operation is
84 provided in the libcap(3) library in the form of
85 cap_drop_bound(3).
86
87 PR_SET_CHILD_SUBREAPER (since Linux 3.4)
88 If arg2 is nonzero, set the "child subreaper" attribute of the
89 calling process; if arg2 is zero, unset the attribute.
90
91 A subreaper fulfills the role of init(1) for its descendant pro‐
92 cesses. When a process becomes orphaned (i.e., its immediate
93 parent terminates), then that process will be reparented to the
94 nearest still living ancestor subreaper. Subsequently, calls to
95 getppid(2) in the orphaned process will now return the PID of
96 the subreaper process, and when the orphan terminates, it is the
97 subreaper process that will receive a SIGCHLD signal and will be
98 able to wait(2) on the process to discover its termination sta‐
99 tus.
100
101 The setting of the "child subreaper" attribute is not inherited
102 by children created by fork(2) and clone(2). The setting is
103 preserved across execve(2).
104
105 Establishing a subreaper process is useful in session management
106 frameworks where a hierarchical group of processes is managed by
107 a subreaper process that needs to be informed when one of the
108 processes—for example, a double-forked daemon—terminates (per‐
109 haps so that it can restart that process). Some init(1) frame‐
110 works (e.g., systemd(1)) employ a subreaper process for similar
111 reasons.
112
113 PR_GET_CHILD_SUBREAPER (since Linux 3.4)
114 Return the "child subreaper" setting of the caller, in the loca‐
115 tion pointed to by (int *) arg2.
116
117 PR_SET_DUMPABLE (since Linux 2.3.20)
118 Set the state of the "dumpable" attribute, which determines
119 whether core du