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:
-
The
toporhtopcommand — interactive utilities that show CPU load, memory, and other process parameters. -
The
pscommand — allows you to get static information about processes. For example:
ps -p <PID> -o %cpu,%mem,cmd
-
Reading from
/proc— the/procfilesystem contains information about processes and the system. For a specific process, you can look at the/proc/<PID>/stator/proc/<PID>/statusfiles. -
Using the
pidstatutility — 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.