So, from this code it seems that your intention is to simultaneously run an infinite number of jobs for every line in some file on your system. You do not care if any of these jobs start successfully. You do not care if any of these jobs complete successfully (or at all). You believe that you should be able to start an infinite number of jobs and all of those jobs should run as though they are the only job running on your system.
Unfortunately, I do not know of any system that will act anything at all like that. Nor, do I understand why you need an infinite loop to read lines in a file forever. Presumably your script terminates when the system kills it because it realizes you have exhausted system resources.
You say that a
while read loop performs about the same way. You are correct in noting that an infinite loop is an infinite loop, but a
while read loop would only have needed one process per line processed while your current nested loops use four processes per line processed plus 3 processes each time the file is processed. And, and a
while read loop would read your file once each time you process the file while your current code reads the entire file
n+1 times if your file contains
n lines.
If, instead of processing a single file an infinite number of times, you want to process each line in a file once; and if instead of ignoring the success or failure of all of the jobs you start, you'd like to actually log any failures that might occur during processing and not terminate your script until all lines have been processed, tell us more about your system:
- Given the expected load on your system and the number of processors available to run your script, how many simultaneous processes should your script expect to be able to run?
- What does my_job do? (If it doesn't exit with a zero exit status if it completes successfully and exit with a non-zero exit status if it does not complete successfully, rewrite it so it does! If it exits before all children it has started have completed, rewrite it so it doesn't return until all of its children have finished!)