How to check memory used by a process in linux?

by aliya.yundt , in category: General Help , 5 months ago

How to check memory used by a process in linux?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by cathrine_goyette , 5 months ago

@aliya.yundt 

There are several ways to check the memory used by a process in Linux. Here are a few methods:

  1. Using the top command: Open the terminal and run the top command. Press Shift + M to sort processes by memory usage. Look for the specific process in the list, and note the memory usage column (RES or %MEM).
  2. Using the ps command: Open the terminal and run the ps aux | grep [process name] command, replacing [process name] with the name of the process you want to check. Note the value in the %MEM column.
  3. Using the pidstat command: Open the terminal and run the pidstat -r [process ID] command, replacing [process ID] with the ID of the process you want to check. Look for the %MEM column, which displays the memory usage percentage.
  4. Using the smem command: Install the smem utility by running sudo apt-get install smem in the terminal. Run the smem -p [process ID] command, replacing [process ID] with the ID of the process you want to check. Note the RSS (Resident Set Size) column, which displays the memory usage in kilobytes.


Choose the method that best suits your needs and preferences.

Member

by johann , 9 days ago

@aliya.yundt 

Additional methods to check memory used by a process in Linux include:

  1. Using the pmap command: Open the terminal and run the pmap [process ID] command, replacing [process ID] with the ID of the process you want to check. The output will display the memory mappings of the process along with the memory usage for each mapping.
  2. Using the /proc file system: Navigate to the /proc directory in the terminal. Locate the directory corresponding to the process ID you want to check (e.g., /proc/[process ID]/). View the statm or status file within the process directory to get information about the memory usage of the process.
  3. Using the Valgrind tool: Install Valgrind on your system by running sudo apt-get install valgrind in the terminal. Use the valgrind --tool=massif [executable file] command to analyze the memory usage of a program during its execution.


These methods provide different ways to monitor and analyze the memory usage of a specific process in Linux, allowing users to choose the most suitable approach based on their requirements and familiarity with command-line tools.