I've implemented the trap-part and now it works fine: the background job
is killed when the script is killed.
But I've noticed that without the trap-part in it, there's a difference
using 'kill PID' or 'killall script' to kill the script. The second way
keeps the background job from the script alive (which was my problem).
When I say kill PID, the background job is killed as well.
But that was not possible for me, because it's xscreensaver that kills
the job for me, and it seems to use the 'killall' way of killing.
The actual script I use now is:
#!/bin/bash
urlget -f -s -m 120 $1 | jpegtran -optimize > ~/.root.jpg
xv -root -rmode 5 -poll -smooth -max -viewonly ~/.root.jpg &
pid=$!
trap "kill $pid ; exit" INT HUP TERM
while sleep 60s; do
urlget -f -s -m 120 $1 | jpegtran -optimize > ~/.root.jpg;
done
Setting this as the xscreensaver program to write to the root-window,
and giving the script as argument an URL of a vidcam-picture, the result
is quite nice. But without the trap in the script, every time the
screensaver started, an instance of xv stayed alive, which was no good
for my system performance...
Tanks for helping me out!
Greetings,
Vic
> : Another solution might be to use 'trap' to trap the signal
> Oh duh, I think you could just kill the job.. Killing the
> "job" should kill all its child processes. Is that what you
> meant?
> (suspend with CTRL-z)
> [1] - Suspended tin -q
> [2] + Suspended testes
> # kill %2
> [2] Terminated testes
> #
> I used a similar script to what you wrote, and it worked.
> --
> "Only two things are infinite, the universe and human stupidity, and
> I'm not sure about the former." --Albert Einstein