Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i remove a signal handler

I've made the follow signal handler

struct sigaction pipeIn;
pipeIn.sa_handler = updateServer;
sigemptyset(&pipeIn.sa_mask);
sa.sa_flags = SA_RESTART;

if(sigaction(SIGUSR1, &pipeIn, NULL) == -1){

    printf("We have a problem, sigaction is not working.\n");
    perror("\n");
    exit(1);    

}

How do I remove or block this particular handler so that I can set up another signal handler that uses the same signal? Thanks.

like image 499
Dr.Knowitall Avatar asked Feb 15 '12 22:02

Dr.Knowitall


People also ask

How do I unregister a signal handler?

Here is what you do: signal(SIGINT, SIG_DFL); That resets the signal handler back to whatever the default behavior was for that signal (including the default disposition if it hasn't been set). In the case of SIGINT, it's aborting your process without a core dump.

What is the purpose of signal handler?

A signal handler is a function which is called by the target environment when the corresponding signal occurs. The target environment suspends execution of the program until the signal handler returns or calls longjmp() . Signal handlers can be set with signal() or sigaction() .

Where are signal handlers executed?

Most handlers run on the thread's stack. A handler can run on an alternate stack if the process uses sigaltstack(2) to provide the stack, and sigaction(2) with SA_ONSTACK to set the handler. The kernel pushes some things onto the chosen stack, and sets some of the thread's registers.

Does sigaction call the signal handler?

sigaction() can be called with a NULL second argument to query the current signal handler. It can also be used to check whether a given signal is valid for the current machine by calling it with NULL second and third arguments.


1 Answers

Use SIG_DFL in place of the function pointer when calling sigaction(2).

like image 130
Nikolai Fetissov Avatar answered Oct 07 '22 06:10

Nikolai Fetissov