CyberPeasant 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?
> >
>
> Most of the things you mention are taken care of regardless. If you
> want to be more orderly, man atexit(3) for 'normal' program wind-down,
> or see man signal(2) to catch signals and do what you will.
Personally I'd recommend using sigaction() in preference to signal().
Especially given that libc-5's signal() defaults to SysV semantics
whereas libc-6's defaults to BSD semantics.
It probably doesn't make much difference if you're going to call
exit() from within the signal handler. But if you want to return and
then exit the main loop, you probably want SysV semantics, i.e. don't
resume a blocking system call that was in progress when the signal
arrived.
--
Glynn Clements <[EMAIL PROTECTED]>