Bug#253099: killall.sh: Can kill wrong PID
Thomas Hood wrote:
[snip]
> pids=$(ps ax | grep 'udhcpc\|dhclient\|pump' | sed 's/^[
> ]*\([0-9]*\).*/\1/')
>
> However, (1) this picks up the PID of the grep process itself:
>
> $ ps ax | grep 'udhcpc\|dhclient\|pump'
> 15769 pts/2 S+ 0:00 grep udhcpc\|dhclient\|pump
>
>
> (2) I don't see where udhcpc is started. In dhcp.c only
> dhclient3, dhclient and pump seem to be supported.
This may need dhclient3 in the pattern, and a "grep -v grep".
> (3) ps has built in output formatting so sed isn't really needed.
>
> Better would be:
>
> for CLIENT in dhclient3 dhclient pump ; do
> pids=$(ps --no-headers -o pid -C $CLIENT)
Are you sure busybox ps behaves that way?
Thiemo
Reply to: