Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process: process.kill() and signals on Windows #12378

Closed
vsemozhetbyt opened this issue Apr 12, 2017 · 16 comments
Closed

process: process.kill() and signals on Windows #12378

vsemozhetbyt opened this issue Apr 12, 2017 · 16 comments
Labels
doc Issues and PRs related to the documentations. process Issues and PRs related to the process subsystem. windows Issues and PRs related to the Windows platform.

Comments

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Apr 12, 2017

  • Version: many
  • Platform: Windows 7 x64
  • Subsystem: process

The doc states:

Note: Windows does not support sending signals, but Node.js offers some emulation with process.kill(), and ChildProcess.kill().

WRT supporting signals on Windows, the doc makes only this remark:

SIGTERM is not supported on Windows, it can be listened on.

As for the rest, process.kill() behavior on Windows is somehow confusing and hazardous. A test file with just this line:

process.kill(process.pid, SIGNAL_NAME_MENTIONED_IN_THE_DOC);

gives three types of results.

  1. SIGTERM, SIGINT, SIGKILL (despite the doc note wrt SIGTERM) — silently exit.
  2. SIGUSR1, SIGPIPE, SIGSTOP, SIGBUS — throw this error:
internal/process.js:184
        throw new Error(`Unknown signal: ${sig}`);
        ^

Error: Unknown signal: SIGUSR1
    at process.kill (internal/process.js:184:15)
    at Object.<anonymous> (...\test.js:5:9)
    at Module._compile (module.js:607:30)
    at Object.Module._extensions..js (module.js:618:10)
    at Module.load (module.js:516:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.runMain (module.js:643:10)
    at run (bootstrap_node.js:441:7)
    at startup (bootstrap_node.js:144:9)
  1. SIGHUP, SIGBREAK, SIGWINCH, SIGFPE, SIGSEGV, SIGILL — throw this error:
internal/process.js:190
      throw errnoException(err, 'kill');
      ^

Error: kill ENOSYS
    at exports._errnoException (util.js:1057:11)
    at process.kill (internal/process.js:190:13)
    at Object.<anonymous> (...\test.js:6:9)
    at Module._compile (module.js:607:30)
    at Object.Module._extensions..js (module.js:618:10)
    at Module.load (module.js:516:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.runMain (module.js:643:10)
    at run (bootstrap_node.js:441:7)

As with this issue, I am not sure, if this is a Node.js or libuv domain. Also I am not sure if this should be addressed in code or in docs. So just reporting for extra precaution.

@vsemozhetbyt vsemozhetbyt added doc Issues and PRs related to the documentations. process Issues and PRs related to the process subsystem. windows Issues and PRs related to the Windows platform. labels Apr 12, 2017
@vsemozhetbyt
Copy link
Contributor Author

In addition, I can't attach an event listener for any signal fired by the process.kill(), so the example here does not work on Windows with any signal (it either throws or silently exits). Maybe this is also worth to be documented.

@sam-github
Copy link
Contributor

sam-github commented Apr 13, 2017

The docs could doubtless be improved, but they say:

Note: Windows does not support sending signals, but Node.js offers some emulation with process.kill(), and ChildProcess.kill(). Sending signal 0 can be used to test for the existence of a process. Sending SIGINT, SIGTERM, and SIGKILL cause the unconditional termination of the target process.

Then you say:

SIGTERM, SIGINT, SIGKILL (despite the doc note) — silently exit.

I don't get it, "silent exit" === "unconditional termination", doesn't it? What doc note are you talking about?

And like the docs say, all other signals are unsupported.

They should perhaps be un-supported more uniformly, perhaps with ENOSYS instead of Unknown signal.

This is probably happening because node does some checking to convert signal strings to numbers, and it fails on Windows because it doesn't know about some signal strings.

But even if it suceeds in converting a signal string to a number, Windows doens't support kill, thus its ENOSYS.

@sam-github
Copy link
Contributor

per "example doesn't work", it links to the signal docs, which say under what conditions it works (3 signals have some emulation on windows). Perhaps its better to rework the docs, moving the signal list into two places, one in process.kill which describes behaviour when signal is sent, and one in process.on() which describes when signal is received. The current structure is I think contributing to the confusion.

@vsemozhetbyt
Copy link
Contributor Author

@sam-github 'despite the doc note': I mean, the doc states 'SIGTERM is not supported on Windows', but exactly SIGTERM does not throw any ENOSYS or Unknown signal error messages, while other many signals throw errors and doc states nothing about support for them.

@sam-github
Copy link
Contributor

Maybe you can improve it now that you know how it works? To be clear, SIGTERM is not supported on Windows as a signal. Windows as an O/S has absolutely no signal support. Like it says later (should probably be moved closer to the note you mention), sending SIGTERM/KILL/INT cause windows processes to be terminated on Windows, as a way of UV trying to emulate signals where they do not exist.

If SIGTERM was supported on Windows, you could listen for it and receive it... but you cannot. You can listen..., but you'll never receive it.

@vsemozhetbyt
Copy link
Contributor Author

vsemozhetbyt commented Apr 13, 2017

I try to abstain from writing English texts of a significant length, as I am clumsy at that. And, to be honest, signals on Windows is a murky topic for me. I do feel it is somehow wrong for me to just dump such issues that I can't fix myself. Sorry. Maybe somebody from @nodejs/platform-windows will find some time to refactor the doc on this topic in future.

@refack
Copy link
Contributor

refack commented Apr 13, 2017

[offtopic] anyone knows a TODO app for windows that can track github issues? I would like to address this issue, but after I finish some stuff I'm doing. By them most probably I'd forget about this one.

@sam-github
Copy link
Contributor

been trying octobox.io lately, I usually just keep a markdown file, http://todotxt.com/ can be nice, too.

@gibfahn
Copy link
Member

gibfahn commented Apr 16, 2017

@refack alternately you could just assign it to yourself, then it'll show up in the GitHub list of assigned to me issues.

@refack refack self-assigned this Apr 27, 2017
@alohaninja
Copy link

alohaninja commented Jun 19, 2017

The windows subsystem lacks signaling support using process.kill(). Managing complex jobs/processes on windows without proper signaling is still doable though - it just takes some creative workarounds.
process.send will allow you to message child processes to notify them of pending termination.
For hung child processes (such as long-running tests), it's best to fire up exec/execFile to kill any processes that have been running longer than a set threshold.
This helper will kill orphaned processes via powershell.exe running longer than 30 min: Get-Process -name myprocess | ? { $_.StartTime -lt (Get-Date).AddMinutes(-30) } | Stop-Process -Force

@refack
Copy link
Contributor

refack commented Jun 19, 2017

“Fear is the path to the dark side. Fear leads to anger. Anger leads to hate. Hate leads to suffering.”
– Yoda

@alohaninja no need to be so negative...

@alohaninja
Copy link

@refack - posted a more positive contribution. Cheers for handling professionally. ;-)

@refack
Copy link
Contributor

refack commented Jun 20, 2017

@refack - posted a more positive contribution. Cheers for handling professionally. ;-)

I'll bump it up my todo list 😉 a.k.a. I'll see what I can do...

@BridgeAR
Copy link
Member

Is this still an issue?

@vsemozhetbyt
Copy link
Contributor Author

It seems all that could be done is done for now)

@imnemo
Copy link

imnemo commented Nov 22, 2018

I have to excute something like taskkill /f /pid ${pid} by ChildProcess.exec to kill a process on windows, but still do not have any idea to kill a signal to a process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. process Issues and PRs related to the process subsystem. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

No branches or pull requests

7 participants