bug-gawk
[Top][All Lists]
Advanced

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

How to get gawk to timeout when reading a file.


From: David Niklas
Subject: How to get gawk to timeout when reading a file.
Date: Thu, 9 Mar 2023 14:33:26 -0500

Hello,
I have a process that needs to be run based on input that will be read by
gawk. While the process runs, input will accumulate that cannot be read
because the other process is being run by system. Even if I could read
the accumulated input while running a process with system I would discard
it. Therefore, I'd like gawk to quickly read the accumulated input and
discard it all.
The problem is that gawk doesn't seem to enter non-blocking mode when I
set it. I tried lowering it to 1 millisecond from 1 second without effect.
Here's a minimalistic code sample which correctly reproduces the problem:

#!/usr/bin/gawk -f 

BEGIN{
    # Polling read...
    PROCINFO[Service, "READ_TIMEOUT"] = 1000;
    PROCINFO["input", "RETRY"] = 1; 

    system("sleep 1s; echo Run process using system.");

    do
    {
        ret = getline < "../fifo";
        # Quickly eat the rest of the input which could
        # not be read due to the other process running.
    }
    while(ret == 1);
}

As you can see, I'm reading from a FIFO. The process on the other end
sends data once per second. It is:
sudo /usr/sbin/iftop -tB | stdbuf -oL grep 'Total receive rate:' > fifo

If you can get the code sample to work correctly, then the program will
exit while the process feeding the fifo is still running.

Thanks,
David



reply via email to

[Prev in Thread] Current Thread [Next in Thread]