This function counts the number of active system processes (threads) that match a given pattern and exceed a specified minimum CPU usage threshold. It works on Unix-like systems (e.g., Linux, macOS) and does not support Windows.

detectActiveCores(pattern = "", minCPU = 50)

Arguments

pattern

A character string used to filter process lines. Only processes whose command line matches this pattern will be considered. Default is "" (matches all).

minCPU

A numeric value specifying the minimum CPU usage (in percent) for a process to be considered active. Default is 50.

Value

An integer representing the number of active threads matching the pattern and exceeding the CPU usage threshold. Returns NULL with a message if run on Windows.

Note

This function uses the ps -ef system command and regular expressions to parse CPU usage. It may not be portable across all Unix variants.

Examples

if (FALSE) { # \dontrun{
  detectActiveCores(pattern = "R", minCPU = 30)
} # }