Loading...

Bash Collection – Script to get the real amount of used memory of an application

The following script was written by me to be able to get the really used amount of memory for one single application.
Since it isn’t that easy to get the used memory through “top” or “ps” or similar tools, this may be helpful for somebody.

The output is in megabytes and looks like this:

Just save the following script as “/usr/local/bin/memused.sh” and make it executable (chmod 755 /usr/local/bin/memused.sh):

Find the script here…

 


If you also have some useful scripts, please don’t hesitate to share them with us!
Just contact info@linuxcounter.net and attach your script with a small description what it does.
Thanks!

.

Share

About Christin Löhner (Linux Counter)


   17 Comments


  1. Chris F.A. Johnson
      2015-09-08

    • GDzien
        2015-09-08

      Chris F.A. Johnson: I absolutely love your version – awesome trick with string insert, never knew that! Hope you will submit some more of your script versions!

    • Elizandro Garcia Roos
        2015-09-09

      Isso é em qual shell ou linguagem Chris?

      • Paulo
          2015-09-11

        “Which shell or language is this?”

        O shell é o executável da primeira linha #!/bin/bash
        Poderia ser outro shell #!/bin/ksh ou #!/bin/tcsh

  2. rmoyao
      2015-09-09

    Shouldn’t the division at the end be to 1024 and not 1000?

    • Alexander Löhner
        2015-09-10

      well, that depends if you want MB or Mb 😛

  3. Ivan Alejandro
      2015-09-09

    The best app I’ve found to get per-app memory consumption is: https://github.com/pixelb/ps_mem/

    • Alexander Löhner
        2015-09-10

      ps_mem is a really cool app, indeed. But it depends on python and not everybody has python installed. or wants to install it.

  4. Nawar
      2015-09-10

    Chris F.A. Johnson

    Your Script does not work!

    • Alexander Löhner
        2015-09-10

      ooookay… THAT is indeed a very usefull error message or problem description….. o.O

    • Alexander Löhner
        2015-09-10

      Okay… after your comment, I looked over that script from Chris and I found, that the formatting was not correct. I’ve fixed that and encapsed the script between code tags. Now it should work after simple copy&paste.

  5. lalebarde
      2015-09-10

    @Chris : please, use code blocks or pastbin, because a copy/past of your code does not work due to wrong quotes.

    • Alexander Löhner
        2015-09-10

      Already fixed

  6. Roger
      2015-09-10

    real-memory-used () # Real Memory used by application name
    {
    for i in $(pidof $1); do echo $(awk ‘/Private/ {sum+=$2} END {print sum}’ /proc/$i/smaps); done | awk ‘{sum+=$1} END {printf(“%.2f\n”, sum/1000)}’
    }

  7. Roger
      2015-09-10

    Oops. The above is a function within .bashrc.

  8. Roger
      2015-09-10

    Ditto.

    I prefer using sh/Bash due to less system resources required.

  9. Ray McKee
      2015-09-11

    Terrific script, thank you. Now I can actually compute usage.

Leave a Reply