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?
ww111697Asked:
Who is Participating?
 
ozoCommented:
awk 'NR==1{print $1}'
0
 
ahoffmannCommented:
kill `ps|awk '($4 ~ /'$1'$/){print}'`
# keep in mind that you might get more than one process
0
 
ww111697Author Commented:
very good answer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.