@@ -44,6 +44,7 @@ pub struct Settings {
4444 pub gid : Option < HashSet < u32 > > ,
4545 pub pgroup : Option < HashSet < u64 > > ,
4646 pub session : Option < HashSet < u64 > > ,
47+ pub cgroup : Option < HashSet < String > > ,
4748 pub threads : bool ,
4849}
4950
@@ -101,6 +102,9 @@ pub fn get_match_settings(matches: &ArgMatches) -> UResult<Settings> {
101102 } )
102103 . collect ( )
103104 } ) ,
105+ cgroup : matches
106+ . get_many :: < String > ( "cgroup" )
107+ . map ( |groups| groups. cloned ( ) . collect ( ) ) ,
104108 threads : false ,
105109 } ;
106110
@@ -115,6 +119,7 @@ pub fn get_match_settings(matches: &ArgMatches) -> UResult<Settings> {
115119 && settings. gid . is_none ( )
116120 && settings. pgroup . is_none ( )
117121 && settings. session . is_none ( )
122+ && settings. cgroup . is_none ( )
118123 && !settings. require_handler
119124 && pattern. is_empty ( )
120125 {
@@ -235,6 +240,10 @@ fn collect_matched_pids(settings: &Settings) -> Vec<ProcessInformation> {
235240 let parent_matched = any_matches ( & settings. parent , pid. ppid ( ) . unwrap ( ) ) ;
236241 let pgroup_matched = any_matches ( & settings. pgroup , pid. pgid ( ) . unwrap ( ) ) ;
237242 let session_matched = any_matches ( & settings. session , pid. sid ( ) . unwrap ( ) ) ;
243+ let cgroup_matched = any_matches (
244+ & settings. cgroup ,
245+ pid. cgroup_v2_path ( ) . unwrap_or ( "/" . to_string ( ) ) ,
246+ ) ;
238247
239248 let ids_matched = any_matches ( & settings. uid , pid. uid ( ) . unwrap ( ) )
240249 && any_matches ( & settings. euid , pid. euid ( ) . unwrap ( ) )
@@ -265,6 +274,7 @@ fn collect_matched_pids(settings: &Settings) -> Vec<ProcessInformation> {
265274 && parent_matched
266275 && pgroup_matched
267276 && session_matched
277+ && cgroup_matched
268278 && ids_matched
269279 && handler_matched)
270280 ^ settings. inverse
@@ -413,8 +423,7 @@ pub fn clap_args(pattern_help: &'static str, enable_v_flag: bool) -> Vec<Arg> {
413423 // arg!(-L --logpidfile "fail if PID file is not locked"),
414424 arg!( -r --runstates <state> "match runstates [D,S,Z,...]" ) ,
415425 // arg!(-A --"ignore-ancestors" "exclude our ancestors from results"),
416- // arg!(--cgroup <grp> "match by cgroup v2 names")
417- // .value_delimiter(','),
426+ arg!( --cgroup <grp> "match by cgroup v2 names" ) . value_delimiter( ',' ) ,
418427 // arg!(--ns <PID> "match the processes that belong to the same namespace as <pid>"),
419428 // arg!(--nslist <ns> "list which namespaces will be considered for the --ns option.")
420429 // .value_delimiter(',')
0 commit comments