[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to get gawk to timeout when reading a file.
From: |
David Niklas |
Subject: |
Re: How to get gawk to timeout when reading a file. |
Date: |
Fri, 10 Mar 2023 10:22:29 -0500 |
On Thu, 9 Mar 2023 18:15:50 -0500
"Andrew J. Schorr" <aschorr@telemetry-investments.com> wrote:
> Hi,
>
> > #!/usr/bin/gawk -f
> >
> > BEGIN{
> > # Polling read...
> > PROCINFO[Service, "READ_TIMEOUT"] = 1000;
>
> What's the value of the Service variable here?
> It should be set to "../fifo", I hope.
Ah! That's what's going wrong!
I didn't know it was a variable I had to set.
I read the man page on PROCINFO["input", "RETRY"] but it mentions that
input should be a file name in the PROCINFO["input", "READ_TIMEOUT"]
section. Likewise I didn't read the top of the chapter in Effective Awk
Programming.
Which goes to show that I should read everything.
> > PROCINFO["input", "RETRY"] = 1;
>
> Shouldn't this be:
> PROCINFO["../fifo", "RETRY"] = 1;
See above.
> >
> > 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.
>
> Have you tried running strace on the gawk script to see in which call
> it's blocking?
>
> Regards,
> Andy
>
I thought strace only worked on compiled code!
Thanks again! My code works now.