A
Andrej Hocevar
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
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