Skip to content
Advertisement

How can I control the number of running processes?

I’m doing a shell script and the unknown situation occurred. I must execute a certain number of processes, lets suppose 12. But I want to limit the executions by ‘t’ each time. So if ‘t’ is 3 I would have to execute 3 processes then 3, 3 and finally 3. But I would like to do it automatically, so I need to monitore those running processes and when one of them has finished I must execute one of the remaining processes.

After some research, I have found the following command:

JavaScript

Proposed by cuonglm.

This can help to know if a process is running or not. I tried to create 12 processes and save them in 3 different variables, but it isn’t working properly.

JavaScript

Do any of you know how can I do this work?

Advertisement

Answer

That’s the improvement of your script.

ps -o pid= -p ${PID[$i]} returns PID if process exists.

num stands for the number of job finished.

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement