Well, you can modify your application to catch any signal except SIGKILL.
Shutdown operation or cleanup can be performed in a signal handler
Here is a simple example of setting up a handler to delete temporary files when certain fatal signals happen:
#include <signal.h>
void
termination_handler (int signum)
{
printf ("Caught signal %d\n", sig);
switch(signum)
{
case SIGINT:
printf ("CTRL C not allowed\n");
break;
case SIGTERM:
struct temp_file *p;
for (p = temp_file_list; p; p = p->next)
unlink (p->name);
exit(1);
break;
default:
...
}
}
int
main (void)
{
...
if (signal (SIGINT, termination_handler) == SIG_IGN)
signal (SIGINT, SIG_IGN);
if (signal (SIGHUP, termination_handler) == SIG_IGN)
signal (SIGHUP, SIG_IGN);
if (signal (SIGTERM, termination_handler) == SIG_IGN)
signal (SIGTERM, SIG_IGN);
...
}
Code after signal handler will not execute in case of SIGTERM.