Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How do I get the memory usage?

How do I get the memory usage?

Scheduled Pinned Locked Moved Unsolved General and Desktop
memorylinux
8 Posts 3 Posters 8.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    ForestPoem
    wrote on 13 Jan 2016, 09:51 last edited by ForestPoem
    #1

    my Function.

    fp = fopen("/proc/meminfo", "r");

    memory usage=(memory total - memory free )*100

    Currently this is in use.

    However, this seems to be the wrong way.

    How do I get the memory usage? in linux

    C F 2 Replies Last reply 13 Jan 2016, 10:24
    0
    • J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 13 Jan 2016, 09:56 last edited by
      #2

      What exactly do you want to have? Bytes used? Percentage used?
      What do you try to calculate with this code: (memory total - memory free )*100 ?
      memory total - memory free gives you amount of used kBytes.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 13 Jan 2016, 09:59 last edited by
        #3

        To calculate the percentage of used memory do: (used memory * 100) / memory total

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • F ForestPoem
          13 Jan 2016, 09:51

          my Function.

          fp = fopen("/proc/meminfo", "r");

          memory usage=(memory total - memory free )*100

          Currently this is in use.

          However, this seems to be the wrong way.

          How do I get the memory usage? in linux

          C Offline
          C Offline
          Charby
          wrote on 13 Jan 2016, 10:24 last edited by
          #4

          @ForestPoem I am afraid Qt is not proposing a portable solution for this...but could you please detail why you think reading proc/meminfo is the wrong way ?

          Another method on linux is reading the sysinfo struct

          1 Reply Last reply
          0
          • F ForestPoem
            13 Jan 2016, 09:51

            my Function.

            fp = fopen("/proc/meminfo", "r");

            memory usage=(memory total - memory free )*100

            Currently this is in use.

            However, this seems to be the wrong way.

            How do I get the memory usage? in linux

            F Offline
            F Offline
            ForestPoem
            wrote on 14 Jan 2016, 02:28 last edited by
            #5

            @ForestPoem

            i'm solved.
            ((total - free + buffer + cache) / total) * 100

            J 1 Reply Last reply 14 Jan 2016, 06:39
            0
            • F ForestPoem
              14 Jan 2016, 02:28

              @ForestPoem

              i'm solved.
              ((total - free + buffer + cache) / total) * 100

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 14 Jan 2016, 06:39 last edited by
              #6

              @ForestPoem Are you sure? It should be ((total - free + buffer - cache) / total) * 100
              At least cache should not be considered as used memory as it is available for application/system as soon as it is needed. The system just uses unused memory as file cache, but that does not mean that this memory is not available.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              F 1 Reply Last reply 14 Jan 2016, 07:30
              0
              • J jsulm
                14 Jan 2016, 06:39

                @ForestPoem Are you sure? It should be ((total - free + buffer - cache) / total) * 100
                At least cache should not be considered as used memory as it is available for application/system as soon as it is needed. The system just uses unused memory as file cache, but that does not mean that this memory is not available.

                F Offline
                F Offline
                ForestPoem
                wrote on 14 Jan 2016, 07:30 last edited by
                #7

                @jsulm

                How, then, would be appropriate?

                i want Utilization.

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 14 Jan 2016, 09:18 last edited by
                  #8

                  Well it depends on what you mean if you say "utilization". From application point of view file cache is free memory.
                  See here: http://www.logicmonitor.com/blog/2014/07/17/the-right-way-to-monitor-virtual-memory-on-linux/

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0

                  2/8

                  13 Jan 2016, 09:56

                  6 unread
                  • Login

                  • Login or register to search.
                  2 out of 8
                  • First post
                    2/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved