Re: How doess Cocoa handle SIGINT?
Re: How doess Cocoa handle SIGINT?
- Subject: Re: How doess Cocoa handle SIGINT?
- From: Thierry Faucounau <email@hidden>
- Date: Tue, 26 Jun 2001 11:55:25 -0600
On Tuesday, June 26, 2001, at 10:34 AM, Douglas Davidson wrote:
On Monday, June 25, 2001, at 05:05 PM, Thierry Faucounau wrote:
I have some questions relating to the handling of SIGINT from a Cocoa
app.
Does the Cocoa runloop handle signals for you? Or is it OK (in fact
required) to put in my own signal handler?
Cocoa has a general policy of avoiding the use of signals. You may use
them yourself for whatever purposes you require, but you should keep in
mind that very little is safe from within the context of a signal
handler. In particular, there is no guarantee that any Cocoa APIs can
be safely called from within a signal handler.
This is fine. All I would do is set a global which instructs my "engine"
(which runs in a separate thread) to halt it's processing and return.
Does hitting Control-C on the keyboard send a SIGINT to the frontmost
Cocoa app?
No; this is a shell convention, not related to the GUI. Hitting
control-C on the keyboard sends a key-down event to the active Cocoa
application, with the character 'c' and the control modifier. If
Terminal happens to be the active application, then I believe that
hitting control-C will send a SIGINT to the current foreground process
in the current key window. If you launch a Cocoa application from a
shell (as you certainly may) then you can interrupt it in this way.
However, in general, most Cocoa applications are launched by other
means, and you will need to signal them by pid.
Douglas Davidson
This is what I gathered from looking at the source to tcsh; that it was
a shell thing. I wanted to make there wasn't some sort of hard wired
keyboard sequence like command-power on classic Mac to invoke the
debugger.
It seems then that my situation gets a lot easier, as I mentioned, in
the UNIX code, the signal handler just sets a global instructing the
engine to abort whatever it is doing.
In my Cocoa version, I'll just trap the abort key sequence (I'll
probably change it to Command-. and hook it up as a menu command) from
the main AppKity thread, set the global and be done with it. I'll still
set the SIGINT signal handler for those times when the IDL Cocoa app
(there is also a pure command line version) is run from the command
line, or someone sends a kill -2 to it.
Thanks to everyone for the info.
--
Thierry Faucounau
Research Systems, Inc.