[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-gawk] flush in the main process but not coprocess?
From: |
Peng Yu |
Subject: |
[bug-gawk] flush in the main process but not coprocess? |
Date: |
Thu, 6 Dec 2012 10:54:15 -0600 |
Hi,
I have to use fflush() in the coprocess, otherwise the program hangs.
This is documented as the following.
I/O buffering may be a problem. gawk automatically flushes all output
down the pipe to the coprocess. However, if the coprocess does not
flush its output, gawk may hang when doing a getline in order to read
the coprocess's results. This could lead to a situation known as
deadlock, where each process is waiting for the other one to do
something.
But when the coprocess was written by somebody else, and I don't have
control of, it is not an option to call flush. Is there a walk-around
to this problem?
~/linux/test/awk/lang/pipe/|&$ cat.sh main.sh main.awk
==> main.sh <==
#!/usr/bin/env bash
seq 10 | awk.sh -f main.awk
==> main.awk <==
BEGIN {
subprogram = "awk -e '{print $1 + 10; fflush()}'"
}
{
print $1 |& subprogram
subprogram |& getline result
print result
}
~/linux/test/awk/lang/pipe/|&$ ./main.sh
11
12
13
14
15
16
17
18
19
20
--
Regards,
Peng
- [bug-gawk] flush in the main process but not coprocess?,
Peng Yu <=