Link to home
Start Free TrialLog in
Avatar of ww111697
ww111697

asked on

kill certain process

we can use the following to kill process by name

$cat kill1
kill `ps|grep $1|awk '{print $1}'`

then we can call it by kill1 sleep

But there is a problem, it will kill all process named sleep. How can I change it so that it only kills a certain process, such as the third one or the first one?
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
kill `ps|awk '($4 ~ /'$1'$/){print}'`
# keep in mind that you might get more than one process
Avatar of ww111697
ww111697

ASKER

very good answer