Is there any command that I could use to check the memory usage for a single linux command? For instance I have a script file (test.sh) which will read and extract word from a 100mb text file. How could I know how much memory does this command (./test.sh input_file.txt) would take? Thanks for the advises there!!
Use the free
command to check the usage of RAM.
To check the size of the program in memory you can check the /proc/[pid]/statm
file. For details of the format of this file read man proc
Fetch the PID of 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
Gives you the VMZ and RSS of the process with $PID
.
Or may want to like to see only the process memory using
watch -n0.5 ps u $PID
this will update the usage of the memory for your process every 0.5 secs. Adjust the value for updating as required.
You can just use top
to see that. When you execute your script, a shell process such as bash
, will be create to execute the script for you. So, find the shell process in top
and you can see how many memory it uses.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With