Artificial intelligent assistant

What are signal traps? Signals are the way of communication between process but I have some questions What are signal traps? How the traps are related to signals in operating system?

Sometimes an example is worth more than a thousand words: This code in c++ exposes a very simple signal handler.


void gracefullShutdown(int sigNum) {

// cleanup or do wathever you need to do in case of received signal(s)

// Terminate this executable
exit(sigNum);
}

int main(int argc, char* argv[]) {

signal(SIGINT , gracefullShutdown);
signal(SIGTERM , gracefullShutdown);

std::cout << "starting..." << std::endl;

while(1);

exit(EXIT_SUCCESS);
}


When you press the Ctrl+C during execution of this program, the linux kernel will send a SIGINT signal to this program, normally it would terminate, but in this precise case it leaves you the possibility to do something before terminating.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 92918596a28ba5304d0c153d3d4d653c