You are not logged in.
I have the following script running in the background:
while true; do
pkill trayer
~/bin/ttrayer &
sleep 60
done &
Now I have changed my mind and want to kill it. How can I do this? If I execute "pkill sleep", then it will loop back into the beginning of the while loop. How can I get out of there?
Last edited by awayand (2011-10-27 02:58:17)
Offline
problem is the script is inside a script file that launches dwm, so I would have to kill dwm as well which I don't really want to. sorry, a small detail I should have mentioned...
Offline
You can add this after the while loop:
echo $! >/tmp/trayer_refresh.pid
And then to kill it:
kill `cat /tmp/trayer_refresh.pid`
Offline
You could put a trap right after the backgrounded loop, e.g.
trap "kill $! && echo 'Caught SIGINT: Break'; exit 1" SIGINT SIGKILL
where $! would contain the PID of the previously run process, e.g. the backgrounded loop.
Then pressing ^C will break out of the loop.
Last edited by egan (2011-10-26 22:52:36)
Offline
@stqn: didn't work I am showing PIDs that are no longer active, both files containing the same PID:
while true; do
echo $! >/tmp/trayer_after_do.pid
pkill trayer
~/bin/ttrayer &
sleep 60
echo $! >/tmp/trayer_before_done.pid
done &
@egan: nice solution, but won't work, as I can't ^C out of the script as it is part of my window manager startup script.
To get the whole picture:
.xinitrc starts my script ~/bin/dwmst which contains:
while true; do
pkill trayer
~/bin/ttrayer &
sleep 60
done &
while true; do
dwm || exit
done
Offline
"After the while loop" means right after "done &" .
Offline
@stqn: I see. Now it worked perfectly. You are nice, I like you.
Is there a more elegant solution? I just tried this, analogous to my dwm loop, and I could break out of the loop by doing "pkill sleep".
while true; do
pkill trayer
~/bin/ttrayer &
sleep 60 || exit
done &
Would there be an even more elegant solution, or is this the way to go?
Offline
If you have several scripts running sleep then pkill will kill them all.
I don't have a better idea...
Last edited by stqn (2011-10-27 13:26:42)
Offline
thanks!
Offline