Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am starting following command from a bash script (arguments omitted for simplicity)
avconv | sox | nc
I am starting about 150 such commands on the same box at the same time.
The last nc command sends the stream to another host. When that host dies, nc dies but avconv and sox can stay alive. I don't know exactly why there is no sigpipe to kill the whole chain. Maybe the system is highly contended and all buffers are full and waiting for some reason? How can I set up this pipe chain so that all processes terminate if any of the 3 processes terminate?
that should be done "automatically", so I would say you do not need to do anything.
From the other hand I think (so it is my own opinion) if you start 150 chains of commands you can be confused about the result.
(just a comment, nc is not trivial, it can be netcat, nedit client or something else, I assumed it was something like netcat)
If you need more help you need to give more information (like what's happened on the other side).
The problem is that it does not happen automatically. I'm not sure no data is being written or there is another issue, but when the target host goes down, I see 0 instances of nc (netcat) and lots and lots of instance of avconv and sox left. They don't die until I do a killall.
My problem is that my re-try mechanism does not work when the target host goes down because only nc terminates, but the other processes don't. Therefore, the parent process stays alive and there is no re-start.
Are those processes actively writing anything to their output pipes? Each process must discover its own broken pipe (the pipes are entirely separate), but a broken pipe is only discovered when a process attempts to write to that pipe.
They should be, but even if they don't, I would like them to close. Is there a way to bind the lifetimes of these processes together so that they exit together without strings attached?
in that case I think you can reproduce that problem easily, you only need to "cut the wire". I do not know how was nc configured, but actually nc should catch the event (something like connection lost) and you can also handle it:
Code:
set -e
set -o pipefail
# call them in a subshell
avconv | sox | nc
# check "$PIPESTATUS[@]"
if returncode != 0 kill all of the child processes
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.