Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+11 added−1 removed
other:+11 added−1 removed
Provenance
Commit
f8d4e08
Tree
914b6fa
Author
ehmicky <ehmicky@users.noreply.github.com>
Committer
GitHub <noreply@github.com>
Parent
ea889c7
1 file changed+11 added−1 removed
modified:docs/termination.md+11 added-1 removed
142 unmodified lines
Expand all
143
144
145
146
147
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
23 unmodified lines
142 unmodified lines
Expand all
```
## Inter-process termination
[`subprocess.kill()`](api.md#subprocesskillsignal-error) only works when the current process terminates the subprocess. To terminate the subprocess from a different process (for example, a terminal), its [`subprocess.pid`](api.md#subprocesspid) can be used instead.
[`subprocess.kill()`](api.md#subprocesskillsignal-error) only works when the current process terminates the subprocess. To terminate the subprocess from a different process, its [`subprocess.pid`](api.md#subprocesspid) can be used instead.
```js
const subprocess = execa`npm run build`;
console.log('PID:', subprocess.pid); // PID: 6513
await subprocess;
```
For example, from a terminal:
```sh
$ kill -SIGTERM 6513
```
Or from a different Node.js process:
```js
import process from 'node:process';
process.kill(subprocessPid);
```
## Error message and stack trace
When terminating a subprocess, it is possible to include an error message and stack trace by using [`subprocess.kill(error)`](api.md#subprocesskillerror). The `error` argument will be available at [`error.cause`](api.md#errorcause).