linux process memory



    How Does a Process Use Memory?

        When a process starts, the operating system allocates the amount of memory the process requires to run. Each process has four memory segments for executable code and data. The "code" segment contains the executable instructions. The "data" segment contains static and global variables. The "stack" contains local variables. The "heap" contains dynamically allocated objects. Processes may use shared libraries. Shared libraries are only loaded into memory once, and all processes using a particular shared library will use that copy.
    What Memory Statistics Does Linux Report?

        Virtual memory is the total amount of the address space reserved by the operating system to the process for its code, data and stack. The virtual memory size reported by Linux includes all the code, data and stack space reserved for use by a process, on both physical memory and swap space. This value includes space used by all shared libraries used by the process. The implication of this is that shared libraries count in full towards the size of a given process.

        The resident memory size of a process reported by Linux includes only the amount of physical memory the process and the shared libraries it references are using at a given time. Segments moved to swap space are not included. Like with virtual memory size, resident memory size includes the space used by shared libraries.
    Viewing a Simple Process Snapshot with ps

        The ps utility provides a snapshot of processes running on the system, reporting the virtual and resident memory size, CPU and memory percentages, and a wide variety of other information. To examine a single process, use the following options to ps, including vsz for the virtual memory size, and rss for the resident memory size. For example,

        ps p 3746 o pid,rss,vsz,comm

        outputs for process 3746:

        PID RSS VSZ COMMAND
        3746 14444 351216 httpd2
    Monitoring Processes with top
        The top utility customized to display process memory usage. Deborah Lee Soltesz

        The top utility provides a live view of system performance. To monitor one or more specific processes with top, use the --p option to provide a list of process IDs. For example:

        top -p 3746,6100,28753,23176,25544

        After launching top, hit the command key "f" to access the column selection screen. Turn on the display for the PID, VIRT, RES, SHR, SWAP, CODE, DATA, and COMMAND columns. As illustrated in the screen shot, the display now shows the following memory statistics:

        VIRT: Virtual memory size
        RES: Resident memory size
        SHR: Shared memory size
        SWAP: Swapped size
        CODE: Code size in physical memory
        DATA: Data plus stack size in physical memory
    Peeking in /proc

        Detailed status and process memory usage information can be found in /proc/<pid>/status and /proc/<pid>/smaps. A variety of information is contained in /proc/<pid>/status, including these memory statistics:

        VmPeak: Peak virtual memory size
        VmSize: Virtual memory
        VmData: Data segment size
        VmStk: Stack size
        VmExe: Executable segment size
        VmLib: Library code size

        /proc/<pid>/smaps provides a very detailed view of a process' memory usages, broken down by mapping for code, stack, heap and each shared library. The complete output of smaps is rather lengthy and difficult to digest. You can use the Linux:Smaps Perl module to parse and process the smaps file.


Read more: How Much Linux Memory is Used by a Process? | eHow.com http://www.ehow.com/about_5497321_much-linux-memory-used-process.html#ixzz2ABgUaeIA

猜你喜欢

转载自ggsonic.iteye.com/blog/1704371