summaryrefslogtreecommitdiff
path: root/man
diff options
context:
space:
mode:
authorChris Down <chris@chrisdown.name>2022-08-10 14:07:38 +0100
committerCraig Small <csmall@dropbear.xyz>2022-08-31 07:37:10 +0000
commit4b44ab98c144dae099442e30a62966a7689818c6 (patch)
treed33fe1b77b1f4326993d92bf579b7d3d845bcf80 /man
parentdeeb82411fee9713bd0c7f41bddbf69151947672 (diff)
downloadprocps-ng-4b44ab98c144dae099442e30a62966a7689818c6.tar.gz
pgrep: Add support for ignoring ancestors with -A/--ignore-ancestors
pgrep and friends naturally filter their own processes from their matches. The same issue can occur when elevating with tools like sudo or doas, where the elevating shim layers linger as a parent and are returned in the results. For example: % sudo pkill -9 -cf someelevatedcmdline 1 zsh: killed sudo pkill -9 -cf someelevatedcmdline This is a situation we've actually seen in production, where some poor soul changes how permission management works (for example with Linux's hidepid option), needs to elevate a pgrep or pkill call, and now ends up with more than they bargained for. Even after the issue is noticed, resolving it requires reinventing some of the pgrep logic, which is unfortunate. This commit adds the -A/--ignore-ancestors option which excludes pgrep's ancestors from the results: % sudo ./pkill -9 -Acf someelevatedcmdline 0 We looks at multiple layers of the process hierarchy because, while things like sudo only have one layer of shimming, some mechanisms (like those found in a typical container manager like those found in Docker or Kubernetes) may have many more. Signed-off-by: Chris Down <chris@chrisdown.name>
Diffstat (limited to 'man')
-rw-r--r--man/pgrep.110
1 files changed, 10 insertions, 0 deletions
diff --git a/man/pgrep.1 b/man/pgrep.1
index 5e1db7f..c11af42 100644
--- a/man/pgrep.1
+++ b/man/pgrep.1
@@ -177,6 +177,16 @@ Fail if pidfile (see \fB\-F\fR) not locked.
\fB\-r\fR, \fB\-\-runstates\fR \fID,R,S,Z,\fP...
Match only processes which match the process state.
.TP
+\fB\-A\fR, \fB\-\-ignore-ancestors\fR\fR
+Ignore all ancestors of
+.BR pgrep ,
+.BR pkill ,
+or
+.BR pidwait .
+For example, this can be useful when elevating with
+.BR sudo
+or similar tools.
+.TP
\fB\-\-cgroup \fIname\fP,...
Match on provided control group (cgroup) v2 name. See
.BR cgroups (8)