Socket
Socket
Sign inDemoInstall

tree-kill

Package Overview
Dependencies
0
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    tree-kill

kill trees of processes


Version published
Weekly downloads
11M
increased by0.38%
Maintainers
2
Install size
8.48 kB
Created
Weekly downloads
 

Package description

What is tree-kill?

The tree-kill npm package is used to kill all processes in the process tree, including the root process. It is particularly useful when you need to clean up all child processes spawned by a parent process, ensuring that no orphan processes remain running.

What are tree-kill's main functionalities?

Kill process trees on different platforms

This code kills the process tree with the PID 12345 on both Windows and Unix systems.

const treeKill = require('tree-kill');
treeKill(12345);

Kill process trees with a specific signal

This code sends the SIGKILL signal to the process tree with the PID 12345, forcing it to terminate immediately.

const treeKill = require('tree-kill');
treeKill(12345, 'SIGKILL');

Kill process trees with a callback

This code attempts to terminate the process tree with the PID 12345 using the SIGTERM signal and provides a callback to handle the result.

const treeKill = require('tree-kill');
treeKill(12345, 'SIGTERM', function(err) {
  if (err) {
    console.error('Error:', err);
  } else {
    console.log('Process tree terminated successfully.');
  }
});

Other packages similar to tree-kill

Readme

Source

Tree Kill

Kill all processes in the process tree, including the root process.

Examples

Kill all the descendent processes of the process with pid 1, including the process with pid 1 itself:

var kill = require('tree-kill');
kill(1);

Send a signal other than SIGTERM.:

var kill = require('tree-kill');
kill(1, 'SIGKILL');

Run a callback when done killing the processes. Passes an error argument if there was an error.

var kill = require('tree-kill');
kill(1, 'SIGKILL', function(err) {
    // Do things
});

You can also install tree-kill globally and use it as a command:

tree-kill 1          # sends SIGTERM to process 1 and its descendents
tree-kill 1 SIGTERM  # same
tree-kill 1 SIGKILL  # sends KILL instead of TERMINATE

Methods

require('tree-kill')(pid, [signal], [callback]);

Sends signal signal to all children processes of the process with pid pid, including pid. Signal defaults to SIGTERM.

For Linux, this uses ps -o pid --no-headers --ppid PID to find the parent pids of PID.

For Darwin/OSX, this uses pgrep -P PID to find the parent pids of PID.

For Windows, this uses 'taskkill /pid PID /T /F' to kill the process tree. Note that on Windows, sending the different kinds of POSIX signals is not possible.

Install

With npm do:

npm install tree-kill

License

MIT

Changelog

[1.2.2] - 2019-12-11

Changed

  • security fix: sanitize pid parameter to fix arbitrary code execution vulnerability

[1.2.1] - 2018-11-05

Changed

  • added missing LICENSE file
  • updated TypeScript definitions

[1.2.0] - 2017-09-19

Added

  • TypeScript definitions

Changed

  • kill(pid, callback) works. Before you had to use kill(pid, signal, callback)

[1.1.0] - 2016-05-13

Added

  • A tree-kill CLI

[1.0.0] - 2015-09-17

Added

  • optional callback
  • Darwin support

Keywords

FAQs

Last updated on 11 Dec 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc