2 .\" This file and its contents are supplied under the terms of the
3 .\" Common Development and Distribution License ("CDDL"), version 1.0.
4 .\" You may only use this file in accordance with the terms of version
7 .\" A full copy of the text of the CDDL should have accompanied this
8 .\" source. A copy of the CDDL is also available via the Internet at
9 .\" http://www.illumos.org/license/CDDL.
12 .\" Copyright 2015 Joyent, Inc.
19 .Nd grab and control a process
23 .Ft "struct ps_prochandle *"
32 function attempts to grab the process identified by
34 and returns a handle to it that allows the process to be controlled,
35 interrogated, and manipulated.
36 This interface only works with processes that already exist.
43 A grabbed process undergoes the following changes unless
45 is set to the contrary:
46 .Bl -bullet -offset indent
48 The process is stopped
50 All other tracing flags are cleared
52 The grab is exclusive.
53 If any existing handles to this process exist or anyone else is using the
54 underlying facilities of the /proc file system to control this process,
57 Unless the process is already stopped, the
59 flag is set indicating the process should run-on-last-close.
60 Allowing the process to resume running if its controlling process dies.
63 Grabbing a process is a
66 Stopping a process stops execution of all its threads.
67 The impact of stopping a process depends on the purpose of that process.
68 For example, if one stops a process that's primarily doing
69 computation, then its computation is delayed the entire time that it
71 However, if instead this is an active TCP server, then the accept backlog may
72 fill causing connection errors and potentially connection time out errors.
74 Special care must be taken to ensure that a stopped process continues,
75 even if the controlling process terminates.
76 If the controlling process disables the
78 flag or the process was already stopped, then the process remains
79 stopped after the controlling process terminates.
80 Exercise caution when changing this behavior.
82 Many of these default behaviors can be controlled by passing values to
88 are constructed by a bitwise-inclusive-OR of flags from the following
90 .Bl -tag -width Dv -offset indent
92 Indicates that any existing tracing flags on
95 If this flag is not specified, they will be cleared as part of creating the
97 handle for this process.
99 Normally extant tracing flags are cleared when a process is grabbed.
101 Indicates that the process should not be grabbed exclusively.
102 Care should be taken with this option.
103 If other consumers are manipulating the process, then this may result in
104 surprising behavior as the process is being manipulated from multiple points of
105 control at the same time.
107 Normally an attempt will be made to grab the process exclusively and
108 fail if it is already in use.
110 Indicates that the process should be grabbed in a read-only fashion.
111 This implies that both the
116 If a process is opened read-only, then a caller can only read information about
117 a process and cannot manipulate it, change its current state, or inject systems
120 Normally when a process is grabbed, it does so for both reading and writing.
122 Do not stop a process as it is grabbed.
123 Note, any extant tracing flags on the process will still be cleared unless the
127 Normally a process is stopped as a result of grabbing the process.
134 pointer which will store a more detailed error in the event that the
137 A human-readable form of the error can be obtained with
138 .Xr Pgrab_error 3PROC .
140 Once a caller is done with the library handle it should call
142 to release the grabbed process.
143 Failure to properly release the handle may leave a process stopped and interfere
144 with the ability of other software to obtain a handle.
146 Unprivileged users may grab and control their own processes only if both
147 the user and group IDs of the target process match those of the calling
149 In addition, the caller must have a super set of the target's privileges.
152 privilege may manipulate any process on the system, as long as it has an
154 For more details on the security and programming considerations, please see the
156 .Sy PROGRAMMING NOTES
160 Upon successful completion, the
162 function returns a control handle to the process.
167 containing the error code.
171 function will fail if:
176 is already being traced and the
178 flag was not passed in
181 The calling process is a 32-bit process and process
185 Too many files are open.
186 This is logically equivalent to receiving
189 The process referred to by
193 The calling process has insufficient permissions or privileges to open
194 the specified process.
197 for more information.
199 The process referred to by
201 is a system process and cannot be grabbed.
203 The process referred to by
205 is the process ID of the caller and the
208 A process may only grab itself if it's read-only.
210 An unanticipated system error occurred while trying to grab the process
211 file and create the handle.
214 indicates the system failure.
216 The process referred to by
218 is a zombie and cannot be grabbed.
220 .Sh INTERFACE STABILITY
228 .Xr Pgrab_core 3PROC ,
229 .Xr Pgrab_error 3PROC ,
230 .Xr Pgrab_file 3PROC ,