JDK-8087286 : Need a way to handle control-C and possibly some other signals
  • Type: Enhancement
  • Component: core-libs
  • Affected Version: 9
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2015-06-11
  • Updated: 2022-10-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
Catching control-C and possibly other signals is one way for applications to handle user-interrupted action.  

There is currently no supported API to intercept and handle any signal.  sun.misc.Signal and sun.misc.SignalHandler are internal API that some existing application depends on.

Need to look into a possible replacement for sun.misc.Signal and SignalHandler API.
Comments
The problem as always with these things is discerning a signal that was directed at the application versus a signal that was directed at the VM. Taking over ctrl-C can leave the VM unable to be terminated (with ease, or non-abruptly)
30-06-2015

SIGTRAP was mentioned also: http://mail.openjdk.java.net/pipermail/jigsaw-dev/2015-June/004362.html
29-06-2015

A little personal feedback on how useful this is: I used the SignalHandler to recognise control C in a console application - the kjdb debugger tool - to let you terminate a long-running command (like getting all backtraces in all theads) that runs longer than you'd like. I just had the handler set a flag which the tool can check. The area of writing a console app is fairly neglected in Java, but that may be justifiable based on demand. After avoiding a termination due to an accidental (instinctive) control-C, the main frustration is using System.in to read user input. I did write a little library using JNI to read the terminal directly, to give a very "lite" emacs mode with ^P and ^N for history recall, and ^B and ^F to move forward within the edited line. I had ideas of implementing some other terminal capabilities, like knowing how wide the term window was so the tool could format appropriately, but haven't used that yet. On Windows, reading System.in gives you this for free in the command prompt.
12-06-2015