pidof misses a pid sometimes

Bastian Bittorf bittorf at bluebottle.com
Mon Dec 26 14:32:58 UTC 2011


dear embedded warriors,

we use "BusyBox v1.19.3 (2011-11-24 08:39:59 CET)"
on ar71xx and brcm47xx (mipsel) on openWRT.

It took us some days to trac down a problem with
pidof. We have some checker scripts, which regulary
watch for tasks, if they are running or not using 'pidof'.
Sometimes we catch an error but in fact everything is ok,
but pidof returns an empty list.

The best thing: it's reproduceable (attached and inline):

#!/bin/sh

mywget()
{
        local url="http://127.0.0.1/favicon.ico"
        local pidnum pidbackground mycmdline pidbackground pidlist

        ( wget -qO - "$url" 2>/tmp/error_wget.$$.txt || echo "$?"
>/tmp/error_wget.$$.rc ) &
        pidbackground="$!"
        pidlist="$( pidof wget )"

        [ -z "$pidlist" -a -n "$pidbackground" ] && {
                for i in 1 2 3 4 5; do {
                        pidnum=$(( $pidbackground + $i ))

                        [ -e "/proc/$pidnum/cmdline" ] && {
                                read mycmdline
<"/proc/$pidnum/cmdline"
                                case "$mycmdline" in
                                        wget*)
                                                logger -s "found a
pid, which pidof did'nt see: $pidnum -> $mycmdline"
                                                return 1
                                        ;;
                                esac
                        }
                } done
        }

        return 0
}

I=0
while true; do {
        if mywget >/dev/null ; then
                I=$(( $I + 1 ))
                rm /tmp/error_wget.* 2>/dev/null
        else
                logger -s "pidof-error after $I iterations"
                break
        fi
} do

# ----------------------------------------

it needs up to 2000 iterations, till we are in a stage, where we can
find the pid
with a slow script on our own (the 1 2 3 4 5-loop), but pidof doesn't
see it.
sorry, that the script is not straigtforward, but this is our very
special situation...
IMHO the problem is located in libbb/find_pid_by_name.c

best wishes, Bastian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pidof_misses_pid.sh
Type: application/x-shellscript
Size: 1264 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20111226/20b23ba8/attachment.bin>


More information about the busybox mailing list