>
> Ahh, OK. I'm glad you brought this up because this part is kind of broken.
>
> 1. It sure looks like the test && return on $pidlist should happen
> after the for loop. This happens to work right now because the for
> loop is only going to ever have one value in $lpids. This is because:
>
> 2. lpids=`head -n 1 ${pidfile}`
> That's just not right. If the pidfile really would have multiple pids
> in it, I would imagine they would be listed like:
>
> /var/run/foo.pid:
> 1000
> 1001
> while read pid; do
> ...
> done < $pidfile
>
> but it was broken somehow. Still have to investigate that. So, yeah
> the test should come after the for loop, but the for loop needs to be
> fixed, too. It might have to have two loops to account for multiple
> pids.
>
> while read line; do
> for pid in $line; do
> ...
> done
> done < $pidfile
>
According to the LSB doc, only the first line of the pidfile should be read, so
it looks like there could be more than one pid in the first line. I don't know
if there would ever be a second line or if it's just a precaution to ignore any
other lines.
Maybe this would work:
read line < $pidfile
while pid in $line; do
if kill -0 $pid > /dev/null ; then
pids="$pids $pid"
fi
done
I think "read" is builtin, so it should process faster than sed, altho it
probably only adds milliseconds to execution time. I thought of using "head",
but if I remember correctly, it's not in /bin.
LSB also mentions /proc/$pid, /proc/$pid/cmdline, and /proc/$pid/exe. I guess
you could do this instead:
read line < $pidfile
while pid in $line; do
if [ -d /proc/$pid ] ; then
pids="$pids $pid"
fi
done
LSB comments that /proc/$pid/exe should not be used by itself and that
/proc/$pid/cmdline should be used with it. I looked at them and they just
contain the complete pathname of the script, but /proc/$pid/cmdline was always
empty. I think that this might be overkill, but until I find out what cmdline
contains, I'm just guessing.
I wonder if /proc/$pid looks different in multiprocessor systems?
--
http://linuxfromscratch.org/mailman/listinfo/lfs-support
FAQ: http://www.linuxfromscratch.org/lfs/faq.html
Unsubscribe: See the above information page