# top

> The `top` command in Unix-like systems displays a real-time view of running processes and system resource usage.

## How do I see which process uses the most CPU with top?

The command that shows running processes, CPU and memory usage in real-time. It's helpful for monitoring system performance and identifying issues.

- Topic: Terminal
- Type: command

## Example

Wrong:

```bash
top > usage.txt
```

Right:

```bash
top -b -n 1 > usage.txt
```

Batch mode prints one snapshot and exits; on macOS the same is `top -l 1`.

## Common mistakes

- Running `top` in a script or CI step that then hangs forever.

## Key points

- Scripts use a one-shot mode (`top -b -n 1` on Linux, `top -l 1` on macOS) or `ps`, since interactive `top` never exits.
- CPU above 100% for one process is read as several cores in use, not an error.

## Interview questions

### How do I quit top?

Press `q`. `Ctrl+C` also works.

### How do I sort top by memory?

In Linux `top`, press `M` to sort by memory and `P` to go back to CPU. On macOS, start it with `top -o mem`.

## Related cards

- [ps aux](https://wonderium.dev/processes/ps-aux.md)
- [`kill <pid>`](https://wonderium.dev/processes/kill.md)
- [`pkill <process>`](https://wonderium.dev/processes/pkill.md)
- [CPU](https://wonderium.dev/engineering/cpu.md)
- [Memory](https://wonderium.dev/engineering/memory.md)

---

- Level: [Processes](https://wonderium.dev/processes.md)
- HTML version: https://wonderium.dev/processes/top
- Last updated: 2026-11-25
