Reputation: 61
NOTE: SEGSEGV is blocked when I raised a SIGSEGV like, raise(SIGSEGV);
but not on dereferencing of NULL
pointer or memory violation. what is the issue here?
Code:
void sig_handler(int signo)
{
psignal(signo,"i am in sig_handler\n");
}
int main()
{
sigset_t intmask;
int c = 0, *p = NULL;
if((signal(SIGSEGV , sig_handler)) == SIG_ERR)
perror("signal call is failed\n");
if ((sigemptyset(&intmask) == -1) || (sigaddset(&intmask, SIGSEGV) == -1))
perror("Failed to initialize the signal mask");
sigprocmask(SIG_BLOCK, &intmask, NULL);
fprintf(stdout, "SIGINT signal blocked\n");
c = *p;
}
Upvotes: 1
Views: 59
Reputation: 399813
The manual page for sigprocmask()
has the answer:
If SIGBUS, SIGFPE, SIGILL, or SIGSEGV are generated while they are blocked, the result is undefined, unless the signal was generated by
kill(2)
,sigqueue(3)
, orraise(3)
.
Upvotes: 1