In Linux, how to tell how much memory processes are using?

前端 未结 13 942
情歌与酒
情歌与酒 2020-11-30 17:36

I think I may have a memory leak in my LAMP application (memory gets used up, swap starts getting used, etc.). If I could see how much memory the various processes are using

相关标签:
13条回答
  • 2020-11-30 18:16

    In case you don't have a current or long running process to track, you can use /usr/bin/time.

    This is not the same as Bash time (as you will see).

    Eg

    # /usr/bin/time -f "%M" echo
    
    2028
    

    This is "Maximum resident set size of the process during its lifetime, in Kilobytes" (quoted from the man page). That is, the same as RES in top et al.

    There are a lot more you can get from /usr/bin/time.

    # /usr/bin/time -v echo
    
    Command being timed: "echo"
    User time (seconds): 0.00
    System time (seconds): 0.00
    Percent of CPU this job got: 0%
    Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.00
    Average shared text size (kbytes): 0
    Average unshared data size (kbytes): 0
    Average stack size (kbytes): 0
    Average total size (kbytes): 0
    Maximum resident set size (kbytes): 1988
    Average resident set size (kbytes): 0
    Major (requiring I/O) page faults: 0
    Minor (reclaiming a frame) page faults: 77
    Voluntary context switches: 1
    Involuntary context switches: 0
    Swaps: 0
    File system inputs: 0
    File system outputs: 0
    Socket messages sent: 0
    Socket messages received: 0
    Signals delivered: 0
    Page size (bytes): 4096
    Exit status: 0
    
    0 讨论(0)
提交回复
热议问题