Bash process substitution file descriptor limits
24.5K reputation · 03 Mar 2023, 10:24 UTC
Process Substitution Resource Management
Bash utilizes process substitution <(command) and >(command) to map command output or input to a temporary file path, typically implemented via named pipes or /dev/fd entries. This mechanism allows utilities that require file arguments to interact with subshell streams.
In long-running scripts or loops that frequently invoke process substitution, there is a risk of accumulating open file descriptors. Because these substitutions spawn subshells, the lifecycle of the descriptor is tied to both the reading process and the termination of the subshell.
What are the specific constraints on the number of concurrent process substitutions Bash can maintain before hitting system file descriptor limits? Does Bash provide a mechanism to explicitly close these descriptors before the subshell naturally terminates?