Sample Header Ad - 728x90

how do I prevent script continuation when the process run queue is full?

0 votes
2 answers
79 views
Environment: shell is BusyBox bash 3.2 running in what started-out as Ubuntu Server many years ago, but has since been tweaked a great deal by the manufacturer of this particular box to become a custom embedded OS. I've encountered a problem that appears to be related to process queuing. I'm hoping someone can advise if there's a better solution that the one described below. I have a bash script that launches several daemons consecutively and in the foreground (no background launches and job control is disabled). After each launch, I grab the returncode $? and check it to ensure there were no issues. Towards the end of this list, (at somewhat random times) launch commands are run, and the following command runs immediately afterward (as if I had just launched the previous one in the background with &). After some investigation, it seems the daemon launching command was received, and is queued. The process state will either be sleeping or runnable (and eventually running). **I need my script to wait for each launch to complete before continuing.** After locating the process ID by grepping ps, I tried wait $pid but this failed to do-so. The usual $! is empty. I've now constructed a loop that watches for the launch process ID directory in /proc to disappear. When it does, it's safe to assume the launch process completed. Is there a way to force my script to wait for each command to finish before proceeding? Has anyone encountered this behaviour before?
Asked by OneCheapDrunk (43 rep)
Jun 7, 2025, 08:30 AM
Last activity: Jun 15, 2025, 05:01 AM