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 PDF

Info

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
echo
timeout
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
Application number
CN201410334993.6A
Other languages
Chinese (zh)
Inventor
焦芬芳
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Inspur Electronic Information Industry Co Ltd
Original Assignee
Inspur Electronic Information Industry Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Inspur Electronic Information Industry Co Ltd filed Critical Inspur Electronic Information Industry Co Ltd
Priority to CN201410334993.6A priority Critical patent/CN104090817A/en
Publication of CN104090817A publication Critical patent/CN104090817A/en
Pending legal-status Critical Current

Links

Landscapes

  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The invention discloses a processing method for linux shell script parallel execution and timeout automatic exit. The processing method involves a main program and subprograms, the main program is run firstly, the subprograms are started in parallel, and then waiting is kept till all the parallel subprograms are ended, wherein the subprograms execute command programs and process results obtained by the command programs, and if the command programs are not finished within the required time, the subprograms kill the unfinished command programs first and then kill themselves. The processing method is high in parallel efficiency and has the timeout suicide function; the main program does not have to judge whether the parallel subprograms are out of time, and thus the parallel efficiency is high; when the timeout subprograms are not finished, the subprograms automatically kill the commands executed by themselves and then kill themselves, and excessive timeout waiting courses will not be caused to a system.

Description

A kind of linux shell script parallel is carried out and the overtime disposal route automatically exiting
Technical field
The present invention relates to Linux technical field, be specifically related to a kind of linux shell script parallel and carry out and the overtime disposal route automatically exiting.
Technical background
The parallel script of general linux shell is by after command program parallel starting parallel needs, and recycle judges that whether each parallel command program is overtime, and such concurrent program efficiency is low; If the parallel command program starting the inside has started again subcommand program, have the overtime situation of not killing of residual subcommand, cause burden to system.
Summary of the invention
The technical problem to be solved in the present invention is: a kind of linux shell script parallel and the overtime disposal route automatically exiting, it has advantages of that parallel efficiency height and overtime automatic all command programs by execution kill.
The technical solution adopted in the present invention is:
Linux shell script parallel is carried out and the overtime disposal route automatically exiting, and described method comprises master routine and subroutine, first moves master routine, and then parallel starting subroutine waits for all parallel ends of subroutine; Wherein, the result that subroutine fill order program processing command program obtain, if command program does not also complete at the appointed time, subroutine is first killed uncompleted command program, then self is killed.
Described main program code is:
#!/bin/bash
nodeList="node1 node2 node3 node4 node5 node6 node7 node8 node9"
date >./nodeInfo.txt
timeout=5
number=0
count=0
echo "parallel start"
for i in $nodeList
do
sub_proc.sh $i $timeout &
done
echo "parent is waiting......"
wait
echo "parallel end" 。
Described subroutine code is:
#!/bin/bash
if [ $# -lt 2 ]
then
echo "please input 2 parameter!"
exit
fi
timeout=`expr $2 \* 1000`
{
#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")
if [ -z "$result" ]
then
echo $$,$1,"error" >>./nodeInfo.txt
else
echo $$,$1,$result >>./nodeInfo.txt
fi
}&
echo "usleeping..."
usleep $timeout
echo "wake up..."
date
tmp=`pstree -p $$ 2>>/dev/null | sed -n 's/.*ipmitool(\([0-9]*\))/\1/p'`
if [ "$tmp" != "" ]
then
kill -9 $tmp
echo $$,$1,"timeout" >>./nodeInfo.txt
fi
wait 。
Beneficial effect of the present invention is: parallel efficiency of the present invention is high and have the function of overtime suicide, and master routine does not need to judge that whether parallel subroutine is overtime, so parallel efficiency is high; In the uncompleted situation of overtime subroutine, subroutine has kills the order of oneself carrying out automatically with own own, does not cause the unnecessary process of waiting-timeout to system.
Brief description of the drawings
Fig. 1 is main program flow chart of the present invention;
Fig. 2 is subroutine flow chart of the present invention.
Embodiment
With reference to the accompanying drawings, by embodiment, the present invention is further described:
Main_proc.sh, the master routine of a kind of linux shell script parallel and the overtime disposal route automatically exiting, it comprises:
1) parallel starting subroutine sub_proc.sh, by a for loop start 9 parallel subroutines, key code is as follows:
for i in $nodeList
do
sub_proc.sh $i $timeout &
done
2) wait subroutine finishes, finish by wait wait subroutine, master routine does not need to judge that whether subroutine is overtime, subroutine oneself judgement, improve the efficiency of executed in parallel, if master routine judges whether subroutine overtime and needs serial nine times, and if allow subroutine is parallel judge that whether oneself overtime, only needs are once.
Sub_proc.sh, the subroutine of a kind of linux shell script parallel and the overtime disposal route automatically exiting, it comprises:
1) result that fill order program processing command program obtain, key code is as follows:
{
#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")
if [ -z "$result" ]
then
echo $$,$1,"error" >>./nodeInfo.txt
else
echo $$,$1,$result >>./nodeInfo.txt
fi
}&
2) if the command program of carrying out is overtime, killed so, key code is as follows:
tmp=`pstree -p $$ 2>>/dev/null | sed -n 's/.*ipmitool(\([0-9]*\))/\1/p'`
if [ "$tmp" != "" ]
then
kill -9 $tmp
echo $$,$1,"timeout" >>./nodeInfo.txt
fi。

