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.

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.

| improve this answer | |

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

| improve this answer | |
  • 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. – Aleksander Azizi Aug 28 '15 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.