Skip to main content

detect_from_process

Function detect_from_process 

Source
pub fn detect_from_process(process_name: &str) -> Option<StackLabel>
Expand description

Detect a stack label from a process executable name.

Matching is ASCII case-insensitive. A trailing Windows .exe suffix is ignored before matching, so NGINX.EXE and nginx produce the same label.

Two relaxations apply when the exact name is unknown:

  • A trailing version made of digits and dots is ignored for runtime names, so python3.12, php8.2, php-fpm8.2, ruby3.2, and node20 match.
  • Processes that set a title which Linux truncates to 15 characters match on the word before the first space or colon: next-server (v1 is Next.js, puma 6.4.2 (tc and puma: cluster w are Puma, and gunicorn: maste is Gunicorn.

§Examples

use what_stack::detect_from_process;

use what_stack::StackKind;

let python = detect_from_process("python3").expect("known runtime");
assert_eq!(python, "Python");
assert_eq!(python.kind(), StackKind::Runtime);
assert_eq!(detect_from_process("python3.12").expect("versioned runtime"), "Python");
assert_eq!(detect_from_process("next-server (v1").expect("titled"), "Next.js");
assert_eq!(detect_from_process("gunicorn: maste").expect("titled"), "Gunicorn");
assert_eq!(detect_from_process("NGINX.EXE").expect("known server"), "Nginx");
assert_eq!(detect_from_process("node-exporter"), None);

§Limits

This function does not inspect command-line arguments or project files. Use StackDetector when process names should be combined with project config and image metadata.