Professional Web Applications Themes

asdf - UNIX Programming

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, which will most likely include an infinite loop, with the nodelay(...) option turned on. Obviously, there must be a ...

  1. #1

    Default asdf

    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, 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

  2. #2

    Default Re: asdf

    Andrej Hocevar wrote:
    >
    > 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, 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
    What you have to decide is: what is the appropriate response time
    for the event that you are monitoring. If one second is sufficient,
    then
    polling the event once a second, and sleeping in between polls is all
    that is necessary. Sleep yields the CPU to other processes. There are
    other methods such as select(), sigpause(), and wait() that allow you
    to yield the CPU pending specific types of events.

    --
    Fletcher Glenn
    email [email]f-g-l-e-n-nquest.com[/email] (remove the dashes)
    Fletcher Glenn Guest

  3. #3

    Default Re: asdf

    On Tue, 15 Jul 2003 13:46:41 GMT
    Andrej Hocevar <ahsiol.net> wrote:
    > 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, 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
    I would use libevent.
    [url]http://www.monkey.org/~provos/libevent/[/url]

    - David

    David Hill Guest

  4. #4

    Default Re: asdf

    Andrej Hocevar wrote:
    > 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?
    The way that meets your requirements and best conserves limited system
    resources like CPU cycles.

    BTW, you'll probably get more responses if your posts have a subject
    that indicates the poster is out of pre-school.

    -- ced
    > 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, 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
    >
    >


    --
    Chuck Dillon
    Senior Software Engineer
    NimbleGen Systems Inc.

    Chuck Dillon Guest

  5. #5

    Default asdf

    hello


    geeta Guest

  6. #6

    Default Re: asdf

    please test in the testing newsgroup

    --
    Regards,
    Alvin Bruney [MVP ASP.NET]

    [Shameless Author plug]
    The Microsoft Office Web Components Black Book with .NET
    Now Available [url]www.lulu.com/owc[/url]
    Forth-coming VSTO.NET - Wrox/Wiley 2006
    -------------------------------------------------------



    "geeta" <geetapatilcodetheatre.com> wrote in message
    news:OjJ2JGr2FHA.3272TK2MSFTNGP09.phx.gbl...
    > hello
    >
    >

    Alvin Bruney - ASP.NET MVP Guest

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139