I'm trying to make a program that does the following:
./run cmd1 arg1 : cmd2 arg2 : cmd3 arg3
allows me to run three commands for example in parallel using fork()
and execvp
and connecting the output of the cmd 1 to the input of the cmd 2 using socketpair
only.
My question is:
do i need to create multiple socketpairs for each command that i use or i can use the same socketpair, i just use it again and again ?
Thanks
You should create a separate socket-pair for each parent-and-child communications-link you need to use.
For example, your program might be structured something like this:
Note that in the above sample, Process #2 can't re-use socket B to communicate with Process #3, since it needs socket B to communicate with Process #1. Process #2 can't use socket A for anything, since socket A is reserved for Process #1 to use (if Process #2 tried to use it socket A, Process #2 would just be sending bytes to itself on socket B, which isn't a useful thing to do)