Skip to main content

Module process_registry

Module process_registry 

Source
Expand description

Global process registry for tracking and terminating spawned child processes.

This module provides a centralized registry for tracking PIDs of child processes spawned during task execution. When the application receives a termination signal (e.g., Ctrl-C), the registry can terminate all tracked processes and their children.

§Process Groups

On Unix systems, spawned processes are placed in their own process groups using setpgid(0, 0). This allows terminating the entire process tree (including any child processes spawned by the task) by sending signals to the process group.

§Usage

use cuenv_core::tasks::process_registry::global_registry;

// Register a process after spawning
if let Some(pid) = child.id() {
    global_registry().register(pid, "task_name".to_string()).await;
}

// Unregister when process completes
global_registry().unregister(pid).await;

// Terminate all on shutdown
global_registry().terminate_all(Duration::from_secs(5)).await;

Structs§

ProcessRegistry
Registry for tracking spawned child processes.

Functions§

global_registry
Returns the global process registry instance.