# Watching several PIDs



## amnixed (Aug 27, 2014)

I have several subdirectories in $SHOP.

I want to use wait_on(1) to watch for changes in each of the subdirectories. So, I tried this:


```
while :; do

        for DIRECTORY in $(find $SHOP -type d -mindepth 1)

        do

                if ps -p $PID_DIRECTORY # > /dev/null 2>&1
                then
                        echo "$PID_DIRECTORY is running"
                else
                        /usr/local/bin/wait_on -h $DIRECTORY &
                        PID_DIRECTORY=$(echo $!)
                fi
        done

        sleep 10

done
```

However, this doesn't work, because once a single instance of wait_on(1) is running, the initial condition for the existence of $PID_DIRECTORY is always satisfied, so wait_on(1) gets only started in the first subdirectory. So, I'd need to set the initial condition so that wait_on(1) is started in each of the subdirectories, and then keep track of each $PID_DIRECTORY.

How could I do that?


----------

