进程调度 [英] Process Scheduling
问题描述
让我们说,我有我想作为cron作业定期运行10脚本。不过,我不希望他们都在同一时间运行。我想其中只有2同时运行。
Let's say, I have 10 scripts that I want to run regularly as cron jobs. However, I don't want all of them to run at the same time. I want only 2 of them running simultaneously.
一个解决方案,我想的是创建两个脚本,把5报表上的每个人,并把它们作为单独的crontab项。然而,解决方案看起来很即兴。
One solution that I'm thinking of is create two script, put 5 statements on each of them, and them as separate entries in the crontab. However the solution seem very adhoc.
有没有执行我上面提到的任务,现有的Unix工具?
Is there existing unix tool to perform the task I mentioned above?
推荐答案
的工作
内置可以告诉你有多少孩子进程正在运行。一些简单的shell脚本可以完成这个任务:
The jobs
builtin can tell you how many child processes are running. Some simple shell scripting can accomplish this task:
MAX_JOBS=2
launch_when_not_busy()
{
while [ $(jobs | wc -l) -ge $MAX_JOBS ]
do
# at least $MAX_JOBS are still running.
sleep 1
done
"$@" &
}
launch_when_not_busy bash job1.sh --args
launch_when_not_busy bash jobTwo.sh
launch_when_not_busy bash job_three.sh
...
wait
这篇关于进程调度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!