Re: memory usage by a process

From: Basile Starynkevitch [news] (basile-news_at_starynkevitch.net)
Date: 04/29/05

  • Next message: invincible: "Re: memory usage by a process"
    Date: Fri, 29 Apr 2005 06:00:24 +0000 (UTC)
    
    

    On 2005-04-29, niraj.kumar.ait@gmail.com <niraj.kumar.ait@gmail.com> wrote:

    > Is their any system call or library to find the memory usage of a

    you didn't define precisely what you mean by memory usage. In
    particular are you thinking of virtual memory space or physical RAM
    usage (which is ill-defined, since a process also consumes the cache
    for files it accesses).

    I assume you are interested by virtual memory space

    > particular process nd total cpu utilization of a particular system.

    Ypu might consider using the getrusage(2) system call.

    > I dont wanna use top command and proc directory.

      I might understand that you don't want to use top or ps, but I don't
    understand why you don't want to use /proc

      From inside your program, a simple way to ask for its memory mapping
    is to read and parse the /proc/self/maps file. For an example, run
    the command "cat /proc/self/maps" which on my system (Debian/Sid) gives
    the map of the process running cat

        % cat /proc/self/maps
        08048000-0804c000 r-xp 00000000 03:02 2828919 /bin/cat
        0804c000-0804d000 rw-p 00003000 03:02 2828919 /bin/cat
        0804d000-0806e000 rw-p 0804d000 00:00 0 [heap]
        b7bca000-b7dca000 r--p 00000000 03:03 718366 /usr/lib/locale/locale-archive
        b7dca000-b7dcb000 rw-p b7dca000 00:00 0
        b7dcb000-b7ef5000 r-xp 00000000 03:02 3597455 /lib/tls/libc-2.3.2.so
        b7ef5000-b7efe000 rw-p 00129000 03:02 3597455 /lib/tls/libc-2.3.2.so
        b7efe000-b7f00000 rw-p b7efe000 00:00 0
        b7f23000-b7f24000 rw-p b7f23000 00:00 0
        b7f24000-b7f3a000 r-xp 00000000 03:02 1177349 /lib/ld-2.3.2.so
        b7f3a000-b7f3b000 rw-p 00015000 03:02 1177349 /lib/ld-2.3.2.so
        bf825000-bf83a000 rw-p bf825000 00:00 0 [stack]
        ffffe000-fffff000 ---p 00000000 00:00 0 [vdso]

      From another program (or a shell), to get the memory mapping of
    process 1234 just read /proc/1234/maps

    Regards

    -- 
    Basile STARYNKEVITCH         http://starynkevitch.net/Basile/ 
    email: basile<at>starynkevitch<dot>net 
    aliases: basile<at>tunes<dot>org = bstarynk<at>nerim<dot>net
    8, rue de la Faïencerie, 92340 Bourg La Reine, France
    

  • Next message: invincible: "Re: memory usage by a process"

    Relevant Pages

    • Re: Can XP cope with 2gb of RAM
      ... steals the top gig for itself. ... WinXP can handle 4GB of physical RAM. ... Each process running in WinXP gets a 4GB virtual memory space. ...
      (microsoft.public.windowsxp.general)
    • Re: /3GB
      ... /3gb switch controls the size of virtual memory space. ... support AWE. ... memory and you should only enable /3gb when your total physical RAM is ... OS to perform AWE memory paging. ...
      (microsoft.public.exchange.admin)
    • Re: Can I use all my RAM?
      ... Each process in XP runs in its own 4GB virtual memory space. ... normal configuration, 2GB of that is reserved for the OS and 2GB is ... processes are swapped in and out of physical RAM by the OS all the ... Tim Slattery ...
      (microsoft.public.windowsxp.general)