Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

kill certain process

Posted on 2002-07-22
3
222 Views
Last Modified: 2012-05-04
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?
0
Comment
Question by:ww111697
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 100 total points
ID: 7169882
awk 'NR==1{print $1}'
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7170383
kill `ps|awk '($4 ~ /'$1'$/){print}'`
# keep in mind that you might get more than one process
0
 

Author Comment

by:ww111697
ID: 7179223
very good answer
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question