Ask a Question related to UNIX Programming, Design and Development.
-
Andrej Hocevar #1
infinite loops -- waiting for some event
Hello,
what is the best way of solving cases where one has to wait
(forever, until killed or instructed otherwise) for some event to
occur? E.g., wait for data, monitoring a file? In fact, that task is
not that difficult, but takes over the CPU if the infinite loop
lacks sleep(). I've always thought using this method was somehow
inferior but then found out that even utilities like tail(1) (on
Linux) use it. Or on another occasion, if one uses curses (UNIX
again), which will most likely include an infinite loop, with the
nodelay(...) option turned on. Obviously, there must be a solution to
such cases: with nodelay() turned off, the infinite loop doesn't need
sleep(). Is a daemon, thus a system-dependant solution, the best way
to go or is it unconnected with such a task?
What is the solution behind these methods?
Thanks,
andrej
--
echo ${girl_name} > /etc/dumpdates
Andrej Hocevar Guest
-
Getting Error: Event Type 'flash.event:event' is unavailable ?????
Hi, I am not using Cairngorm or anything, but trying to get an app built first without it then look into it. I am getting this error however... -
Mysql infinite loop?!
this query doesnt work: SELECT d.cID,d.cLName,d.cFName , k.kid FROM cname d, cu_key e, rep_key f , `key` k WHERE (d.cLName LIKE '%') and (((e.cID... -
Infinite recursion detected... How do I prevent that?
I have a rule similar to this: CREATE RULE rule_branch_delete AS ON DELETE TO tree DO DELETE FROM tree WHERE ancestor_id IS NOT NULL AND... -
Weird Infinite loop
Hello, I have this piece of code, and since i put it on a new webserver, it has caused an infinite loop. As you can see, n begins at 1, and B_x... -
infinite menu help
Hello folks. I'm having a few difficulties with a horizontally scrolling infinite menu on a flash site I am building. My problem is that only... -
Barry Margolin #2
Re: infinite loops -- waiting for some event
In article <slrnbh8irl.r2.drejcica@sonet.utopija.linux>,
Andrej Hocevar <drejcica@volja.net> wrote:If the event you're waiting for is data from a device, you normally block>Hello,
>what is the best way of solving cases where one has to wait
>(forever, until killed or instructed otherwise) for some event to
>occur? E.g., wait for data, monitoring a file? In fact, that task is
>not that difficult, but takes over the CPU if the infinite loop
>lacks sleep(). I've always thought using this method was somehow
>inferior but then found out that even utilities like tail(1) (on
>Linux) use it. Or on another occasion, if one uses curses (UNIX
>again), which will most likely include an infinite loop, with the
>nodelay(...) option turned on. Obviously, there must be a solution to
>such cases: with nodelay() turned off, the infinite loop doesn't need
>sleep(). Is a daemon, thus a system-dependant solution, the best way
>to go or is it unconnected with such a task?
in read() or select() to wait for data to be available.
If you're monitoring an ordinary file, there's usually no alternative to an
infinite loop, and you should have a sleep() in it to keep from
monopolizing the system.
--
Barry Margolin, [email]barry.margolin@level3.com[/email]
Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
Barry Margolin Guest
-
Gianni Mariani #3
Re: infinite loops -- waiting for some event
Andrej Hocevar wrote:select() and or poll() are the most common ways to do what you describe> Hello,
> what is the best way of solving cases where one has to wait
> (forever, until killed or instructed otherwise) for some event to
> occur? E.g., wait for data, monitoring a file? In fact, that task is
> not that difficult, but takes over the CPU if the infinite loop
> lacks sleep(). I've always thought using this method was somehow
> inferior but then found out that even utilities like tail(1) (on
> Linux) use it. Or on another occasion, if one uses curses (UNIX
> again), which will most likely include an infinite loop, with the
> nodelay(...) option turned on. Obviously, there must be a solution to
> such cases: with nodelay() turned off, the infinite loop doesn't need
> sleep(). Is a daemon, thus a system-dependant solution, the best way
> to go or is it unconnected with such a task?
>
on unix.
select and poll suffer scalability issues when you start dealing with
around several thousand or more file descritors and there are newer
techniques like /dev/kqueue or signals (SIGIO) and most recently and
probably the best technique yet is epoll on linux.
The problem you describe with curses I have solved with select and poll
but you need to be careful wrt buffering, i.e. data may not be available
from the kernel but may be sitting in an internal buffer and waiting on
I/O at that point would be bad because you'd rather finish processing
the remaining data in the buffer.
Gianni Mariani Guest
-
Valentin Nechayev #4
Re: infinite loops -- waiting for some event
>>> Andrej Hocevar wrote:
AH> what is the best way of solving cases where one has to wait
AH> (forever, until killed or instructed otherwise) for some event to
AH> occur? E.g., wait for data, monitoring a file? In fact, that task is
AH> not that difficult, but takes over the CPU if the infinite loop
AH> lacks sleep(). I've always thought using this method was somehow
AH> inferior but then found out that even utilities like tail(1) (on
AH> Linux) use it. Or on another occasion, if one uses curses (UNIX
AH> again), which will most likely include an infinite loop, with the
AH> nodelay(...) option turned on. Obviously, there must be a solution to
AH> such cases: with nodelay() turned off, the infinite loop doesn't need
AH> sleep(). Is a daemon, thus a system-dependant solution, the best way
AH> to go or is it unconnected with such a task?
You can choose a event library from existing ones or write your own
implementation. They allow waiting for multiple events, organizing timer
lists, etc.
-netch-
Valentin Nechayev Guest
-
Nate Hill #5
Re: infinite loops -- waiting for some event
Andrej Hocevar wrote:
While unrelated I have to point out that the only real solutions to infinite> Hello,
> what is the best way of solving cases where one has to wait
> (forever, until killed or instructed otherwise) for some event to
> occur? E.g., wait for data, monitoring a file? In fact, that task is
> not that difficult, but takes over the CPU if the infinite loop
> lacks sleep(). I've always thought using this method was somehow
> inferior but then found out that even utilities like tail(1) (on
> Linux) use it. Or on another occasion, if one uses curses (UNIX
> again), which will most likely include an infinite loop, with the
> nodelay(...) option turned on. Obviously, there must be a solution to
> such cases: with nodelay() turned off, the infinite loop doesn't need
> sleep(). Is a daemon, thus a system-dependant solution, the best way
> to go or is it unconnected with such a task?
loops must be done in kernel-land. Any feature that "blocks" is either
driven itself by an infinite loop or is a kernel feature. Of course, these
things are trivial in kernel space. For instance, most filesystem layers
implement some kind of queue for files being monitored and since they are
the ultimate authority on a files state they only need to notify these
monitors when the file changes.
--
Nate Hill <vugdeox@freeshell.org>
Nate Hill Guest



Reply With Quote

