NAME
Developer::Dashboard::ProcessSupervision - process-supervision helpers shared by the runtime manager and the collector runner
PURPOSE
Hold the one definition of each low-level helper that RuntimeManager and CollectorRunner both need: deciding whether a pid is alive, forking and reaping children, reading a process's namespace and environment, and replacing state files atomically.
WHY IT EXISTS
Both modules supervise processes, and both grew their own copy of the same helpers. The copies did not merely cost duplicated maintenance - they had to receive the same fix independently more than once, across separate pieces of work, until a standing test sweep was added to catch the next recurrence. Worse, the duplication hid a subtler problem: two copies can be identical in code while only one of them has a test, so both files report full coverage and one outcome is never exercised.
WHEN TO USE
Import a helper here when a module needs to ask whether a process is running, start or reap a child, inspect a process through the platform's process interface, or replace a state file without a reader seeing a partial write.
Do NOT move a helper here because two modules happen to have one with the same name. Some same-named helpers differ deliberately between consumers; sharing one of those imposes a single behaviour on both and no existing test will object.
HOW TO USE
use Developer::Dashboard::ProcessSupervision qw(_pid_is_running _reap_child_process);
# call sites are unchanged - these arrive as methods on the importing class
return if !$self->_pid_is_running($pid);
Import only what the module uses. Nothing is exported by default.
WHAT USES IT
Developer::Dashboard::RuntimeManager and Developer::Dashboard::CollectorRunner.
EXAMPLES
Asking whether a supervised child is still alive, where a bare kill 0 would report a zombie as running:
if ( !$self->_pid_is_running($pid) ) {
$self->_restart_collector($name);
}
Replacing a cached state file so a concurrent reader sees the whole old file or the whole new one, never a partial write:
$self->_replace_state_file( $path, $payload );