We send bash: silently kill the background process of the function and the timeout of the command in bash without unnecessary delay , I wrote my own script to set the timeout for the command and also disable the error message.
But I still get a "Terminated" message when my process is killed. What is wrong with my code?
#!/bin/bash silent_kill() { kill $1 2>/dev/null wait $1 2>/dev/null } timeout() { limit=$1 #timeout limit shift command=$* #command to run interval=1 #default interval between checks if the process is still alive delay=1 #default delay between SIGTERM and SIGKILL ( ((t = limit)) while ((t > 0)); do sleep $interval; #kill -0 $$ || exit 0 ((t -= interval)) done silent_kill $$ #kill -s SIGTERM $$ && kill -0 $$ || exit 0 sleep $delay #kill -s SIGKILL $$ ) &> /dev/null & exec $* } timeout 1 sleep 10
There is nothing wrong with the code that the “Terminated” message does not come from your script, but from the calling shell (the one you are running the script from).
, :
$ set +m $ bash <your timeout script>
, bash 4 . , Terminated, . . :
Terminated
$ sleep 100 & [1] 15436 $ disown -r $ kill -9 15436
help disown:
help disown
disown [-h] [-ar] [jobspec...].JOBSPEC . JOBSPEC, .-a , JOBSPEC-h JOBSPEC, SIGHUP , SIGHUP-r
disown [-h] [-ar] [jobspec...].JOBSPEC . JOBSPEC, .
, , () s , . , . .
, . m; , set -m ( ). , set +m.
m
set -m
set +m
, , . ,
$ sleep 5 & [1] 59468 $ [1] + done sleep 5 $
Source: https://habr.com/ru/post/1607176/More articles:Сложить штабель монады - haskellCorrect way to compile Ruby 2.2 with jemalloc and rbenv? - ruby | fooobar.comUsing webdriver to run in Chrome using Python - pythonReal-time Recording Operations - cocoaGoogle AdMod для мобильных объявлений с просмотром Recycler - admobObtaining a user context identifier for an Open Open Graph API request - facebookhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1607178/ios-todayview-widget-breakpoints-not-working&usg=ALkJrhiIV41NOJZ81Cw9zeZTOlqf_LfyYwSomething is wrong; all ROC metric values are missing: - rHow to use Jackson ObjectMapper inside my own deserializer? - javacart - error - something is wrong - all values of the ROC metric are missing: - rAll Articles