Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4059412
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:12:20+00:00 2026-05-20T15:12:20+00:00

i have written a small piece of code. This code first blocks the {SIGSEGV},

  • 0

i have written a small piece of code. This code first blocks the {SIGSEGV}, then adds SIGRTMIN to the same set. So, my final signal set is, {SIGSEGV,SIGRTMIN}. Thus, if i use SIG_UNBLOCK, as per my understanding, first SIGRTMIN should be unblocked, and then again if i invoke SIG_UNBLOCK, SIGSEGV should be unblocked.

That is, 1) {SIGSEGV,SIGRTMIN} 2) SIG_UNBLOCK = unblock SIGRTMIN, 3) Again invoke SIG_UNBLOCK = unblock SIGSEGV.
I am giving the process a SIGRTMIN only, thus my second unblock should halt the process with SIGRTMIN. But it is not. Please help.
N.B: Please don’t give links to answers of other questions on sigprocmask( ), i have seen them and they don’t clarify my question.

enter code here
#include <signal.h>
#include <unistd.h>
#include <stdio.h>

int main()
{
 sigset_t old_set,new_set;
 sigemptyset(&old_set);
 sigemptyset(&new_set);

 if(sigaddset(&old_set,SIGSEGV)==0)
 {
   printf("sigaddset successfully added for SIGSEGV\n");
 }
 sigprocmask(SIG_BLOCK,&old_set,NULL); // SIGSEGV signal is masked
 kill(0,SIGSEGV);


 //*****************************************************************

 if(sigaddset(&new_set,SIGRTMIN)==0)
 {
  printf("sigaddset successfully added for SIGRTMIN\n");
 }
  sigprocmask(SIG_BLOCK,&new_set,&old_set); // SIGRTMIN signal is masked
 kill(0,SIGSEGV);

 //****************** Unblock one signal at a time ******************

 sigprocmask(SIG_UNBLOCK,&new_set,&old_set); // SIGRTMIN signal is unmasked
 sigprocmask(SIG_UNBLOCK,&new_set,&old_set); // SIGSEGV signal is unmasked

}

Output:
 [root@dhcppc0 signals]# ./a.out
  sigaddset successfully added for SIGSEGV
  sigaddset successfully added for SIGRTMIN
  (Note:SIGSEGV is not received even after sigprocmask(SIG_UNBLOCK,&new_set,&old_set); a second time)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:12:21+00:00Added an answer on May 20, 2026 at 3:12 pm

    Your premise is wrong. The whole set gets blocked and unblocked with a single call of sigprocmask.

    Also, normally you would create a set containing every signal you want to block, then you would attempt to block them all with sigprocmask(SIG_BLOCK, pointer_to_sigset);.

    Your code doesn’t really unblock SIGSEGV though. Here’s what i would write WITHOUT error handling, because it would make the snippet unnecessarily long. Check every function
    for errors though, the lists of possible errors are provided by man pages:

    /* ... */
    sigset_t signal_set; /* We don't need oldset in this program. You can add it,
                            but it's best to use different sigsets for the second
                            and third argument of sigprocmask. */
    sigemptyset(&signal_set);
    
    sigaddset(&signal_set, SIGSEGV);
    sigaddset(&signal_set, SIGRTMIN);
    
    /* now signal_set == {SIGSEGV, SIGRTMIN} */
    
    sigprocmask(SIG_BLOCK, &signal_set, NULL): /* As i said, we don't bother with the 
                                                  oldset argument. */
    
    kill(0,SIGSEGV);  
    kill(0,SIGSEGV);  /* SIGSEGV is not a realtime signal, so we can send it twice, but
                         it will be recieved just once */
    
    sigprocmask(SIG_UNBLOCK, &signal_set, NULL); /* Again, don't bother with oldset */
    
    /* SIGSEGV will be received here */
    

    Of course, you might want to split blocking the signals into two operations on separate sets. The mechanism works like this: there is some set of blocked signals, which would replace oldset if you provided an oldset argument. You can add to that set with SIG_BLOCK, remove from that set with SIG_UNBLOCK, and change the whole set to your liking with SIG_SETMASK arguments of the sigprocmask function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a small java application for which I need to obtain performance
I have written a small Perl script and now I would like to create
As a Christmas gift I have written a small program in Java to calculate
In Ruby I have often written a number of small classes, and had a
I have a small AJAX application, written in PHP that I did not secure
I have written some code in my VB.NET application to send an HTML e-mail
I have written a small XML validator, that takes in an XML file and
I have written a small program using Borland's C++ builder, and along the way,
I have written a small HTTP server and everything is working fine locally, but
I have written a small script in Perl which I am executing on Windows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.