Skip to content

Commit 69780bd

Browse files
swissspidyclaude
andcommitted
Keep killing captured jobs after the driver exits
peek_kill_tree() returned as soon as the xargs driver was gone, so a job that ignored the signal kept running after the display exited. It now waits on every PID it captured before signalling, and sends SIGKILL to those still alive after two seconds. The list is not rebuilt from ps, as jobs that outlive the driver are reparented. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWTd5n8EwiVkC4y4eEWszr
1 parent 2a4f6b5 commit 69780bd

1 file changed

Lines changed: 28 additions & 8 deletions

File tree

‎.maintenance/peek.php‎

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -525,24 +525,44 @@ function peek_kill_tree( $proc, $signo ) {
525525
$queue = array_merge( $queue, $children[ $pid ] );
526526
}
527527
}
528-
$send = function ( $sig ) use ( $pids ) {
528+
$send = function ( $sig, array $targets ) {
529529
if ( function_exists( 'posix_kill' ) ) {
530-
foreach ( $pids as $pid ) {
530+
foreach ( $targets as $pid ) {
531531
@posix_kill( $pid, $sig );
532532
}
533-
} else {
534-
@exec( 'kill -' . (int) $sig . ' ' . implode( ' ', $pids ) . ' 2>/dev/null' );
533+
} elseif ( $targets ) {
534+
@exec( 'kill -' . (int) $sig . ' ' . implode( ' ', $targets ) . ' 2>/dev/null' );
535535
}
536536
};
537-
$send( $signo );
537+
// Check the PIDs captured above rather than asking ps again: a job that
538+
// outlives the driver is reparented and would no longer show up below it.
539+
$driver = $pids[0];
540+
$alive = function () use ( $proc, $pids, $driver ) {
541+
$left = array();
542+
foreach ( $pids as $pid ) {
543+
if ( $pid === $driver ) {
544+
$status = proc_get_status( $proc );
545+
$running = $status['running'];
546+
} elseif ( function_exists( 'posix_kill' ) ) {
547+
$running = @posix_kill( $pid, 0 );
548+
} else {
549+
@exec( 'kill -0 ' . $pid . ' 2>/dev/null', $out, $rc );
550+
$running = 0 === $rc;
551+
}
552+
if ( $running ) {
553+
$left[] = $pid;
554+
}
555+
}
556+
return $left;
557+
};
558+
$send( $signo, $pids );
538559
for ( $i = 0; $i < 20; $i++ ) {
539-
$status = proc_get_status( $proc );
540-
if ( ! $status['running'] ) {
560+
if ( ! $alive() ) {
541561
return;
542562
}
543563
usleep( 100000 );
544564
}
545-
$send( 9 );
565+
$send( 9, $alive() );
546566
}
547567

548568
function peek_cmd_serve( array $argv ) {

0 commit comments

Comments
 (0)