Is there a way to set the pipe capacity of pipes defined in a Bash (or other shell) script? Take e.g.
cmd1 | cmd2
In recent Linuxes the pipe capacity is set to 64KB by default. I know I can control the amount of data "buffered" between the two processes in two ways:
- Using
buffer(1)
: e.g.cmd1 | buffer | cmd2
- Using
fcntl(2)
with theF_SETPIPE_SZ
flag from insidecmd1
orcmd2
Each solution has downsides: buffer
can only be used to increase the buffer; also writes over the default pipe capacity will still require waking up the downstream command. fcntl
, as far as I know, can only be called from inside cmd1
or cmd2
.
My question is: is there a way, when the shell creates the pipe, to specify in the shell how much capacity the pipe should have?