CN104090817A - Processing method for linux shell script parallel execution and timeout automatic exit - Google Patents
Processing method for linux shell script parallel execution and timeout automatic exit Download PDFInfo
- Publication number
- CN104090817A CN104090817A CN201410334993.6A CN201410334993A CN104090817A CN 104090817 A CN104090817 A CN 104090817A CN 201410334993 A CN201410334993 A CN 201410334993A CN 104090817 A CN104090817 A CN 104090817A
- Authority
- CN
- China
- Prior art keywords
- parallel
- timeout
- echo
- subroutine
- subprograms
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Landscapes
- Management, Administration, Business Operations System, And Electronic Commerce (AREA)
Abstract
Description
技术领域 technical field
本发明涉及Linux技术领域,具体涉及一种linux shell脚本并行执行与超时自动退出的处理方法。 The invention relates to the technical field of Linux, in particular to a processing method for parallel execution and timeout automatic exit of a Linux shell script. the
技术背景 technical background
一般linux shell并行脚本将需要并行的命令程序并行启动后,再循环判断每个并行的命令程序是否超时,这样的并行程序效率低;如果启动的并行命令程序里面又启动了子命令程序,会有残留的子命令超时没有杀死的情况,给系统造成负担。 Generally, the linux shell parallel script will require parallel command programs to be started in parallel, and then recycle to determine whether each parallel command program times out. Such parallel programs are inefficient; The remaining subcommands are timed out and not killed, causing a burden to the system. the
发明内容 Contents of the invention
本发明要解决的技术问题是:一种linux shell脚本并行与超时自动退出的处理方法,它具有并行效率高和超时自动将执行的所有命令程序杀死的优点。 The technical problem to be solved by the present invention is: a processing method for parallel and timeout automatic exit of linux shell scripts, which has the advantages of high parallel efficiency and automatic killing of all executed command programs when timeout occurs. the
本发明所采用的技术方案为: The technical scheme adopted in the present invention is:
一种linux shell脚本并行执行与超时自动退出的处理方法,所述方法包括主程序和子程序,首先运行主程序,并行启动子程序,然后等待所有并行的子程序结束;其中,子程序执行命令程序并处理命令程序得到的结果,如果命令程序在规定时间内还没有完成,子程序先将未完成的命令程序杀死,再将自身杀死。 A processing method for linux shell script parallel execution and timeout automatic exit, said method includes a main program and a subroutine, first runs the main program, starts the subroutines in parallel, and then waits for the end of all parallel subroutines; wherein, the subroutine executes the command program And process the result obtained by the command program, if the command program has not been completed within the specified time, the subroutine will first kill the unfinished command program, and then kill itself.
所述主程序代码为: The main program code is:
#!/bin/bash #!/bin/bash
nodeList="node1 node2 node3 node4 node5 node6 node7 node8 node9" nodeList="node1 node2 node3 node4 node5 node6 node7 node8 node9"
date >./nodeInfo.txt date >./nodeInfo.txt
timeout=5 timeout=5
number=0 number=0
count=0 count=0
echo "parallel start" echo "parallel start"
for i in $nodeList for i in $nodeList
do do
sub_proc.sh $i $timeout & sub_proc.sh $i $timeout &
done done
echo "parent is waiting......" echo "parent is waiting..."
wait wait
echo "parallel end" 。 echo "parallel end" .
所述子程序代码为: The subroutine code is:
#!/bin/bash #!/bin/bash
if [ $# -lt 2 ] if [ $# -lt 2 ]
then then
echo "please input 2 parameter!" echo "please input 2 parameters!"
exit exit
fi the fi
timeout=`expr $2 \* 1000` timeout=`expr $2 \* 1000`
{ {
#result=$(cat /proc/meminfo 2>&1 | grep "MemFree:") #result=$(cat /proc/meminfo 2>&1 | grep "MemFree:")
result=$(ipmitool -I lan -H 192.168.11.10 -U admin -P admin power status 2>&1 | grep "Chassis Power") result=$(ipmitool -I lan -H 192.168.11.10 -U admin -P admin power status 2>&1 | grep "Chassis Power")
if [ -z "$result" ] if [ -z "$result" ]
then then
echo $$,$1,"error" >>./nodeInfo.txt echo $$,$1,"error" >>./nodeInfo.txt
else else
echo $$,$1,$result >>./nodeInfo.txt echo $$,$1,$result >>./nodeInfo.txt
fi fi
}& }&
echo "usleeping..." echo "usleeping..."
usleep $timeout usleep $timeout
echo "wake up..." echo "wake up..."
date date
tmp=`pstree -p $$ 2>>/dev/null | sed -n 's/.*ipmitool(\([0-9]*\))/\1/p'` tmp=`pstree -p $$ 2>>/dev/null | sed -n 's/.*ipmitool(\([0-9]*\))/\1/p'`
if [ "$tmp" != "" ] if [ "$tmp" != "" ]
then then
kill -9 $tmp kill -9 $tmp
echo $$,$1,"timeout" >>./nodeInfo.txt echo $$,$1,"timeout" >>./nodeInfo.txt
fi the fi
wait 。 wait.
本发明的有益效果为:本发明并行效率高并且具有超时自杀的功能,主程序不需要去判断并行子程序是否超时,所以并行效率高;在超时子程序未完成的情况下,子程序具有自动杀死自己执行的命令和自己本身,不给系统造成超时等待的多余进程。 The beneficial effect of the present invention is: the parallel efficiency of the present invention is high and has the function of overtime suicide, and the main program does not need to judge whether the parallel subroutine has timed out, so the parallel efficiency is high; Kill the commands executed by itself and itself, without causing redundant processes waiting for timeout to the system. the
附图说明 Description of drawings
图1为本发明主程序流程图; Fig. 1 is the main program flowchart of the present invention;
图2为本发明子程序流程图。 Fig. 2 is a subroutine flow chart of the present invention.
具体实施方式 Detailed ways
下面参照附图,通过具体实施方式对本发明进一步说明: Below with reference to accompanying drawing, the present invention is further described by specific embodiment:
main_proc.sh,一种linux shell脚本并行与超时自动退出的处理方法的主程序,它包括: main_proc.sh, the main program of a linux shell script parallelism and timeout automatic exit processing method, it includes:
1) 并行启动子程序sub_proc.sh,通过一个for循环启动了9个并行子程序,关键代码如下: 1) Start the subroutine sub_proc.sh in parallel, start 9 parallel subroutines through a for loop, the key code is as follows:
for i in $nodeList for i in $nodeList
do do
sub_proc.sh $i $timeout & sub_proc.sh $i $timeout &
done done
2) 等待子程序结束,通过wait等待子程序结束 ,主程序不需要判断子程序是否超时,子程序自己判断,来提高并行执行的效率,如果主程序判断子程序是否超时需要串行九次,而如果让子程序并行判断自己是否超时,只需要一次。 2) Wait for the end of the subroutine, wait for the end of the subroutine through wait, the main program does not need to judge whether the subroutine has timed out, the subroutine judges by itself to improve the efficiency of parallel execution, if the main program judges whether the subroutine is timed out, it needs to be serialized nine times, And if the subroutines are allowed to judge whether they time out in parallel, only one time is required.
sub_proc.sh,一种linux shell脚本并行与超时自动退出的处理方法的子程序,它包括: sub_proc.sh, a subroutine of a linux shell script parallelism and timeout automatic exit processing method, which includes:
1) 执行命令程序并处理命令程序得到的结果,关键代码如下: 1) Execute the command program and process the results obtained by the command program. The key codes are as follows:
{ {
#result=$(cat /proc/meminfo 2>&1 | grep "MemFree:") #result=$(cat /proc/meminfo 2>&1 | grep "MemFree:")
result=$(ipmitool -I lan -H 192.168.11.10 -U admin -P admin power status 2>&1 | grep "Chassis Power") result=$(ipmitool -I lan -H 192.168.11.10 -U admin -P admin power status 2>&1 | grep "Chassis Power")
if [ -z "$result" ] if [ -z "$result" ]
then then
echo $$,$1,"error" >>./nodeInfo.txt echo $$,$1,"error" >>./nodeInfo.txt
else else
echo $$,$1,$result >>./nodeInfo.txt echo $$,$1,$result >>./nodeInfo.txt
fi fi
}& }&
2) 如果执行的命令程序超时,那么将其杀死,关键代码如下: 2) If the executed command program times out, kill it. The key code is as follows:
tmp=`pstree -p $$ 2>>/dev/null | sed -n 's/.*ipmitool(\([0-9]*\))/\1/p'` tmp=`pstree -p $$ 2>>/dev/null | sed -n 's/.*ipmitool(\([0-9]*\))/\1/p'`
if [ "$tmp" != "" ] if [ "$tmp" != "" ]
then then
kill -9 $tmp kill -9 $tmp
echo $$,$1,"timeout" >>./nodeInfo.txt echo $$,$1,"timeout" >>./nodeInfo.txt
fi。 fi.
Claims (3)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201410334993.6A CN104090817A (en) | 2014-07-15 | 2014-07-15 | Processing method for linux shell script parallel execution and timeout automatic exit |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201410334993.6A CN104090817A (en) | 2014-07-15 | 2014-07-15 | Processing method for linux shell script parallel execution and timeout automatic exit |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN104090817A true CN104090817A (en) | 2014-10-08 |
Family
ID=51638536
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201410334993.6A Pending CN104090817A (en) | 2014-07-15 | 2014-07-15 | Processing method for linux shell script parallel execution and timeout automatic exit |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN104090817A (en) |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN104978006A (en) * | 2015-05-19 | 2015-10-14 | 中国科学院信息工程研究所 | Low power consumption idle waiting method in multi-threaded mode |
Citations (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| EP1341083A2 (en) * | 2002-02-28 | 2003-09-03 | Fujitsu Limited | Parallel-process execution method and multiprocessor-type computer |
| CN102768637A (en) * | 2011-05-05 | 2012-11-07 | 阿里巴巴集团控股有限公司 | Method and device for controlling test execution |
| US20130074080A1 (en) * | 2011-09-16 | 2013-03-21 | Skype Limited | Timed Iterator |
| CN102999387A (en) * | 2012-11-09 | 2013-03-27 | 北京奇虎科技有限公司 | Process running device and method |
| CN103593293A (en) * | 2013-11-22 | 2014-02-19 | 浪潮电子信息产业股份有限公司 | Parallel automated testing method |
| CN103744675A (en) * | 2014-01-06 | 2014-04-23 | 浪潮(北京)电子信息产业有限公司 | Engine and method for executing scripts and commands based on Linux pipeline technology |
-
2014
- 2014-07-15 CN CN201410334993.6A patent/CN104090817A/en active Pending
Patent Citations (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| EP1341083A2 (en) * | 2002-02-28 | 2003-09-03 | Fujitsu Limited | Parallel-process execution method and multiprocessor-type computer |
| CN102768637A (en) * | 2011-05-05 | 2012-11-07 | 阿里巴巴集团控股有限公司 | Method and device for controlling test execution |
| US20130074080A1 (en) * | 2011-09-16 | 2013-03-21 | Skype Limited | Timed Iterator |
| CN102999387A (en) * | 2012-11-09 | 2013-03-27 | 北京奇虎科技有限公司 | Process running device and method |
| CN103593293A (en) * | 2013-11-22 | 2014-02-19 | 浪潮电子信息产业股份有限公司 | Parallel automated testing method |
| CN103744675A (en) * | 2014-01-06 | 2014-04-23 | 浪潮(北京)电子信息产业有限公司 | Engine and method for executing scripts and commands based on Linux pipeline technology |
Cited By (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN104978006A (en) * | 2015-05-19 | 2015-10-14 | 中国科学院信息工程研究所 | Low power consumption idle waiting method in multi-threaded mode |
| CN104978006B (en) * | 2015-05-19 | 2018-04-27 | 中国科学院信息工程研究所 | A kind of low power idle under multithread mode waits method |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| JP6761878B2 (en) | Controlling the tasks performed by the computing system | |
| JP2014515885A5 (en) | ||
| JP2013545169A5 (en) | ||
| US9477579B2 (en) | Embedded software debug system with partial hardware acceleration | |
| CN104714838A (en) | Task scheduling method and device | |
| RU2016144804A (en) | ROBOT TRACKING | |
| CN102937904A (en) | Multi-node firmware updating method and device | |
| CN108241496A (en) | Smooth upgrade method and device for application programs | |
| WO2013029513A1 (en) | Method and system, scheduler for parallel simulating processors | |
| RU2014151740A (en) | AUTO UPDATE WITH ACKNOWLEDGE DURING CUSTOMER INTERFACE OPERATION | |
| WO2018010381A1 (en) | Multi-target elevator group control system and method | |
| CN111078265B (en) | Web project update patch generation method based on jenkins | |
| US20040268335A1 (en) | Modulo scheduling of multiple instruction chains | |
| CN104090817A (en) | Processing method for linux shell script parallel execution and timeout automatic exit | |
| CN106030539A (en) | Software-installed apparatus, and software updating method | |
| CN109947015B (en) | Task execution method and main controller | |
| CN105912416B (en) | A kind of method and terminal monitoring processor in the terminal | |
| CN104597832A (en) | PLC program scheduler IP core based on AMBA bus | |
| CN111177232A (en) | A data processing method, device, system and storage medium | |
| CN109002318A (en) | A kind of firmware update of CPLD, device, equipment and medium | |
| TWI690849B (en) | Method and device for upgrading and closing applications | |
| CN106161107A (en) | Multimachine intelligent service deployment system and method | |
| CN112084014A (en) | A data processing method, device, equipment and medium | |
| CN104683463B (en) | A control method and device for an application server and a server system | |
| CN114637557B (en) | A script service-oriented approach based on heterogeneous operating systems |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| C06 | Publication | ||
| PB01 | Publication | ||
| C10 | Entry into substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| RJ01 | Rejection of invention patent application after publication |
Application publication date: 20141008 |
|
| RJ01 | Rejection of invention patent application after publication |