Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: kill and pid files



> well, I don't have the file part, but I use this
> 
> pid () {
> 
> for i in $*
> do
>         echo `/bin/ps -auxwww | grep -v grep |
>         grep -w $i | awk '{print $2}' | tr -s '\012' ' '`
>  
> done
> 
> }

Oh, this is a really overcomplicated solution for a simple problem.  How
about this:

pid () {
    local i
    for i
    do
        ps acx | sed -n "s/ *\([0-9]*\) .* $i *\$/\1/p"
    done
}

Under Linux, you can even do that without ps or sed:

pid2 () {
    local i
    for i in /proc/<->/stat
    do
        [[ "$(< $i)" = *\((${(j:|:)~@})\)* ]] && echo $i:h:t
    done
}

Zoltan



Messages sorted by: Reverse Date, Date, Thread, Author