Say we have a simple pipeline:
a | b
say, a
exits – is there a surefire way to keep b
alive for an arbitrary amount of time (to complete a task etc).
bashpipeshell
Say we have a simple pipeline:
a | b
say, a
exits – is there a surefire way to keep b
alive for an arbitrary amount of time (to complete a task etc).
Best Answer
b
would not be terminated bya
terminating.Here,
a
(theecho hello
) would simply output a string and terminate. The right hand side of the pipe (b
) would read the string, output it, sleep for a while, and then do its finalecho
before terminating.If
b
was terminated whena
was, it would never have time to do what it needed to do. The only thingb
can't do here is to read more data from its standard input (an extraread
at the end would get end-of-file immediately).In the other scenario (not mentioned in the question), where
b
terminates beforea
,a
would receive aPIPE
signal if it tried to write to its standard output (across to the non-existingb
process) and terminate from that (by default).If it didn't try to write to the pipe,
a
would continue running until done.