> For the complete documentation index, see [llms.txt](https://riteshs4hu.gitbook.io/infosec-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://riteshs4hu.gitbook.io/infosec-notes/linux-server-administrator/process-management.md).

# Process Management

Process management in Linux is essential for monitoring, controlling, and optimizing system performance.

### Viewing Processes

#### `jobs` - Show Background Processes

* Display running background jobs:

  ```sh
  jobs
  ```
* Bring a background process to the foreground:

  ```sh
  fg %1
  ```
* Move a foreground process to the background:

  ```sh
  bg %1
  ```

#### `ps` - Process Status

* Show all running processes:

  ```sh
  ps -aux
  ```
* Display all processes for a specific user:

  ```sh
  ps -U username -u username
  ```
* List all processes with terminal type:

  ```sh
  ps -e
  ```
* Show process tree with hierarchical structure:

  ```sh
  ps -ejH
  ```
* Alternative way to display process tree:

  ```sh
  ps -axjH
  ```

***

### Killing Processes

#### Installing Required Tools

* Install `psmisc` for enhanced process management:

  ```sh
  yum install psmisc
  ```

#### `kill` - Terminate a Process

* Kill a process using its ID:

  ```sh
  kill -9 processid
  ```
* Terminate all instances of a process:

  ```sh
  killall processname
  ```
* Kill all processes owned by a specific user:

  ```sh
  killall -u username
  ```
* Kill processes by pattern using regex:

  ```sh
  killall -r processname
  ```

#### `htop` - Interactive Process Viewer

* Launch `htop` for a graphical process overview:

  ```sh
  htop
  ```
* Sort processes by memory usage in `htop`:
  * Press **F6**, then select **MEM**
* Kill a process within `htop`:
  * Select the process, then press **F9**

***

### Monitoring Memory and System Performance

#### `free` - Display Memory Usage

* Show system memory and swap usage in human-readable format:

  ```sh
  free -h
  ```
* Display memory usage in bytes:

  ```sh
  free -b
  ```

#### `vmstat` - System Performance Monitoring

* Show memory usage details:

  ```sh
  vmstat
  ```
* Display disk statistics:

  ```sh
  vmstat -d
  ```
* Show memory statistics every 4 seconds, repeated 5 times:

  ```sh
  vmstat -S M 4 5
  ```
* Monitor CPU usage:

  ```sh
  vmstat 2 10
  ```
