1

How may I fetch and kill all processes with a PID above e.g 1000?

Using commands like ps -A and top is fine for viewing the list of processes, but how would one only get the PIDs?

The logic of number comparison and task killing is not really an issue. It's just in the question to describe what I wish to accomplish more clearly.

2 Answers 2

1
ps | tr -s ' ' | cut -d ' ' -f 2

will give you a list of PIDs. cut takes the second field of output separated by spaces, but before that we use tr to squeeze out multiple spaces. You can then pipe that through

egrep '\d{4}\d*'

to select all numbers over 1000. Then you could probably send it to xarg for killing.

1000 is easy, but for an arbitrary number like 32768 you may need to use something like sed for filtering.

1

You could use this command :

ps -ef | grep "your_process" | awk '{print $2}' | grep -v 'grep' | xargs kill

Note : "Your_process" would be your "PID"

Else :

ps -ef | grep "your_process" | awk '{print $2}' | xargs kill

would be a worth to try

1
  • I think you've misunderstood the question. Pointing to a specific process isn't what is needed in this scenario. To be specific, the wanted result is to fetch all running processes's PID. Commented Aug 28, 2015 at 15:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .