Is it possible to have multiple concurrent coprocesses?
7
votes
2
answers
2354
views
The *intent* of the test script1 below is to start an "outer" coprocess (running
seq 3
), read from this coprocess in a while
-loop, and for each line read, print a line identifying the current iteration of the outer loop, start an "inner" coprocess (also running seq
, with new arguments), read from this inner coprocess in a nested while loop, and then clean up this inner coprocess. The nested while loop prints some output for each line it reads from the inner coprocess.
#!/bin/bash
# filename: coproctest.sh
PATH=/bin:/usr/bin
coproc OUTER { seq 3; }
SAVED_OUTER_PID="${OUTER_PID}"
exec {OUTER_READER}1 I've only recently started to work with coprocesses, and there is still a lot I don't understand. As a result, this script almost certainly contains incorrect, awkward, or unnecessary code. Please feel free to comment on and/or fix these weaknesses in your responses.
Asked by kjo
(16299 rep)
Jul 20, 2019, 04:16 PM
Last activity: Jul 22, 2019, 03:28 PM
Last activity: Jul 22, 2019, 03:28 PM