Verify main memory usage with linux command

Is there any command that I could use to test memory usage for a single linux command? For example, I have a script file (test.sh) that will read and extract a word from a 100 MB text file. How could I find out how much memory this command (./test.sh input_file.txt) will make? Thanks for the tips there!

+4
source share
2 answers

You can simply use top to see this. When you execute your script, a shell process such as bash will be created to execute the script for you. So, find the shell process at top and you will see how much memory it uses.

+3
source

Use the free command to test RAM usage.

To check the size of the program in memory, you can check the file /proc/[pid]/statm . Read more about the format of this file man proc

Extract the PID from the script from the script using the $$ variable (in bash).

EDIT

Other solutions:

ps u $PID | tail -n1 | tr -s ' ' | cut -d ' ' -f 5,6 ps u $PID | tail -n1 | tr -s ' ' | cut -d ' ' -f 5,6 Gives you the VMZ and RSS process using $PID .

Or you might want to see only the process memory with

watch -n0.5 ps u $PID

this will update the memory usage for your process every 0.5 seconds. If necessary, adjust the value for the update.

+8
source

Source: https://habr.com/ru/post/1494204/


All Articles