processexists

Table of Contents

Prototype: processexists(regex)

Return type: boolean

The return value is cached.

Description: Return whether a process matches the given anchored regular expression regex.

This function searches for the given regular expression in the process table. Use .*sherlock.* to find all the processes that match sherlock. Use .*\bsherlock\b.* to exclude partial matches like sherlock123 (\b matches a word boundary).

Arguments:

  • regex: regular expression - Regular expression to match process name - in the range: .*

The process table is usually obtained with something like ps -eo user,pid,ppid,pgid,%cpu,%mem,vsize,ni,rss,stat,nlwp,stime,time,args, and the CMD or COMMAND field (args) is used to match against. However the exact data used may change per platform and per CFEngine release.

Example:

    classes:
      # the class "holmes" will be set if a process line contains the word "sherlock"
      "holmes" expression => processexists(".*sherlock.*");

History: Introduced in CFEngine 3.9

See also: processes findprocesses().