Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Handling CTRL+C and Process killing on Windows #5054

Closed
geNAZt opened this issue Mar 17, 2013 · 2 comments
Closed

Handling CTRL+C and Process killing on Windows #5054

geNAZt opened this issue Mar 17, 2013 · 2 comments
Labels

Comments

@geNAZt
Copy link

geNAZt commented Mar 17, 2013

Under Xubuntu 12.10 and Debian 6 i am able to catch the Signals from the Kernel. On Windows i am not able to do this (it doesnt support it). So i assume that the exit event gets fired in all cases (CTRL+C and killed from Taskmanger). But if i want to catch a CTRL+C i must set the stdin to rawMode and add a keypressemitter. This breaks my code.

setInterval(function() {

}, 500000);

process.on('SIGINT', function() {
  process.exit(0);
});

process.on('SIGTERM', function() {
  process.exit(0);
});

process.on('exit', function() {
  process.stdout.write("Bye");
});

Expected Result:
Hitting CTRL+C on Windows: "Bye"
Killing it with the Taskmanager: "Bye"
Killing it on Linux (SIGTERM): "Bye"
Hitting CTRL+C on Linux: "Bye"

Current Result:
Hitting CTRL+C on Windows:
Killing it with the Taskmanager:
Killing it on Linux (SIGTERM): "Bye"
Hitting CTRL+C on Linux: "Bye"

@mscdex
Copy link

mscdex commented Mar 17, 2013

This should fix the problem.

piscisaureus added a commit that referenced this issue Mar 19, 2013
This reverts commit ea1cba6.

The offending commit was intended to land on the v0.8 branch only, but
it accidentally got merged at some point.

Closes #5054.
@piscisaureus
Copy link

@geNAZt

I pushed a patch that enables some signal support on windows. Short story: you can expect SIGINT to work now, as well as SIGBREAK and to some extent SIGHUP. However SIGTERM will never work because killing a process in the task manager is unconditional, e.g. there's no way for an application to detect or prevent it.

The long story comes from uv.h:

 * Some signal support is available on Windows:
 *
 *   SIGINT is normally delivered when the user presses CTRL+C. However, like
 *   on Unix, it is not generated when terminal raw mode is enabled.
 *
 *   SIGBREAK is delivered when the user pressed CTRL+BREAK.
 *
 *   SIGHUP is generated when the user closes the console window. On SIGHUP the
 *   program is given approximately 10 seconds to perform cleanup. After that
 *   Windows will unconditionally terminate it.
 *
 *   SIGWINCH is raised whenever libuv detects that the console has been
 *   resized. SIGWINCH is emulated by libuv when the program uses an uv_tty_t
 *   handle to write to the console. SIGWINCH may not always be delivered in a
 *   timely manner; libuv will only detect size changes when the cursor is
 *   being moved. When a readable uv_tty_handle is used in raw mode, resizing
 *   the console buffer will also trigger a SIGWINCH signal.
 *
 * Watchers for other signals can be successfully created, but these signals
 * are never generated. These signals are: SIGILL, SIGABRT, SIGFPE, SIGSEGV,
 * SIGTERM and SIGKILL.
 *
 * Note that calls to raise() or abort() to programmatically raise a signal are
 * not detected by libuv; these will not trigger a signal watcher.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants