# # LECA Bash library # # The LECA bash library provides a set of function used for helping # development of bash script mainly to write job script on the luke # cluster # # The files from the LECA Bash library must be sourced from your main script # include logging logdebug "Load timeout package" function timeoutcmd() { local seconde=$1 shift $* & local mainpid=$! sleep $seconde & local sleeppid=$! local nproc=$(ps $mainpid $sleeppid | tail -n +2 | wc -l) while (( nproc > 1 )) ; do sleep 1 nproc=$(ps $mainpid $sleeppid | tail -n +2 | wc -l) done local timealive=$(ps $sleeppid | tail -n +2 | wc -l) if (( timealive > 0 )) ; then kill -9 $sleeppid else if (( $(ps $mainpid | tail -n +2 | wc -l) > 0 )) ; then echo killed kill -9 $mainpid # logwarning "Timeout after ${seconde}s on command : $*" fi fi }