我的Linux服务器(Ubuntu 12.04 LTS)上有3个脚本,expA,expB和expC。 然后,我得到32个名为nctu_0,nctu_1 ..... nctu_31的输入文件。其中六个比其他的大得多,所以我为expA输入3个输入文件,为expB输入3个,为expC输入另一个。
即。 expA:运行nctu_6 nctu_13 nctu_17 ,expB:运行nctu_20 nctu_24 nctu_31 ,expC:运行其他文件
这是expB的原始脚本,expA的脚本与expB几乎相同
#!/bin/bash
PROGRAM=./Simulator
FILE_PART_PREFIX1=/home//data/pcap_partial/h1200/nctu_
RESULT_PREFIX1=/home/data/setup_exp/h1200
RECEIVER_SIZE=4096
SENDER_SIZE=4096
BETA=0.25
UPDATE=400
MARKER=20
part=20
if [ ${part} -eq 20 ];then
nohup ${PROGRAM} 1 ${FILE_PART_PREFIX1}${part}.pcap ${RECEIVER_SIZE} ${SENDER_SIZE} ${BETA} ${UPDATE} ${MARKER} ${MODE} >> ${RESULT_PREFIX1}/res_${part} 2>&1 &
fi
part=24
if [ ${part} -eq 24 ];then
nohup ${PROGRAM} 1 ${FILE_PART_PREFIX1}${part}.pcap ${RECEIVER_SIZE} ${SENDER_SIZE} ${BETA} ${UPDATE} ${MARKER} ${MODE} >> ${RESULT_PREFIX1}/res_${part} 2>&1 &
fi
part=31
if [ ${part} -eq 31 ];then
nohup ${PROGRAM} 1 ${FILE_PART_PREFIX1}${part}.pcap ${RECEIVER_SIZE} ${SENDER_SIZE} ${BETA} ${UPDATE} ${MARKER} ${MODE} >> ${RESULT_PREFIX1}/res_${part} 2>&1 &
fi
我想首先运行nctu_20,然后在nctu_24完成后运行nctu_24。在nctu_24完成后,最后运行nctu_31。
这是expC的原始脚本
#!/bin/bash
PROGRAM=./Simulator
FILE_PART_PREFIX1=/home/data/pcap_partial/h1200/nctu_
RESULT_PREFIX1=/home/data/setup_exp/h1200
RECEIVER_SIZE=4096
SENDER_SIZE=4096
BETA=0.25
UPDATE=400
MARKER=20
for (( part=0;part<32;part=part+1 ))
do
if [ ${part} -eq 6 ] || [ ${part} -eq 13 ] || [ ${part} -eq 17 ] || [ ${part} -eq 20 ] ||[ ${part} -eq 24 ] || [ ${part} -eq 31 ];then
continue
else
nohup ${PROGRAM} 1 ${FILE_PART_PREFIX1}${part}.pcap ${RECEIVER_SIZE} ${SENDER_SIZE} ${BETA} ${UPDATE} ${MARKER} ${MODE} >> ${RESULT_PREFIX1}/res_${part} 2>&1 &
fi
done
简而言之,我想同时运行expA,expB expC,并且每个人都在后台启动一个带有顺序输入文件的模拟器程序。有人能帮助我吗?
答案 0 :(得分:0)
我不确定我是否已经很清楚你需要什么,但是如果你想同时运行它们,我认为bash不能帮助你。你应该用支持线程的其他语言编写一个包装器,例如perl:
#!/usr/bin/perl
use strict;
use warnings;
use threads;
sub start_simulator {
my $simulator = shift;
system("./$simulator");
}
my $thA = threads->create('start_simulator', 'expA');
$thA->detach();
my $thB = threads->create('start_simulator', 'expB');
$thB->detach();
my $thC = threads->create('start_simulator', 'expC');
$thC->detach();
exit 0;
将此包装器添加到您拥有shell脚本的同一目录中,并使用./perl_wrapper.pl
运行它。