I have a command inside my bash script that could start infinite execution. And when it will happen I'd like to terminate the proccess of that command and continue script execution.
I've googled and tried to find duplicate answer - no result:(
"myProgram" is a C language simple program inside bash script that prints "*" to "stars.txt" file.
It's compiled with command gcc myProgram .cpp -o myProgram
.
"myProgram" can start infinite execution and I'd like to terminate it when it happens.
...
./myProgram 2>> log.txt > stars.txt
...
Please help me with solution or point me to material that will help to get an answer. If you need any additional information, please ask for it, I'll answer as soon as possible:)
You can use the timeout
shell command to exit the command and start executing the next lines in case the command takes more time than the time specified in the timeout value.
...
timeout 100 ./myProgram 2>> log.txt > stars.txt
...
In the above program your ./myProgram
will exit if it takes more than 100 seconds.