[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AWKing for PIDs (was Re: NetBSD style rc.d scripts?)



## Michael Erdely (mike_(_at_)_erdelynet_(_dot_)_com):

> command = "httpd"
> PID=`ps -axo pid,ppid,command | grep -v grep \
>         | grep $command | awk '{if ($2 == "1") print $1}'`

For easy use:
pidof() {
	ps -axo pid,ppid,command | awk "\$3==\"$1\" && \$2==\"1\" {print \$1}"
	}

in your .profile. Saves two processes, too (why run grep if you have awk
already running?)

Regards,
cmt

-- 
Spare Space



Visit your host, monkey.org