0

I need to stop execution of a running java script in terminal and start the same execution at every x interval of time in terminal. Is it possible?

1

Yes, /usr/bin/timeout is the tool to use. See man timeout. Here is an example, from one of my nightly cron jobs, you can wrap yours in a while true ; do loop:

TO_KILL="45m"           # timeout (kill -KILL) for hpodder
TO_HUP="42m"            # timeout (kill -HUP) for hpodder. Makes sense only if it is less than $TO_KILL
# ...
timeout -k $TO_KILL -s HUP $TO_HUP hpodder  update

This will run the hpodder update until it finishes, or 42 minutes have passed, when it will be sent (see man 7 signal) a HUP signal. If hpodder update is still running after 45 minutes (3 minutes after the HUP was sent), it will be sent the uncatchable KILL signal, and will be terminated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.