using signals instead of busy wait


 
Thread Tools Search this Thread
Top Forums Programming using signals instead of busy wait
# 1  
Old 11-20-2007
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
# 2  
Old 11-20-2007
The alarm() api sets a timer and when the timer expires delivers SIGALRM to the calling process. Meanwhile the process is suspended.
# 3  
Old 11-21-2007
Quote:
Originally Posted by jut26
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
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.
# 4  
Old 11-21-2007
signals

Hi.

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


Sincerely,
Jut
# 5  
Old 11-21-2007
It would be ok to share it with us Smilie

Mipko
# 6  
Old 03-04-2009
Java signal to notify the program to begin

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
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

calling a shell script in background and wait using "wait" in while loop

Hi, I am facing a strange issue, when i call a script from my while loop in background it doesnt go in background, despite the wait i put below the whil loop it goes forward even before the process put in background is completed. cat abc.txt | while read -u4 line do #if line contains #... (2 Replies)
Discussion started by: mihirvora16
2 Replies

2. UNIX for Advanced & Expert Users

Filesystem mystery: disks are not busy on one machine, very busy on a similar box

Hi, We have a filesystem mystery on our hands. Given: 2 machines, A and Aa. Machine Aa is the problem machine. Machine A is running Ubuntu, kernel 2.6.22.9 #1 SMP Wed Feb 20 08:46:16 CST 2008 x86_64 GNU/Linux. Machine Aa is running RHEL5.3, kernel 2.6.18-128.el5 #1 SMP Wed Dec 17 11:41:38... (2 Replies)
Discussion started by: mschwage
2 Replies

3. Shell Programming and Scripting

wait command - cat it wait for not-chile process?

Did not use 'wait' yet. How I understand by now the wait works only for child processes, started background. Is there any other way to watch completion of any, not related process (at least, a process, owned by the same user?) I need to start a background process, witch will be waiting... (2 Replies)
Discussion started by: alex_5161
2 Replies

4. Shell Programming and Scripting

Need to execute 2 scripts, wait, execute 2 more wait, till end of file

:cool: I need to execute a shell script to do the following: cat a file run two back ground processes using the first two values from the file wait till those background processes finish run two more background processes using the next two values from the file wait till those background... (1 Reply)
Discussion started by: halo98
1 Replies

5. UNIX for Advanced & Expert Users

CD Drive is busy

one problem which seems simple but i've faced many times is when i've used cd & want to eject, however i'm not in /dev/cdrom/... in any of my Xterms but it gives the message that the the CD drive is busy. the only thing i could do is /etc/init.d/volmgt stop & eject the CD manually but it doesn't... (6 Replies)
Discussion started by: nikk
6 Replies
Login or Register to Ask a Question