coproc is a shell keyword related to coprocesses in GNU Bash

ABOUT coproc

Bash 4.0 introduced coprocesses, a feature certainly familiar to ksh users. The coproc keyword starts a command as a background job, setting up pipes connected to both its stdin and stdout so that you can interact with it bidirectionally. Optionally, the co-process can have a name NAME. If NAME is given, the command that follows must be a compound command. If no NAME is given, then the command can be either simple or compound.

The process ID of the shell spawned to execute the coprocess is available through the value of the variable named by NAME followed by a _PID suffix. For example, the variable name used to store the PID of a coproc started with no NAME given would be COPROC_PID (because COPROC is the default NAME). The wait builtin command may be used to wait for the coprocess to terminate. Additionally, coprocesses may be manipulated through their jobspec

[bash]
$coproc ls
[1] 4620
$coproc ls
bash: warning: execute_coproc: coproc [4620:COPROC] still exists
[2] 4621
[1] Done coproc COPROC ls
$coproc top
bash: warning: execute_coproc: coproc [4621:COPROC] still exists
[3] 4622
[2] Done coproc COPROC ls
$top: failed tty get

[3]+ Exit 1 coproc COPROC top
$coproc date
[1] 4624
$coproc arch
bash: warning: execute_coproc: coproc [4624:COPROC] still exists
[2] 4625
[1] Done coproc COPROC date
$coproc arch
bash: warning: execute_coproc: coproc [4625:COPROC] still exists
[3] 4628
[2] Done coproc COPROC arch
$fg 1
bash: fg: 1: no such job
[3]+ Done coproc COPROC arch
$
[/bash]
LINKS
https://wiki-dev.bash-hackers.org/syntax/keywords/coproc
http://blog.amit-agarwal.co.in/2010/05/10/coproc-feature-bash/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s