Claims (3)

1. linux shell script parallel is carried out and the overtime disposal route automatically exiting, and described method comprises master routine and subroutine, it is characterized in that: first move master routine, parallel starting subroutine, then waits for all parallel ends of subroutine; Wherein, the result that subroutine fill order program processing command program obtain, if command program does not also complete at the appointed time, subroutine is first killed uncompleted command program, then self is killed.
2. a kind of linux shell script parallel according to claim 1 is carried out and the overtime disposal route automatically exiting, and it is characterized in that, described main program code is:
#!/bin/bash
nodeList="node1 node2 node3 node4 node5 node6 node7 node8 node9"
date >./nodeInfo.txt
timeout=5
number=0
count=0
echo "parallel start"
for i in $nodeList
do
sub_proc.sh $i $timeout &
done
echo "parent is waiting......"
wait
echo "parallel end" 。
3. a kind of linux shell script parallel according to claim 1 and 2 is carried out and the overtime disposal route automatically exiting, and it is characterized in that, described subroutine code is:
#!/bin/bash
if [ $# -lt 2 ]
then
echo "please input 2 parameter!"
exit
fi
timeout=`expr $2 \* 1000`
{
#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")
if [ -z "$result" ]
then
echo $$,$1,"error" >>./nodeInfo.txt
else
echo $$,$1,$result >>./nodeInfo.txt
fi
}&
echo "usleeping..."
usleep $timeout
echo "wake up..."
date
tmp=`pstree -p $$ 2>>/dev/null | sed -n 's/.*ipmitool(\([0-9]*\))/\1/p'`
if [ "$tmp" != "" ]
then
kill -9 $tmp
echo $$,$1,"timeout" >>./nodeInfo.txt
fi
wait 。
CN201410334993.6A 2014-07-15 2014-07-15 Processing method for linux shell script parallel execution and timeout automatic exit Pending CN104090817A (en)

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)

* Cited by examiner, † Cited by third party
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)

* Cited by examiner, † Cited by third party
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

Patent Citations (6)

* Cited by examiner, † Cited by third party
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)

* Cited by examiner, † Cited by third party
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
US10489191B2 (en) Controlling tasks performed by a computing system using controlled process spawning
CN108027751A (en) Efficient scheduling to multi version task
US8863131B2 (en) Transaction load reduction for process completion
RU2016144804A (en) ROBOT TRACKING
CN105204913A (en) Method and system for running Linux application on Android operating system and system
TW201732629A (en) Task processing method, apparatus and system based on distributed system
US9146713B2 (en) Tool composition for supporting openCL application software development for embedded system and method thereof
RU2014136808A (en) METHOD AND DEVICE FOR ADVANCED LOCK PASS TECHNOLOGIES
RU2015128627A (en) SYSTEMS AND METHODS FOR CREATING AND USING HYBRID MOBILE APPLICATIONS
JP2013529810A5 (en)
CN101667147A (en) Multitasking controllable automatic snapshot method
EP3032413B1 (en) Code generation method, compiler, scheduling method, apparatus and scheduling system
RU2014151740A (en) AUTO UPDATE WITH ACKNOWLEDGE DURING CUSTOMER INTERFACE OPERATION
CN109298876A (en) System and method for the firmware updating in the multiple equipment of wireless fire disaster detection system
CN104090817A (en) Processing method for linux shell script parallel execution and timeout automatic exit
JP2015503812A5 (en)
CN105912416B (en) A kind of method and terminal monitoring processor in the terminal
CN104597832A (en) PLC program scheduler IP core based on AMBA bus
CN104090747A (en) Method for optimizing Linux intelligent terminal through real-time scheduling optimizer
CN106201667B (en) User instruction queue management system and method
CN104683463B (en) The control method and device and server system of a kind of application server
CN110888640A (en) Intelligent operation and maintenance method and device based on ChatOps
CN103500084A (en) Method of service component architecture supporting software dynamic update
Fletcher et al. Evolving into embedded develop
CN109725984B (en) Method for remotely stopping executing Shell command

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