nodejs / nodejs/node

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

Đang mở
#64,406 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

child_process
Ngôn ngữ chính
JavaScript
Star
122k
Fork
37.3k
Merge trung bình
4 ngày 2 giờ
Pull request đã merge (30 ngày)
283

Mô tả

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với API child_process subprocess.kill và so sánh cách tiếp cận nhóm tiến trình của Unix với Windows taskkill /T /F được mô tả trong issue. Xác định ngữ nghĩa đa nền tảng của killTree, ánh xạ tín hiệu và các giới hạn đã được ghi lại, sau đó kiểm tra hành vi trên Windows, Linux và macOS.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, node.js
Lĩnh vực
api, operating-systems
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
38/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.