pgrep: Match on cgroup v2 paths

You can match or filter on cgroup paths. Currently the match is only
done for version 2 cgroups because these are way simpler as they have
a unified name and always start with "0::".

cgroup v1 can have:
 named groups "1:name=myspecialname:"
 controllers "9:blkio:"
 multiple controllers! "4:cpu,cpuacct:"

So they are very much more complicated from a options parsing and
cgroup matching point of view.

In addition, both my Debian bookworm and bullseye systems use
v2 cgroups.

$ ./pgrep --cgroup /system.slice/cron.service
760

Signed-off-by: Craig Small <csmall@dropbear.xyz>
This commit is contained in:
Craig Small
2021-10-26 20:56:19 +11:00
parent 14d6ab27d6
commit 4cfb0fb763
3 changed files with 56 additions and 5 deletions

View File

@@ -7,7 +7,7 @@
.\" the Free Software Foundation; either version 2 of the License, or
.\" (at your option) any later version.
.\"
.TH PGREP "1" "2020-06-04" "procps-ng" "User Commands"
.TH PGREP "1" "2021-10-26" "procps-ng" "User Commands"
.SH NAME
pgrep, pkill, pidwait \- look up, signal, or wait for processes based on name and other attributes
.SH SYNOPSIS
@@ -177,6 +177,10 @@ 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\-\-cgroup \fIname\fP,...
Match on provided control group (cgroup) v2 name. See
.BR cgroups (8)
.TP
\fB\-\-ns \fIpid\fP
Match processes that belong to the same namespaces. Required to run as
root to match processes from other users. See \fB\-\-nslist\fR for how to
@@ -282,7 +286,8 @@ Defunct processes are reported.
.BR killall (1),
.BR skill (1),
.BR kill (1),
.BR kill (2)
.BR kill (2),
.BR cgroups (8)
.SH AUTHOR
.UR kjetilho@ifi.uio.no
Kjetil Torgrim Homme