What does this statement below do? If anyone can explain this function I would really appreciate it.
signal(SIGINT, SIG_DFL);
SIGINT is one of the predefined signals that's associated with the terminal interrupt character (commonly Ctrl + C ). It causes the shell to stop the current process and return to its main loop, displaying a new command prompt to the user.
In signal processing, a signal is a function that conveys information about a phenomenon. Any quantity that can vary over space or time can be used as a signal to share messages between observers. The IEEE Transactions on Signal Processing includes audio, video, speech, image, sonar, and radar as examples of signal.
When Ctrl+C is pressed, SIGINT signal is generated, we can catch this signal and run our defined signal handler. C standard defines following 6 signals in signal.
If you want to ignore the signal specified by the first argument (i.e., pretending that the signal never happens), use SIG_IGN for the second argument. In the above two lines, SIGINT and SIGALRM are ignored. If you want the system to use the default way to handle a signal, use SIG_DFL for the second argument.
SIGINT is the interrupt signal (ctrl+C). Its default behaviour is to terminate the process. SIGINT signal can be dis-positioned, means one can change the default behaviour ( By calling sighandler, or setting it SIG_IGN ) Now once the action is changes and you want to set it again the default behaviour of this signal then you should write
signal(SIGINT, SIG_DFL);
It will again change the default behaviour of the signal. ( which is to terminate a process )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With