[6a3a178] | 1 | Tree Kill
|
---|
| 2 | =========
|
---|
| 3 |
|
---|
| 4 | Kill all processes in the process tree, including the root process.
|
---|
| 5 |
|
---|
| 6 | Examples
|
---|
| 7 | =======
|
---|
| 8 |
|
---|
| 9 | Kill all the descendent processes of the process with pid `1`, including the process with pid `1` itself:
|
---|
| 10 | ```js
|
---|
| 11 | var kill = require('tree-kill');
|
---|
| 12 | kill(1);
|
---|
| 13 | ```
|
---|
| 14 |
|
---|
| 15 | Send a signal other than SIGTERM.:
|
---|
| 16 | ```js
|
---|
| 17 | var kill = require('tree-kill');
|
---|
| 18 | kill(1, 'SIGKILL');
|
---|
| 19 | ```
|
---|
| 20 |
|
---|
| 21 | Run a callback when done killing the processes. Passes an error argument if there was an error.
|
---|
| 22 | ```js
|
---|
| 23 | var kill = require('tree-kill');
|
---|
| 24 | kill(1, 'SIGKILL', function(err) {
|
---|
| 25 | // Do things
|
---|
| 26 | });
|
---|
| 27 | ```
|
---|
| 28 |
|
---|
| 29 | You can also install tree-kill globally and use it as a command:
|
---|
| 30 | ```sh
|
---|
| 31 | tree-kill 1 # sends SIGTERM to process 1 and its descendents
|
---|
| 32 | tree-kill 1 SIGTERM # same
|
---|
| 33 | tree-kill 1 SIGKILL # sends KILL instead of TERMINATE
|
---|
| 34 | ```
|
---|
| 35 |
|
---|
| 36 | Methods
|
---|
| 37 | =======
|
---|
| 38 |
|
---|
| 39 | ## require('tree-kill')(pid, [signal], [callback]);
|
---|
| 40 |
|
---|
| 41 | Sends signal `signal` to all children processes of the process with pid `pid`, including `pid`. Signal defaults to `SIGTERM`.
|
---|
| 42 |
|
---|
| 43 | For Linux, this uses `ps -o pid --no-headers --ppid PID` to find the parent pids of `PID`.
|
---|
| 44 |
|
---|
| 45 | For Darwin/OSX, this uses `pgrep -P PID` to find the parent pids of `PID`.
|
---|
| 46 |
|
---|
| 47 | 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.
|
---|
| 48 |
|
---|
| 49 | Install
|
---|
| 50 | =======
|
---|
| 51 |
|
---|
| 52 | With [npm](https://npmjs.org) do:
|
---|
| 53 |
|
---|
| 54 | ```
|
---|
| 55 | npm install tree-kill
|
---|
| 56 | ```
|
---|
| 57 |
|
---|
| 58 | License
|
---|
| 59 | =======
|
---|
| 60 |
|
---|
| 61 | MIT
|
---|
| 62 |
|
---|
| 63 | Changelog
|
---|
| 64 | =========
|
---|
| 65 |
|
---|
| 66 |
|
---|
| 67 | ## [1.2.2] - 2019-12-11
|
---|
| 68 | ### Changed
|
---|
| 69 | - security fix: sanitize `pid` parameter to fix arbitrary code execution vulnerability
|
---|
| 70 |
|
---|
| 71 | ## [1.2.1] - 2018-11-05
|
---|
| 72 | ### Changed
|
---|
| 73 | - added missing LICENSE file
|
---|
| 74 | - updated TypeScript definitions
|
---|
| 75 |
|
---|
| 76 | ## [1.2.0] - 2017-09-19
|
---|
| 77 | ### Added
|
---|
| 78 | - TypeScript definitions
|
---|
| 79 | ### Changed
|
---|
| 80 | - `kill(pid, callback)` works. Before you had to use `kill(pid, signal, callback)`
|
---|
| 81 |
|
---|
| 82 | ## [1.1.0] - 2016-05-13
|
---|
| 83 | ### Added
|
---|
| 84 | - A `tree-kill` CLI
|
---|
| 85 |
|
---|
| 86 | ## [1.0.0] - 2015-09-17
|
---|
| 87 | ### Added
|
---|
| 88 | - optional callback
|
---|
| 89 | - Darwin support
|
---|