简体   繁体   中英

bash script kill command after timeout

I have bash script that work for many files in loop. It compiles, check the result etc. Now I'd like to make a security in case of infinity loop inside of one of thouse files. something like: If it's not done after 5 min. Kill the process and gave info about that.

gcc -Wall -o "${FN}_execute" ${FN} 2> ${FN}_c_compilation.txt
./${FN}_execute $PARAM > ${FN}_c_result.txt

How to do that?

You could record the start time (in seconds) and just check if the current time (in seconds) is more than 300.

But why are you writing a script to compile files manually? Doesn't make do what you want?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM