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
5 More Discussions You Might Find Interesting
1. UNIX for Advanced & Expert Users
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
2. Shell Programming and Scripting
: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
3. Shell Programming and Scripting
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. UNIX for Advanced & Expert Users
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
5. Shell Programming and Scripting
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
LEARN ABOUT SUNOS
gsignal
ssignal(3C) Standard C Library Functions ssignal(3C)
NAME
ssignal, gsignal - software signals
SYNOPSIS
#include <signal.h>
void(*ssignal (int sig, int (*action)(int)))(int);
int gsignal(int sig);
DESCRIPTION
The ssignal() and gsignal() functions implement a software facility similar to signal(3C). This facility is made available to users for
their own purposes.
ssignal()
Software signals made available to users are associated with integers in the inclusive range 1 through 17. A call to ssignal() associates a
procedure, action, with the software signal sig; the software signal, sig, is raised by a call to gsignal(). Raising a software signal
causes the action established for that signal to be taken.
The first argument to ssignal() is a number identifying the type of signal for which an action is to be established. The second argument
defines the action; it is either the name of a (user-defined) action function or one of the manifest constants SIG_DFL (default) or SIG_IGN
(ignore). The ssignal() function returns the action previously established for that signal type; if no action has been established or the
signal number is illegal, ssignal() returns SIG_DFL.
gsignal()
The gsignal() raises the signal identified by its argument, sig.
If an action function has been established for sig, then that action is reset to SIG_DFL and the action function is entered with argument
sig. The gsignal() function returns the value returned to it by the action function.
If the action for sig is SIG_IGN, gsignal() returns the value 1 and takes no other action.
If the action for sig is SIG_DFL, gsignal() returns the value 0 and takes no other action.
If sig has an illegal value or no action was ever specified for sig, gsignal() returns the value 0 and takes no other action.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|MT-Level |Unsafe |
+-----------------------------+-----------------------------+
SEE ALSO
raise(3C), signal(3C), attributes(5)
SunOS 5.10 29 Dec 1996 ssignal(3C)