using signals instead of busy wait

Hello,

 First time posting on this board hopefully someone will able to help me. 

I am looking for some examples of c programs which use a signal to notify the program to begin a certain action instead of having it continually loop to check to see if condition is attained(busy wait). Any tutorials or examples
will be appreciated.

This is how I think it should be done but still feels like a busy wait
while(1)
if(x == 5) // where x is the condition under which I want
// program to execute the action.
{
raise(signal);
}
sleep(3);
}

Sincerely,
Jut

The alarm() api sets a timer and when the timer expires delivers SIGALRM to the calling process. Meanwhile the process is suspended.

I suggest a program based around select and have a pipe pair dedicated to supporting signals. The write end is written by the signal handle (write a single byte containing the number of the signal) and have the select include the read end of the pipe in the read fd_set.

Then when a signal occurs a single byte is written to the pipe, this wakes up the select, the code in the select loop then reads the pipe and knows which signal occurred and can then handle it in a more graceful manner.

Hi.

  Thanks to everybody's ideas I have a solution to the problem.

Sincerely,
Jut

It would be ok to share it with us :slight_smile:

Mipko

Hello
i need a method that use a signal to notify the program to begin a certain action instead of having it continuously loop . Not like

while(1)
sleep(1);

process receiving signal get activated only when signal sender process send signal.
thanks in advanced