You will have questions about how you should call an external program (fork / exec / wait, how else), but this is only one part of the problem. The real problem is planning this, I suppose you do not want to run too many external programs in parallel.
Not knowing how threading works in your system, I can warn you about two problems.
An important issue is load reduction by limiting the external command / script call. You can configure a parameter that indicates how many parallel external commands should be executed at the same time. Before calling an external command, you must increase the variable, which shows the number of active external processes; if it exceeds the limit parameter, sleep () some and try again. After the process is complete, reduce this variable. (Increase and decrease must be mutually labeled.)
Another problem is that you are using an external program that controls its lifetime. You must set a timeout for each external process and kill it if it freezes for a while. There must be a "timeout" stream (or should be the main stream) that controls the others.
source share