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 6799725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:52:57+00:00 2026-05-26T18:52:57+00:00

I wrote a similar question at How to block all SIGNALS in thread WITHOUT

  • 0

I wrote a similar question at How to block all SIGNALS in thread WITHOUT using SIGWAIT? but must admit I still need 100% clarity on the topic…C is not my day job 😉 Sorry for the similar question….

All i need 100% clarification on is:

  • I want to block all signals from going to the thread I create, but I want to catch the signals mentioned below in the MAIN thread, hence the SIG_UNBLOCK after the thread creation.

  • Also very important is to prevent any interruptions to libraries I have no control over from being “disturbed” during i.e. a SIGINT. I have a situation where a WAIT step is happening in a thread on a “message GET from a queue”. That wait step seems to reject SIGINT even though the signal handler is defined in main, hence the SA_RESTART below.

Could you please let me know if the code below will accomplish this? I am pretty sure it is ok.

Thanks for the help, much appreciated

Lynton

The following is a snippet of the MAIN program:

int main(int argc, char * argv[]){
    sigset_t set;
    struct sigaction sa_shutdown;
    struct sigaction sa_error;  

    //Shutdown hook for CTRL-C    
    sa_shutdown.sa_handler = shutdownHook;
    sigemptyset(&sa_shutdown.sa_mask);
    sa_shutdown.sa_flags = SA_RESTART;
    sigaction(SIGINT, &sa_shutdown, NULL);        
    //Error handlers for erroneous signals
    sa_error.sa_handler = signalErrorHandler;
    sigemptyset(&sa_error.sa_mask);
    sa_error.sa_flags = SA_RESTART;
    sigaction(SIGSEGV, &sa_error, NULL);    
    sigaction(SIGBUS, &sa_error, NULL); 
    sigaction(SIGILL, &sa_error, NULL); 
    sigaction(SIGTERM, &sa_error, NULL); 
    sigaction(SIGABRT, &sa_error, NULL);    

    //BLOCK all SIGNALS in threads  
    sigfillset(&set);
    rc = pthread_sigmask(SIG_BLOCK, &set, NULL);    
    if(rc != 0){
        printf("Thread sigmask failed\n");
        exit(1);
    }
    rc = pthread_create(&outboundThread, NULL, outboundThreadMainLoop, (void *)argv);
    if(rc != 0){
        printf("Thread creation failed\n");
        exit(1);
    }
    pthread_sigmask(SIG_UNBLOCK, &set, NULL);
    pthread_join(outboundThread, NULL); 
    return 0;
}
  • 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-26T18:52:58+00:00Added an answer on May 26, 2026 at 6:52 pm

    Regarding to block all signals, your code looks OK to me.

    Anyway I’d say you should not block SIGFPE, SIGILL, SIGSEGV, or SIGBUS.

    pthread_sigmask()‘s man page says: “If any of the SIGFPE, SIGILL, SIGSEGV, or SIGBUS signals are generated while they are blocked, the result is undefined, unless the signal was generated by the kill() function, the sigqueue() function, or the raise() function.“

    Regarding “… interruptions to libraries …“: If your are referring to any call into libraries from a thread created the way you did in your example you, I’d also say that’s OK, they won’t be interrupted.

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

Sidebar

Related Questions

My question is similar to this one: need to call soap ws without wsdl
Possible Duplicate: Need help solving Project Euler problem 200 Similar to this question Project
I asked this question yesterday, but I wrote it far more complicated than I
I have ask similar question before : Java String Memory Leak But I was
* UPDATE: *I've already answered my question. But you can still give me advise
I wrote a trigger that updates local table and similar table on linked server.
Asciidoc supports callouts . How can one write similar callouts using reStructuredText ?
I wrote a windows service using VB that read some legacy data from Visual
This is very similar to another question ( Functional Data Structures in Java )
I'm writing a file generic block for my application and started with using Lambda

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.