nodejs / nodejs/node

child_process: add cross-platform subprocess.killTree([signal])

オープン
#64,406 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

child_process
主要言語
JavaScript
スター
122k
フォーク
37.3k
平均マージ
4日 2時間
マージ済み PR(30日)
283

説明

What is the problem this feature will solve?

subprocess.kill([signal]) only targets the direct child PID. Descendants often keep running, especially when:

  • shell: true (shell exits, real command survives)
  • the child is a build driver (bash / make / ninja) that spawns grandchildren
  • on Windows, where POSIX signals are not real and kill() does not terminate a process tree

Userland workarounds are fragmented and OS-specific:

  • Unix: detached: true + process.kill(-pid, signal) (process group; not always applicable)
  • Windows: taskkill /pid <pid> /T /F (or equivalent)
  • npm packages such as tree-kill

This comes up often for Ctrl+C / timeout cleanup in CLIs and build orchestrators.

Related prior request (closed stale): https://github.com/nodejs/node/issues/40438 (killDeep).

What is the feature you are proposing to solve the problem?

Add an explicit, documented API, for example:

subprocess.killTree([signal]);
// and/or
child_process.killTree(pid[, signal]);

Goals:

  1. Cross-platform: one call that best-effort terminates the process and its descendants on Windows, Linux, and macOS.
  2. Clear semantics vs kill(): kill() stays single-PID; killTree() is the tree variant.
  3. Document limitations: PID reuse races, process-group vs true tree walk, signal mapping on Windows (where signals are not POSIX).

A reasonable Windows implementation can use the platform tree-terminate facility (today: taskkill /T); Unix can use process-group kill when the child is a group leader, otherwise a documented tree walk.

What alternatives have you considered?
  • Keep using tree-kill / ad-hoc taskkill in every project
  • Rely on detached + negative PID (Unix-only, requires spawn options up front)
  • Expand subprocess.kill() to kill trees (breaking / surprising; prefer a separate killTree name)

Naming killTree (rather than overloading kill) makes the stronger, OS-dependent behavior opt-in and discoverable.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

child_process subprocess.kill API から始め、issue で説明されている Unix のプロセスグループアプローチと Windows taskkill /T /F を比較します。クロスプラットフォームでの killTree のセマンティクス、シグナルのマッピング、文書化されている制限事項を定義し、その後 Windows、Linux、macOS での動作を検証します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, node.js
領域
api, operating-systems
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
活発
明瞭さ
説明が足りない
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。