Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Understanding signal blocking and signal suspension

After reading the documentation I still don’t really understand signal blocking. If you have a mask that blocks a given signal, do you need to unblock that signal first to allow the program to intercept it or does signal blocking behave in a different way?

If you use sigsuspend, does your program get suspended until a given signal from the mask you pass as an argument arrives?

Should the signal you wait for when using sigsuspend be unblocked or is it not necessary?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Btw i am using C and the pthread library to write my programs

>Solution :

If you have a mask that blocks a given signal, do you need to unblock that signal first to allow the program to intercept it or does signal blocking behave in a different way?

A signal is never delivered to any thread that has it blocked. If a signal is raised for a process while all threads of that process have it blocked, then it remains pending until it is unblocked for at least one thread, or the process terminates.

If you use sigsuspend, does your program get suspended until a given signal from the mask you pass as an argument arrives?

No. The signal mask you pass to sigsuspend has the same meaning as the one you pass to (for example) sigprocmask(): it specifies a complete set of the signals that should be blocked. This mask must not include any signals you want the thread to be able to receive. Often, it is appropriate to pass sigsuspend() the mask that was in effect prior to a preceding sigprocmask() call, which the latter function will have provided to you if you asked for it.

Should the signal you wait for when using sigsuspend be unblocked or is it not necessary

At all times, you should ensure that any signal you want a thread to be able to receive is unblocked, and conversely, that any signal the thread must not receive is blocked. This is why sigsuspend() gives you a way to specify a different signal mask to be in effect for the duration of the call.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading