Hi Everybody, In my note about increasing my skill, I told you that I wrote
Pascal with C syntax. I meant that my C programs looked too much like
Pascal programs. I did not mean that I wrote Pascal in a C-like style.
Sorry.
Best wishes,
Bill
is it possible to have a function called when the user presses ^C or kills
the program so that the program can 'clean up' before being terminated? (i.e
close all open files, write out data, free allocated memory etc). if so, how?
-[[EMAIL
Hi,
Sure you just need to have a signal handler in your program.
For instance:
#include signal.h
int catch_signal(); /* Prototype function */
int main()
{
.
.
.
/*
* Setup to catch interrupt (^C)
*/
signal(SIGINT, catch_signal);
.
.
} /* END: main() */
int catch_signal()
{
On Tue, 16 Jun 1998, James wrote:
is it possible to have a function called when the user presses ^C or kills
^C generates SIGINT so u may catch it by sigaction()/signal()
SIGKILL cannot be caught so if your process is kill-ed it has no chance of
cleaning after itself. Cleanup routines
Hello, James!
On Tue, 16 Jun 1998, James wrote:
is it possible to have a function called when the user presses ^C or kills
the program so that the program can 'clean up' before being terminated? (i.e
close all open files, write out data, free allocated memory etc). if so,
On Mon, 15 Jun 1998, Brett Thompson wrote:
-Why, hello there! :)
-
-This is just a really quick little answer, as I'm sure if you wait
-somebody else much more clever than I will probably give a better
-response... it just might suffice though, anyway, here goes. :)
-
-Note that C++ does
James wrote:
is it possible to have a function called when the user presses ^C or kills
the program so that the program can 'clean up' before being terminated? (i.e
close all open files, write out data, free allocated memory etc). if so, how?
Use sigaction() to install a handler for SIGINT,
Marin D wrote:
void handle_sigint()
{
/* your cleanup code */
printf("Doing cleanup\n");
fflush(stdout);
The stdio functions aren't guaranteed to be re-entrant, so they
shouldn't be called from within a signal handler.
--
Glynn Clements [EMAIL PROTECTED]