How to find and stop multiple processes by a user

  WHM

Introduction

Sometimes it becomes necessary to stop processes run by a user, whether for troubleshooting or due to overwhelming resource usage. The following guide will assist in finding and stopping multiple processes.

Procedure

First, find the processes you’re interested in stopping. The ps utility can list running processes, and grep can be used to filter the output. Here, I am searching for all processes by a user. In this guide, I’ll be using the user cptest and the process sleep

But, if you notice, there is an extra process in that list that is not from that user. This is the search query you’ve just made. If you leave it in, you’ll get a warning about that process not existing further in the guide. It is simply a warning, but it is also easy to remove.

To remove this entry, format your first search like this, surrounding the query in single quotes, and the first letter in square brackets:

You can then filter this further. In my case, I only have one type of process running under this user, but the syntax is as follows:

As you can see, the special formatting is not needed for subsequent filters.

The kill utility uses the Process Identifier or PID to identify what processes it is going to stop. You can use awk to filter for it from the second column:

You can use the following syntax to place the output of a command in-line with the arguments for another command:

We’re going to use this feature to feed the PID list we found to the kill utility:

You should now see the processes are no longer running:

LEAVE A COMMENT