pgrep.1 (6072B)
1 .\" 2 .\" Copyright (c) 2003 Gunnar Ritter 3 .\" 4 .\" This software is provided 'as-is', without any express or implied 5 .\" warranty. In no event will the authors be held liable for any damages 6 .\" arising from the use of this software. 7 .\" 8 .\" Permission is granted to anyone to use this software for any purpose, 9 .\" including commercial applications, and to alter it and redistribute 10 .\" it freely, subject to the following restrictions: 11 .\" 12 .\" 1. The origin of this software must not be misrepresented; you must not 13 .\" claim that you wrote the original software. If you use this software 14 .\" in a product, an acknowledgment in the product documentation would be 15 .\" appreciated but is not required. 16 .\" 17 .\" 2. Altered source versions must be plainly marked as such, and must not be 18 .\" misrepresented as being the original software. 19 .\" 20 .\" 3. This notice may not be removed or altered from any source distribution. 21 .\" 22 .\" Sccsid @(#)pgrep.1 1.9 (gritter) 8/14/05 23 .TH PGREP 1 "8/14/05" "Heirloom Toolchest" "User Commands" 24 .SH NAME 25 pgrep, pkill \- find or signal processes by name and other attributes 26 .SH SYNOPSIS 27 .HP 28 .ad l 29 \fBpgrep\fR [\fB\-flnovx\fR] [\fB-d\ \fIdelim\fR] 30 [\fB\-P\ \fIppidlist\fR] [\fB\-g\ \fIpgrplist\fR] [\fB\-s\ \fIsidlist\fR] 31 [\fB\-u\ \fIeuidlist\fR] [\fB\-U\ \fIuidlist\fR] 32 [\fB-G\ \fIgidlist\fR] [\fB\-t\ \fItermlist\fR] [\fIpattern\fR] 33 .HP 34 .ad l 35 \fBpkill\fR [\fB-\fIsignal\fR] [\fB\-fnovx\fR] 36 [\fB\-P\ \fIppidlist\fR] [\fB\-g\ \fIpgrplist\fR] [\fB\-s\ \fIsidlist\fR] 37 [\fB\-u\ \fIeuidlist\fR] [\fB\-U\ \fIuidlist\fR] 38 [\fB-G\ \fIgidlist\fR] [\fB\-t\ \fItermlist\fR] [\fIpattern\fR] 39 .br 40 .ad b 41 .SH DESCRIPTION 42 .I Pgrep 43 searches the currently active processes 44 for occurences of the specified 45 .I pattern 46 and prints the process IDs of the matching ones. 47 .I Pattern 48 is treated as an extended regular expression 49 as described in 50 .IR egrep (1). 51 A number of options can be used in addition to the 52 .I pattern 53 (or without specifying 54 .IR pattern ) 55 to further restrict the set of matching processes. 56 Multiple criteria can be specified for each of these options, 57 separated by commas or blanks, 58 or by giving the option more than once. 59 In this case, 60 all processes that match any of the given criteria 61 are considered matches. 62 If more than one kind of criterion is specified, 63 a process must match each kind of criterion. 64 .PP 65 .I Pkill 66 is similar to 67 .IR pgrep , 68 but a signal (SIGTERM by default) 69 is sent to matching processes 70 instead of printing its process ID. 71 The signal can be changed with the 72 \fB\-\fIsignal\fR 73 argument; 74 this argument must appear before all options 75 to be recognized. 76 .I Signal 77 can be either numeric 78 or symbolic with the SIG prefix omitted 79 (as in QUIT for SIGQUIT). 80 .PP 81 Zombie processes and the current 82 .I pgrep 83 or 84 .I pkill 85 process are never included. 86 .PP 87 Both commands accept the following options: 88 .TP 12 89 \fB\-d \fIdelim\fR 90 Use the specified 91 .I delimiter 92 string to separate process IDs in output. 93 By default, a newline character is used. 94 This option is accepted by 95 .I pgrep 96 only. 97 .TP 12 98 .B \-f 99 Use the command line arguments of each process 100 instead of the name of its executable file 101 for matching, 102 and, if 103 .B \-l 104 is also specified, 105 for printing. 106 .TP 12 107 \fB\-g\fI pgrplist\fR 108 Restrict matches to processes 109 whose process group ID 110 appears in 111 .IR pgrplist . 112 If an ID is `0', 113 the process group ID of the current process is used. 114 .TP 12 115 \fB\-G\fI gidlist\fR 116 Restrict matches to processes 117 whose real group ID 118 appears in 119 .IR gidlist . 120 .TP 12 121 .B \-l 122 Print the command name in addition to the process ID. 123 This option is accepted by 124 .I pgrep 125 only. 126 .TP 12 127 .B \-n 128 Select only the newest (most recently created) process 129 of all processes that matched the other criteria. 130 Cannot be combined with 131 .IR \-o . 132 .TP 12 133 .B \-o 134 Select only the oldest (least recently created) process 135 of all processes that matched the other criteria. 136 Cannot be combined with 137 .IR \-n . 138 .TP 12 139 \fB\-P\fI ppidlist\fR 140 Restrict matches to processes 141 whose parent ID appears in 142 .IR ppidlist . 143 .TP 12 144 \fB\-s\fI sidlist\fR 145 Restrict matches to processes 146 that are members of a session given in 147 .IR sidlist . 148 If an ID is `0', 149 the session ID of the current process is used. 150 .TP 12 151 \fB\-t\fI termlist\fR 152 Restrict matches to processes 153 that run on any controlling terminal given in 154 .IR termlist . 155 Terminal specifications have the format described in 156 .IR ps (1). 157 .TP 12 158 \fB\-u\fI uidlist\fR 159 Restrict matches to processes 160 whose effective user ID 161 appears in 162 .IR uidlist . 163 .TP 12 164 \fB\-U\fI uidlist\fR 165 Restrict matches to processes 166 whose real user ID 167 appears in 168 .IR uidlist . 169 .TP 12 170 .B \-v 171 Reverse the match, 172 that is, 173 select all processes that fail to fulfill the given criteria. 174 .TP 12 175 .B \-x 176 Require the entire process name to be matched, 177 as if 178 .I pattern 179 was surrounded by `^( )$'. 180 .SH EXAMPLES 181 .PP 182 Determine the process ID of the 183 .I inetd 184 process: 185 .RS 186 .sp 187 pgrep \-x inetd 188 .sp 189 .RE 190 Print all processes that have a first argument starting with 191 .I /bin/ 192 along with their arguments: 193 .RS 194 .sp 195 pgrep \-l \-f \'^/bin/\' 196 .sp 197 .RE 198 Send a SIGHUP signal to all processes that are owned by either the 199 .I root 200 or the 201 .I daemon 202 user and are children of the 203 .I init 204 process 205 (process ID 1): 206 .RS 207 .sp 208 pkill \-HUP \-u root,daemon \-P 1 209 .sp 210 .RE 211 .SH "ENVIRONMENT VARIABLES" 212 .TP 213 .BR LANG ", " LC_ALL 214 See 215 .IR locale (7). 216 .TP 217 .B LC_COLLATE 218 Affects the collation order for range expressions, 219 equivalence classes, and collation symbols 220 in extended regular expressions. 221 .TP 222 .B LC_CTYPE 223 Determines the mapping of bytes to characters and 224 the availability and composition of character classes 225 in extended regular expressions. 226 .SH "SEE ALSO" 227 egrep(1), 228 ps(1), 229 locale(7) 230 .SH DIAGNOSTICS 231 .I Pgrep 232 and 233 .I Pkill 234 exit with 235 .TP 236 0 237 if matching processes were found, 238 and the \fI\-v\fR option was not specified; 239 .br 240 .ns 241 .TP 242 1 243 if no matching processes were found, 244 or the \fI\-v\fR option was specified without any matches; 245 .br 246 .ns 247 .TP 248 2 249 if an invalid command line argument was found; 250 .br 251 .ns 252 .TP 253 3 254 on fatal errors. 255 .SH NOTES 256 Command names are limited to 18 characters, 257 process arguments to 80 characters; 258 excess characters are stripped.