How to use sigatomic_t volatile variables in signal handlers instead of calling several functions or making semops?

I'm sorry in advance if this isn't the space for this question, but I can't find much information on the subject. In my project I have a parent who forks several children and at one point, it will send SIGTERM to his still-alive kids. The kids, who are either working or "stuck" on a msgop. Immediately after receiving the signal, they get to... doing other things, including calling other functions and releasing or reserving sempahores, accessing a shared memory, doing other stuff based on whether they can make these semops. After these operations, the kids exit.

While my project still works like this, as it's a relatively small project, I'd like to code as correctly as possible and I read that signal handlers should be very short, preferably just few lines of code (like changing the sigatomic_t volatile variable's value). While it's my understanding that I'm supposed to check said variable's value somewhere in the code (and if it's changed, do everything I'm doing in the handler), I don't understand where I'm supposed to check its value because signals can interrupt the kids at any point in time.

Any sort of help, examples, explanations are extremely appreciated; I thank you in advance. Or even just someone pointing me to where I can find more examples, that specifically mention signal handlers and how my functions are supposed to be called immediately, that's also great.

(I can only use System V IPCs and none of my processes access the internet, in case it's relevant in any way)

reddit.com
u/Avi250 — 13 days ago

In a message queue, can 2 consumers consume messages of the same type? In C.

Hello, everyone; I have a server and multiple clients, who send their requests to the server. At one point, there could be another server (I'm calling them servers for a lack of a better word) to help the first server out. However, I need the consumers to be in a queue. I know it is agreed upon to have the messages' type be 1 and the server answers back with a message whose type is the client's pid. I also know message queues are destructive.

That said, can I have 2 servers consume type-1 messages? They'd have to race for them, which isn't a problem (at least not in my simulation: think restaurant or ticket offices). However, I need each message to be consumed, and only be consumed once. Even if it is possible, is it a practice that is frowned upon? If yes, why?

I'm writing this in C on linux, if it's necessary information.

Thank you in advance!

Edit: we have covered pipes, fifos, and system v mq, semaphores and shared memory in our OS program

reddit.com
u/Avi250 — 5 months ago