process.killAndWait¶
process.killAndWait sends a signal to a child process and waits for the process to end. If the process does not end in time, the daemon can end it by force.
An untagged rule on this page matches build 5fd08069 or an earlier build.
Request¶
| Parameter | Required | Meaning |
|---|---|---|
id |
yes | The id of the process, as given to process.spawn. An unknown id of up to 128 bytes is given up. |
signal |
no | The first signal, named as for process.kill. On Windows the daemon ignores the name: see Differences by system. |
timeoutMs |
no | How long the daemon waits for the process to end after the signal, in milliseconds. The default is 3000. A value of 0 or below means the default. The daemon limits a larger value to 30000. |
escalate |
no | What the daemon does at the end of that time. With true, the default, it ends the process by force. With false, it leaves the process alone. |
farewell, graceMs |
no | See Farewell, also for the farewellEnd member of the result. |
The first signal reaches the same processes as a signal of process.kill, except a request with a valid farewell in the exit drain.
Response¶
| Member | Meaning |
|---|---|
found |
If the daemon has a process with this id, true. |
died |
If the process ended and the daemon sent its exit frame, true. |
alreadyExited |
true if the exit frame went out before the request. The daemon then sent no signal. Otherwise absent. |
escalated |
true if the wait ran out and the daemon used the force. Otherwise absent. |
Results:
| Result | What happened |
|---|---|
{"found": false, "died": false} |
The daemon has no such process. This is not an error. |
{"found": true, "died": true, "alreadyExited": true} |
The exit frame of the process went out before the request. |
{"found": true, "died": true} |
The process ended after the first signal, inside the wait. |
{"found": true, "died": true, "escalated": true} |
The process, or its output, did not end in time, and the daemon used the force. |
{"found": true, "died": false, "escalated": true} |
The daemon used the force, and the process, or its output, still did not end in the 7 seconds after that. |
{"found": true, "died": false} |
Only with "escalate": false: the wait ran out. The process still runs, or it ended and its output is not complete. |
The response comes at the end of the process and its output, or at the end of the wait, whichever is first. With the defaults that is up to 3 seconds, and up to 7 seconds more after the use of force.
Errors¶
This method has no errorCode member. A failure is a JSON-RPC error.
| Code | Text | Cause |
|---|---|---|
-32602 |
Invalid params |
The request has no params member, or params or a member that it reads has the wrong type. See the rules for params. |
-32602 |
Process ID is required |
id is absent or empty. |
Which processes the force reaches¶
On Linux and macOS, the force is a SIGKILL to the process group of the child. So the processes that the child started end too, unless one left the group.
If the child ends inside the wait and its output is complete, the daemon sends no SIGKILL. A process that the child started then stays. Use "signal": "KILL" to end the whole group at once.
The output of a child is not complete while another process holds the output pipe open, in its group or not. The daemon waits at most 5 seconds for that output after the child ended. If the wait of the request ends first, the daemon uses the force although the child itself ended. If those 5 seconds end first, the answer is {"found": true, "died": true}, and the daemon sends no SIGKILL.
Differences by system¶
On Windows the daemon ignores the signal name. A kill ends the job of the child at once, with exit code 1 (52d82f0a). With no job it ends the direct child only (89cb6289). See Windows child trees.
Rare states¶
A request during the exit drain¶
For a short time after a child ends, the daemon still collects its last output and did not yet send the exit frame. A request then does not answer alreadyExited, and the daemon sends no first signal.
- On Linux and macOS,
"signal": "KILL"sendsSIGKILLto the group at once instead. Windows makes that call too, and it ends nothing (not measured). - If the
exitframe comes inside the wait, the answer is{"found": true, "died": true}. If the wait ends first, the request goes on as for a child whose output is not complete.
These answers and the group kill are measured on Linux and macOS, not on Windows. For TERM b3081b51 sends no first signal to the ended child either (measured on Linux). On macOS and for INT and HUP that is claustrum's own, not measured.
For a signal other than KILL, that missing first signal is a guard: the operating system can reuse the process id (pid) of an ended child. For KILL claustrum follows the reference and accepts the risk of a reused group number.
A refused signal¶
On Linux and macOS a refused signal, as to a child that runs as root, gives no error. The answer has "died": false, and the log names a refused first signal and a refused group kill (52d82f0a, measured). Only TERM was measured as the first signal.
Differences from the reference¶
No entry of the divergence catalog names this method.