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

前端 未结 13 1106
情歌与酒
情歌与酒 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:09

    Use

    • ps u `pidof $TASKS_LIST` or ps u -C $TASK
    • ps xu --sort %mem
    • ps h -o pmem -C $TASK

    Example:

    ps-of()
    {
     ps u `pidof "$@"`
    }
    
    $ ps-of firefox
    USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
    const    18464  5.9  9.4 1190224 372496 ?      Sl   11:28   0:33 /usr/lib/firefox/firefox
    
    $ alias ps-mem="ps xu --sort %mem | sed -e :a -e '1p;\$q;N;6,\$D;ba'"
    $ ps-mem 
    USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
    const     3656  0.0  0.4 565728 18648 ?        Sl   Nov21   0:56 /usr/bin/python /usr/lib/ubuntuone-client/ubuntuone-syncdaemon
    const    11361  0.3  0.5 1054156 20372 ?       Sl   Nov25  43:50 /usr/bin/python /usr/bin/ubuntuone-control-panel-qt
    const     3402  0.0  0.5 1415848 23328 ?       Sl   Nov21   1:16 nautilus -n
    const     3577  2.3  2.0 1534020 79844 ?       Sl   Nov21 410:02 konsole
    const    18464  6.6 12.7 1317832 501580 ?      Sl   11:28   1:34 /usr/lib/firefox/firefox
    
    $ ps h -o pmem -C firefox
    12.7
    

提交回复
热议问题