I run a script like:
sleep 20 &
PID=$!
kill -9 $PID >/dev/null 2>&1
I dont want the script show the output like:
line 51: 22943 Killed sleep
I have no idea why this happen, I have redirect the output to /dev/null
I run a script like:
sleep 20 &
PID=$!
kill -9 $PID >/dev/null 2>&1
I dont want the script show the output like:
line 51: 22943 Killed sleep
I have no idea why this happen, I have redirect the output to /dev/null
This can be done using 'wait' + redirection of wait to /dev/null :
This script will not give the "killed" message:
While, if you try to use something like:
It will output the message:
I like this solution much more than using 'disown' which may have other implications.
Idea source: https://stackoverflow.com/a/5722850/1208218
The message isn't coming from either
kill
or the background command, it's coming from bash when it discovers that one of its background jobs has been killed. To avoid the message, usedisown
to remove it from bash's job control:Another way to disable job notifications is to put your command to be backgrounded in a
sh -c 'cmd &'
construct.I was able to accomplish this by redirecting the output of the command that I am running in the background. In your case it would look like:
... or if you do not want a log file:
Then, when you want to kill that background process' PID, it will not show on standard out.