How to see top processes sorted by actual memory usage?

前端 未结 12 992
栀梦
栀梦 2020-12-07 06:53

I have a server with 12G of memory. A fragment of top is shown below:

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                              


        
12条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 07:12

    This very second in time

    ps -U $(whoami) -eom pid,pmem,pcpu,comm | head -n4
    

    Continuously updating

    watch -n 1 'ps -U $(whoami) -eom pid,pmem,pcpu,comm | head -n4'
    

    I also added a few goodies here you might appreciate (or you might ignore)

    -n 1 watch and update every second

    -U $(whoami) To show only your processes. $(some command) evaluates now

    | head -n4 To only show the header and 3 processes at a time bc often you just need high usage line items

    ${1-4} says my first argument $1 I want to default to 4, unless I provide it

    If you are using a mac you may need to install watch first brew install watch

    Alternatively you might use a function

    psm(){
        watch -n 1 "ps -eom pid,pmem,pcpu,comm | head -n ${1-4}"
        # EXAMPLES: 
        # psm 
        # psm 10
    }
    

提交回复
热议问题