This script displays the memory/swap usage for each process in MB. Additionally, it informs the user about the total memory/swap usage and utilization percentage for the system.
- Linux OS
- Bash shell
- Commands:
free
,awk
,getent
-
Make the script file (saved as something like
swap_usage.sh
) executable:chmod +x memory_usage.sh chmod +x swap_usage.sh
-
Execute the script:
./memory_usage.sh ./swap_usage.sh
-
The output will be displayed in the following format:
User: root - PID: 1234 - Swap Used: 2.20 MB - Command: /path/to/command arg1 arg2 User: user1 - PID: 5678 - Swap Used: 1.10 MB - Command: /path/to/another-command arg1 ... Total Swap: 4096.00 MB Used Swap: 100.00 MB Swap Usage: 2.44%
- It's recommended to run this script with root permissions to gather information from all processes.
- The script is primarily designed for Linux environments.