Sobes.tech
Junior — Middle

How can you obtain information about the current process load in Linux OS?

sobes.tech AI

Answer from AI

In Linux, there are several ways to obtain information about the current process load:

  1. The top or htop command — interactive utilities that show CPU load, memory, and other process parameters.

  2. The ps command — allows you to get static information about processes. For example:

ps -p <PID> -o %cpu,%mem,cmd
  1. Reading from /proc — the /proc filesystem contains information about processes and the system. For a specific process, you can look at the /proc/<PID>/stat or /proc/<PID>/status files.

  2. Using the pidstat utility — shows resource usage statistics for processes.

Example of using ps for a process with PID 1234:

ps -p 1234 -o %cpu,%mem,cmd

This will display the CPU and memory usage percentages and the command of the process.

For programmatic access, you can read files in /proc or use libraries like psutil in Python.