How to disable the message "Completion" when my team is killed by a timeout?

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
+4
source share
3 answers

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>
+1

, bash 4 . , Terminated, . . :

$ sleep 100 &
[1] 15436
$ disown -r
$ kill -9 15436

help disown:

disown [-h] [-ar] [jobspec...]
.
JOBSPEC . JOBSPEC, .

  • -a , JOBSPEC
  • -h JOBSPEC, SIGHUP , SIGHUP
  • -r
+1

, , () s , . , . .

, . m; , set -m ( ). , set +m.

, , . ,

$ sleep 5 &
[1] 59468
$
[1]  + done       sleep 5
$
+1

Source: https://habr.com/ru/post/1607176/


All Articles