Linux : how to see memory usage by various processes in segregated output format

I  am having Linux server, there are various process running the server.

I would like to know details about, the amount of memory consumed by each process.

so that  I can tune the process in simplified manner.
mac_gAdmin - Oracle Fusion Middleware suiteAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try this for all processes:

ps -eo pid, vsize,comm

and this for a single proces ID pid:

ps -p pid -o pid, vsize,comm

You will see the process id, the total virtual memory size in kB and the command.

Instead of (or in addition to) "vsize" you can specify "rss" to see the resident set size or "size" to see the memory size in kilobytes.

A very fine-grain memory map of a particular process ID pid can be obtained with

cat /proc/pid/smaps

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mac_gAdmin - Oracle Fusion Middleware suiteAuthor Commented:
getting below error message

[root@RDOV-BPMDEV01 ~]# ps -eo pid, vsize,comm
ERROR: Unsupported option (BSD syntax)
********* simple selection *********  ********* selection by list *********
-A all processes                      -C by command name
-N negate selection                   -G by real g
Remove the space between "pid," and "vsize,comm"
Redefine Your Security with AI & Machine Learning

The implications of AI and machine learning in cyber security are massive and constantly growing, creating both efficiencies and new challenges across the board. Check out our on-demand webinar to learn more about how AI can help your organization!

mac_gAdmin - Oracle Fusion Middleware suiteAuthor Commented:
i am not getting, can you please type complete command
ps -eo pid,vsize,comm
mac_gAdmin - Oracle Fusion Middleware suiteAuthor Commented:
1)   Can you brief me about params
2)   Can we display memory usage in MB's
ps = report about current processes

-e = select all processes

-p pid = select a particular process ID pid or list of pids. Do not combine with "-e"

-o user-defined output format:

    pid = process id
    rss = non-swapped physical memory used
    size = approximate swap space required for code+data+stack, very rough value!
    vsize = total virtual memory including currently swapped-out pages
    comm = short command (executable only)

ps itself cannot display MB, we'll have to calculate (Example: all processes, vsize):

ps -eo pid,vsize,comm | awk 'NR>1 {printf "%10s%10.2f\t%s\n",$1,$2/1024,$3}'

Open in new window

or simpler (no formatting):
ps -eo pid,vsize,comm | awk 'NR>1 {$2=$2/1024;print $0}

Open in new window


And sorry, the extra space was indeed a mistake (typo)!
mac_gAdmin - Oracle Fusion Middleware suiteAuthor Commented:
wow ..what a genius you are ...

i have applied I got part output as below, very nice.
Does middle column value in MB's ?

      9660      0.67    systemmetrics
     10260    105.61    ps
     10261    103.52    awk
     15369      0.00    kworker/3:0
     27050      0.00    kworker/1:0
     28932     98.06    sshd
     28934     98.06    sshd
     28935    105.94    bash
     32495      0.00    kworker/0:0
     32714      0.00    kworker/0:1H

If you are a friend of nice output you can have a header and better formatting:

ps -eo pid,vsize=VSIZE_MB,comm | awk '{if(NR==1) printf "%8s%10s\t%s\n", $1,$2, $3; else printf "%8s%10.2f\t%s\n", $1, $2/1024,$3}'

Open in new window

mac_gAdmin - Oracle Fusion Middleware suiteAuthor Commented:
wow .. what a magic ...

highly appreciate ur work..

no words ..just great.

i advice  you one thing .. write a book with tricks sell from amazon. I am sure book get downloaded by many.
mac_gAdmin - Oracle Fusion Middleware suiteAuthor Commented:
can this details be fetched for CPU details and its utilization ?
There are two CPU-related fields:

%cpu       cpu utilization of the process in "##.#" format. This is the cputime/realtime ratio in percent
cputime  cumulative CPU time, "[dd-]hh:mm:ss" format.


ps-eo pid,%cpu,cputime

(no formatting required).
mac_gAdmin - Oracle Fusion Middleware suiteAuthor Commented:
am getting below details

[root@RDOV-BPMDEV01 ~]# ps-eo pid,%cpu,cputime
-bash: ps-eo: command not found
Again, a typo, It's

ps -eo pid,%cpu,cputime
mac_gAdmin - Oracle Fusion Middleware suiteAuthor Commented:
i have raised seperate request for CPU...

i wish if you could advice there in detail what I am looking for...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.