[Date Prev] [Date Index] [Date Next] [Thread Prev] [Thread Index] [Thread Next]

Re: [SPAM] Re: Console taking 100% CPU

Chris Marget chris@marget.com
Tue, 14 Dec 2010 22:15:11 GMT


On Tue, Dec 14, 2010 at 4:59 PM, Chris Fowler
<cfowler@outpostsentinel.com> wrote:
> On Tue, 2010-12-14 at 16:54 -0500, Chris Marget wrote:
>> read(0, "", 8192)                       = 0
>> select(4, [0 3], [], NULL, NULL)        = 1 (in [0])
>> read(0, "", 8192)                       = 0
>> select(4, [0 3], [], NULL, NULL)        = 1 (in [0])
>> read(0, "", 8192)                       = 0
>
> select() has seen STDIN ready to be read.
> read() reads 0 bytes.  This is an EOF condition.
>
> Easy.  Fix the code so that when reading from 0 if 0 bytes are read is
> restores the terminal and exits.

I've added two lines here.  Seems to do what I need.  Am I on the right track?

static int screwy = 0;
<snip>
        /* anything from stdin? */
        if (FD_ISSET(0, &rmask)) {
            if ((nc = read(0, acMesg, sizeof(acMesg))) <= 0) {
if ( nc == 0 ) fprintf(stderr, "gotcha!\n");    // added by chris m
if ( nc == 0 ) break;                           // added by chris m
                if (screwy)
                    break;
                else {
                    FD_SET(0, &rinit);
                    continue;
                }
            }


Thanks very much!

/chris