I have a script that is suppose to stop and recover the process to run in the background:
process_id=`ps -eaf | grep -i daemon | grep -v grep | grep -v status | grep -v stop | awk '{print $2}'`
(kill -STOP $process_id) &
... # do something else
(kill -CONT $process_id) &
This is working fine, but then in the STDOUT / STDERR this appears:
[1] + 8545 Suspended (signal) /etc/init.d/...
So far I tried to:
(kill -STOP $process_id)
(kill -STOP $process_id) & > /dev/null
/etc/init.d/{name_of_the_daemon} start > /dev/null
(kill -STOP $process_id & ) 2>/dev/null
(kill -STOP $process_id & disown;) 2>/dev/null
set +m
(kill -STOP $process_id) &
(kill -STOP $process_id) & 1>&2
These are the steps that I'm doing:
- create a file fff in
/etc/init.d/
- paste the script from below
chmod 755 fff
- /etc/init.d/fff start
After that, I receive the "suspended" message...
According to @sourcejedi my script is not a daemon; when a child process of the script has been suspended, the "suspended" message appears
How can I suppress the output from the shell for only that particular message?
Here is a very simple version of my script:
#!/bin/bash
pid_script=`ps -eaf | grep -i fff | grep -v grep | grep -v status | grep -v stop | awk '{print $2}'`
case "$1" in
start)
( sleep 3; kill -STOP $pid_script ) &
sleep 10;
(sleep 1; kill -CONT $pid_script) &
;;
stop)
for p in $pid_script # kill all the other processes related with this script (if any)
do
kill -9 $p
done
esac
kill
in the background? What is$process_id
? How did you start the process that$process_id
is the PID of?kill
statement? It really shouldn't take that long... Also, what have you tried so far? Have you even tried redirecting STDOUT or even STDERR? If so, why do you think it didn't work for you? Which Shell are you using?sleep 999 &
, and in the second window you do akill -STOP ...
for the PID of the sleep command. You will see that the suspended message occurs in the first window, not in the one where the kill is executed.