There could be scenarios where a process needs to send a signal to other processes. This recipe will teach you how to achieve that using a hands-on approach.
Learning how to send a signal to another process
How to do it...
We'll write a program that will send the SIGTERM signal to a running process. We'll see the process terminating as expected. On a shell, open a new source file called signal_send.cpp. We'll be using the system call, kill(), which sends a signal sig to a process specified by pid. The program accepts an input parameter, which is pid of the program to terminate:
#include<stdio.h>
#include<signal.h>
#include <iostream>
int main(int argc, char* argv[])
{
std...