pidof misses a pid sometimes

Bastian Bittorf bittorf at
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):


        local url=""
        local pidnum pidbackground mycmdline pidbackground pidlist

        ( wget -qO - "$url" 2>/tmp/error_wget.$$.txt || echo "$?"
>/tmp/error_wget.$$.rc ) &
        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
                                case "$mycmdline" in
                                                logger -s "found a
pid, which pidof did'nt see: $pidnum -> $mycmdline"
                                                return 1
                } done

        return 0

while true; do {
        if mywget >/dev/null ; then
                I=$(( $I + 1 ))
                rm /tmp/error_wget.* 2>/dev/null
                logger -s "pidof-error after $I iterations"
} 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...
Type: application/x-shellscript
Size: 1264 bytes
Desc: not available
URL: <>

More information about the busybox mailing list