bash - Why doesn't script call the cleanup and kill the script after 5s, and I also want to get where it stoppped -


the script designed kill after 5s. doesn't kill script after 5s, , not call cleanup. important thing want value of i when stopped.

#!/bin/sh trap "cleanup" term  #call cleanup when recive term mainpid=$$ #script's pid  cleanup() {     echo "cleaup called"     echo "i=$i when stopped "     exit 1 }   (sleep 5 && echo "timeout";kill -term $mainpid) &  #after 5s should kill script  run_test() {  i=1 sleep 100 i=$$(i+1)   }  run_test 2>&1 > x.log  

because parent processes waiting sleep 100 ends "processing". if want process ends before sleep ends, should kill him too.

something like

(sleep 5 && echo "timeout";kill -term `ps -ef | grep $mainpid | grep sleep |  grep -v grep| awk '{print $2}'` $mainpid) & 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -