Sign up ×
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.

I want to obtain information about memory used by different users and different processes which users are running and statistics about those processes like memory consumption, execution speed, etc., using Linux system calls.

I don't want to use commands like free, top etc. Can anyone suggest how to do so?

share|improve this question
The /proc filesystem is the typical source of this kind of information. –  Andy Apr 19 '11 at 3:52

2 Answers 2

It's important to understand how memory is used. A significant portion of memory is often shared. Any code used in a program and it's libraries are shared between different processes. Code is mapped into memory as read-only and is shared by all processes so it not owned by any one user. Certain libraries like libc are used by practically every single process, but are only loaded in RAM once. Programs that are more code heavily will have more shared memory than programs that are more data heavy.

To answer your question, nearly all the information that programs like top, free, and ps get comes from scanning the /proc filesystem. Every process has it's own folder named after it's PID. In there are a number of files like maps that show's it's memory map, comm that shows the command that was executed to start the process, and io that shows I/O usage. There's an introduction to /proc in the Linux Kernel Documentation.

share|improve this answer

I think that you need to use following method.I am showing an example :

  • Consider that I need to know information about firefox browser that is running on my Linux Box. I will follow below steps :

    1. Get PID of firefox :

    [shubham@system-dev ~]$ ps -aux | grep firefox Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ shubham 24790 17.5 25.8 1679220 1038440 ? Sl 09:15 26:02 /usr/lib/firefox/firefox

    1. Now use /proc FS with "PID" to see various information (an example for firefox on my linux box is given below) [shubham@system-dev ~]$ cat /proc/24790/status Name: firefox State: S (sleeping) Tgid: 24790 Pid: 24790 PPid: 29843 TracerPid: 0 Uid: 501 501 501 501 Gid: 0 0 0 0 Utrace: 0 FDSize: 256 Groups: 0 VmPeak: 1682804 kB VmSize: 1679412 kB VmLck: 0 kB VmPin: 0 kB VmHWM: 1183048 kB VmRSS: 1040800 kB VmData: 1453848 kB VmStk: 152 kB VmExe: 64 kB VmLib: 61296 kB VmPTE: 2828 kB VmSwap: 147048 kB Threads: 24 SigQ: 1/31287 SigPnd: 0000000000000000 ShdPnd: 0000000000000000 SigBlk: 0000000000000000 SigIgn: 0000000001001000 SigCgt: 00000001800044ef CapInh: 0000000000000000 CapPrm: 0000000000000000 CapEff: 0000000000000000 CapBnd: ffffffffffffffff Cpus_allowed: f Cpus_allowed_list: 0-3 Mems_allowed: 1 Mems_allowed_list: 0 voluntary_ctxt_switches: 2604819 nonvoluntary_ctxt_switches: 560691

    2. You can use many files under /proc// directory for monitoring purpose (ex: mem, io,stat.stack etc)

NOTE: For using with syscalls only, you will need syscalls like: open(), creat(), close(), read() etc.

I hope you could understand the answer!

share|improve this answer

Your Answer


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.