|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
如果您觉得本篇CentOSLinux教程讲得好,请记得点击右边漂浮的分享程序,把好文章分享给你的小伙伴们!即好比我有100个可实行文件,相互间没有出格的前后实行干系,如
CODE:
job_1
job_2
job_2
.....
job_100想用csh/bash来多线程挪用实行
好比一次开5个线程,那末job_1,2,3,4,5一同先入手下手,那末个中任何一个线程假如先实行完成,则持续实行下一个没有初实行过的文件,如job_6,7,8....,如许一向以所指定的线程数来实行一切100个文件。
我原本想用"&"来放进背景,但是如许我一次能够指定5放进背景,可是没法晓得个中任何一个步伐什么时候实行终了,以是也没法持续实行下一个步伐啊!
完善办理计划
- -(dearvoid@LinuxEden:Forum)-(~/tmp)-[$$=6718$?=0];catjob_1#!/bin/bashn=$((RANDOM%5+1))echo"$0sleepingfor$nseconds..."sleep$necho"$0exiting..."-(dearvoid@LinuxEden:Forum)-(~/tmp)-[$$=6718$?=0];for((i=2;i<=10;++i));docpjob_1job_$i;done-(dearvoid@LinuxEden:Forum)-(~/tmp)-[$$=6718$?=0];catjobs.sh#!/bin/bashnParellel=5nJobs=10sJobPattern=./job_%daJobs=()sNextJob=for((iNextJob=1;iNextJob<=nJobs;));dofor((iJob=0;iJob<nParellel;++iJob));doif[$iNextJob-gt$nJobs];thenbreak;fiif[!"${aJobs[iJob]}"]||!kill-0${aJobs[iJob]}2>/dev/null;thenprintf-vsNextJob"$sJobPattern"$((iNextJob++))echo"$sNextJobstarting..."$sNextJob&aJobs[iJob]=$!fidonesleep.1donewait-(dearvoid@LinuxEden:Forum)-(~/tmp)-[$$=6718$?=0];./jobs.sh./job_1starting..../job_1sleepingfor3seconds..../job_2starting..../job_2sleepingfor2seconds..../job_3starting..../job_3sleepingfor5seconds..../job_4starting..../job_5starting..../job_4sleepingfor4seconds..../job_5sleepingfor2seconds..../job_2exiting..../job_6starting..../job_6sleepingfor2seconds..../job_5exiting..../job_7starting..../job_7sleepingfor1seconds..../job_1exiting..../job_8starting..../job_8sleepingfor3seconds..../job_7exiting..../job_9starting..../job_9sleepingfor5seconds..../job_4exiting..../job_6exiting..../job_10starting..../job_10sleepingfor5seconds..../job_3exiting..../job_8exiting..../job_9exiting..../job_10exiting...-(dearvoid@LinuxEden:Forum)-(~/tmp)-[$$=6718$?=0];bye
复制代码
如果您觉得本篇CentOSLinux教程讲得好,请记得点击右边漂浮的分享程序,把好文章分享给你的好朋友们! |
|