Using Signals to Terminate Processes

A P.I.P.S. process can terminate another P.I.P.S process by sending a SIGKILL or a SIGTERM signal to it using kill() or sigqueue().

SIGKILL terminates a process without any notification. Typically it used by a parent process to manage its children, or by a system utility to terminate other applications.

Note: Your process must have the PowerMangement capability to send a SIGKILL signal to another process.

SIGTERM is a request for termination. The receiving process can choose to shutdown gracefully or ignore the request. The following example code demonstrates how you can handle a SIGTERM signal and shutdown a process:

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
void sighandler(int signum)
    {
    if(signum == SIGTERM)
        {
        // Perform clean up
        exit(-1);
        }
    else
        printf(“Error: Unknown signal”);
    }
int main()
    {
    signal(SIGTERM,sighandler); // When SIGTERM arrives, invoke sighandler()
    // program logic
    return 0;
    }