bugfixed 'find lowest subprocess'

| No Comments | No TrackBacks
It turns out there's a bug, due primarily to testing on zsh and putting the script into bash.
function find_lowest_subprocess() {
    local -i parent=$1
    local pids
    typeset -a pids

    pids=($(pgrep -P $parent))
    while ((${#pids[@]} > 0)); do
        if ((${#pids[@]} > 1)); then
            parent=${pids[0]}
            local i=0
            while ((i < ${#pids[@]})); do
                local sub=$(pgrep -P ${pids[$i]})
                [[ -n $sub ]] && parent=$sub
                ((i=i + 1))
            done
        else
            parent=$pids
        fi
        pids=($(pgrep -P $parent))
    done
    echo $parent
}
Someone, somewhere forgot about the parenthes around the array assignments. Shame on me!

No TrackBacks

TrackBack URL: http://www.petesh.com/scgi-bin/MT/mt-tb.cgi/100

Leave a comment

About this Entry

This page contains a single entry by Pete Shanahan published on October 5, 2007 12:54 AM.

Waiting on Clannad was the previous entry in this blog.

Plucking dell battery! is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.