You do this by defining a signal handler for SIGTERMalong these lines:
Somewhere in your include block:
#include <signal.h>
#include <stdio.h>
Yes, we do style me C!
Somewhere regarding the initialization of your code:
signal (SIGTERM, handler);
and then define the code for the signal handlers (clear everything, etc.):
void handler(int num)
{
switch (num)
{
case SIGTERM:
break;
}
}
Now, when you run pkill <app>where <app>is the name of the executable file, the code for will be run handler().
Without switches SIGTERM, a default signal will be sent to the application . If you decide to use a different signal, you will need to make sure that you are sending the same signal as "catch" in handler().
Relevant information can be found on man 7 signaland of course man kill.
source
share