Skip to content
Advertisement

How to use SIGALARM in rust?

I have a problem using alarm from nix library in rust. I am trying to communicate two child process with alarms, the exercise consist in send a signal to child process to other every two seconds, and retun it with pipe. When I run the code it still waiting and I can’t see the message. This is my code:

JavaScript

Thanks!!!

Advertisement

Answer

Try the patch below and see if that helps.

The reader will block on the read from the pipe so there is no need for a pause on the reader.

The writer needs some event to trigger it every 2 seconds so use the alarm in the writer to create the trigger event which writes into the pipe.

That trigger will wake up the reader and show what the writer wrote into the pipe.

I am a bit weak on the use of wait so I am using waitpid instead.

Here is the output I observed after the patch:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement