Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When my computer is slowing down, I usually run ps aux --sort -rss to find out which process consumes too much memory. There may be a lot of processes. How to see only a few ones?

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

You can tell ps to sort its output. But this seems to be a use case for top or htop. Press M to sort processes by memory and P to sort by CPU time.

share|improve this answer
    
thank you. It's much simpler than ps -eo pid,command,pcpu,pmem --sort -rss | head -N (N is the number of processes I'd like to see. –  Maksim Dmitriev Apr 11 '13 at 8:13
add comment

ps aux --sort -rss | head would seem to be the best bet. head with no argument will display the first 10 lines of its standard input (which would mean the ps column headers, followed by the first 9 processes as returned by your ps command). To see a different number of processes, call head -n <n> where <n> is the number of lines you want.

share|improve this answer
    
I tested the command you had given. It printed names of the processes with all their arguments as a string. It would quite suit me if I didn't use head. head made the table unreadable. I used ps -eo pid,command,pcpu,pmem --sort -rss | head -5 (to see 5 processes). –  Maksim Dmitriev Apr 10 '13 at 12:20
    
head prints on its standard output what it reads on its standard input - it's all strings. Show us what you got, and what you want, and perhaps we can get you closer. –  D_Bye Apr 10 '13 at 12:27
    
I want and I got. –  Maksim Dmitriev Apr 10 '13 at 12:39
    
Drop the -e flag on ps. It causes ps to print each process's environment, which is not what you show in the "I want" image. –  D_Bye Apr 10 '13 at 12:43
    
I don't understand you. I print all the processes and decrease the output with head. Is anything wrong here? –  Maksim Dmitriev Apr 10 '13 at 14:07
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.