I'm working on a Docker container where I need to run multiple native binaries using named coprocesses. In my project, I have a script called `project.sh` that defines my project and an array of mock programs like this: `declare -r PROJECT='widget'` and `declare -ra MOCKS=(gadget what-sit)`. I run another script `session.sh`, which sources `project.sh`, and I loop through the `MOCKS` array to create coprocesses for each mock. The first one works fine, but when I try to run the second, `what-sit`, I encounter issues with file descriptors not being created correctly. I'm using a substitution to replace punctuation in names, but for some reason, the `what_sit` coprocess doesn't seem to initialize correctly. I get warnings about existing coprocesses and can't access its file descriptors at all, which I need to manage them properly. Can anyone help me figure out what's going wrong?
3 Answers
It sounds like your `session.sh` script is getting confused with the existing coprocess when trying to create a new one. One thing to check is whether the first coprocess is still running. If it is, sometimes the shell might throw a fit about creating another. You might want to see if you can set things up to ensure that the first coprocess exits before you try to create the second one. If that's not the issue, consider simplifying the script to isolate what's causing the problem and testing each coprocess creation step by step.
That's a good idea! Isolating your code can often reveal hidden bugs.
Actually, you can have multiple coprocesses; it's just about managing them correctly. Make sure your naming substitutions are accurate, and perhaps add some debug prints to track the state and existence of your coprocesses right before you invoke them. If you're running into file descriptor issues, ensure that the names generated are being registered properly in your environment.
What do you mean by managing them? Do I need to prioritize which ones run?
Exactly! Keeping track of which coprocesses are active might help avoid conflicts.
You should definitely try creating a Minimal, Complete, and Verifiable Example (MCVE). This way, you can confirm that the code consistently produces the same errors in a fresh environment. Check for any typos, especially where you assign variables, as those can trip you up, too. Keep everything neat to ensure you're referencing the right names throughout your scripts.
Good advice about the MCVE! I often find that helps clear up issues I thought were bigger than they are.
That makes sense! Maybe I should add some verification before looping through the mock array.