[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-bash] silly question - which is better to pipe 2 sources into one
From: |
John McKown |
Subject: |
[Help-bash] silly question - which is better to pipe 2 sources into one command |
Date: |
Mon, 30 Apr 2018 09:10:41 -0500 |
This really is probably a stupid question. Or maybe a "self evident" one.
But I'll ask anyway. I need to feed the output of two programs into another
program. I have thought of two ways to do it. I am not really sure which is
"best". Or maybe it is a toss up.
Way one: { pgm1; pgm2; } | pgm3
Way two: cat <(pgm1) <(pgm2) | pgm3
Way one _seems_ better to me mainly because there are fewer processes
running. Basically pgm1 runs and feeds its stdout into pgm3; then pgm2 runs
and pgm3 continues to get input but from pgm2's stdout. I'm fairly sure
that this executes pgm1 & pgm3 concurrently followed with pgm2 taking
pgm1's "place" while pgm3 continues running - so 2 user processes.
But I'm wondering a bit about way two. I don't know really how that is
working. I think that "pgm1" and "pgm2" are both fork()'d & exec()'d to run
concurrently. But I imagine that there is some sort of "buffer" involved
with their stdout so that pgm2 will block after a while because the "cat"
will not start reading it until it has read all of the output from pgm1.
Anyway, all (kindly worded) thoughts are appreciated.
--
We all have skeletons in our closet.
Mine are so old, they have osteoporosis.
Maranatha! <><
John McKown
- [Help-bash] silly question - which is better to pipe 2 sources into one command,
John McKown <=