栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在任何给定时间运行5个脚本

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在任何给定时间运行5个脚本

这个问题弹出了几次,但我找不到合适的答案。我想现在我找到了一个很好的解决方案!

不幸的

parallel
是,这不是标准发行版的一部分,但make是。它有一个开关
-j
可做并联。

man make(1) ]
:(有关make的并行执行的更多信息)

       -j [jobs], --jobs[=jobs] Specifies the number of jobs (commands) to run simultaneously. If  there  is  more than one -j option, the last one is effective. If  the -j option is given without an argument, make  will  not limit  the number of jobs that can run simultaneously.

因此,

Makefile
只要适当地解决这个问题即可。

    .PHONY: all $(PHP_DEST)    # Create an array of targets in the form of PHP1 PHP2 ... PHP90    PHP_DEST := $(addprefix PHP, $(shell seq 1 1 90))    # Default target    all: $(PHP_DEST)    # Run the proper script for each target    $(PHP_DEST): N=$(subst PHP,,$@); php path$N/some_job_$N.php

PHP#
每个呼叫创建90个目标
php path#/some_job_#.php
。如果运行
make -j5
,它将运行5个php并行实例。如果一个完成,则开始下一个。

我将重命名

Makefile
parallel.mak
,然后运行
chmod 700 parallel.mak
并添加
#!/usr/bin/make-f
到第一行。现在可以称为
./parallel.mak -j 5

甚至您可以使用更复杂的

-l
开关:

       -l [load], --load-average[=load]  Specifies  that  no new jobs (commands) should be started if there  are others jobs running and the load average is at least  load (a  floating-point number).  With no argument, removes a previous load  limit.

在这种情况下,make将根据系统的负载来决定可以启动多少个作业。

我用它测试

./parallel.mak -j-l1.0
并运行良好。相反,它首先并行启动了4个程序,
-j
而没有args意味着要尽可能多地并行运行进程。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/408955.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号