benzaita
benzaita

Reputation: 13419

how to create a zero-copy, no-capacity, blocking pipe in bash?

I know the concept sounds a little abusive (?), but still - how can I create a pipe in bash which:

  1. has no capacity
  2. and therefore requires no memory copy, and
  3. requires the write to be blocking

Upvotes: 0

Views: 378

Answers (1)

jim mcnamara
jim mcnamara

Reputation: 16389

I am guessing a lot here. But possibly you are thinking about coprocesses and do not know what that term means.

bash supports coprocesses: http://www.gnu.org/software/bash/manual/html_node/Coprocesses.html

    The format for a coprocess is:

    coproc [NAME] command [redirections]

    This creates a coprocess named NAME. 
If NAME is not supplied, the default name is COPROC.

NAME must not be supplied if command is a simple command (see Simple Commands); 

otherwise, it is interpreted as the first word of the simple command.

When the coproc is executed, the shell creates an array variable (see Arrays) named NAME in the context of the executing shell. The standard output of command is connected via a pipe to a file descriptor in the executing shell, and that file descriptor is assigned to NAME[0].

The standard input of command is connected via a pipe to a file descriptor in the executing shell, and that file descriptor is assigned to NAME[1].

This pipe is established before any redirections specified by the command (see Redirections).

The file descriptors can be utilized as arguments to shell commands and redirections using standard word expansions.

Upvotes: 1

Related Questions