0

I need to write a function which restores default behavior of CTRL+C (terminating process) after pressing CTRL+\ Here's my program:

#include <stdlib.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>

void sig_int(int sig)
{

    printf("U PRESSED CTRL+C\n");
}
void sig_quit(int sig){
            printf("CTRL+C NOW DO ITS KILLING JOB\n");

}
int main(int argc, char** argv) 
{
    signal(SIGINT,sig_int);
    signal(SIGQUIT, sig_quit);

    return 0;
}

Thank you for all the help and descriptions to better understanding :)

Sz3jdii
  • 507
  • 8
  • 23

2 Answers2

2

Taken from the man page on my machine:

To set the default action of the signal to occur as listed above, func should be SIG_DFL.

so signal(SIQUIT, SIG_DFL) if I've understood your question correctly.

DrC
  • 7,528
  • 1
  • 22
  • 37
2

signal returns the previously configured handler, store it somewhere and then use signal to restore it whenever you want. Also SIG_DFL points to the C run-time's default handler, but that's not always the right one to use.

jwdonahue
  • 6,199
  • 2
  • 21
  • 43