Aychin's Oracle RDBMS Blog

Only for Advanced level Professionals

Linux for DBA

In this post I will share some useful information collected from different sources. Also, I want to share some commands to get information about memory allocation and processes.

ps command

ps -eo pid,ppid,user,psr,pcpu,thcount,cputime,etime,pmem,rss,comm,wchan,stat,args

Description of the fields:

pid – process ID number of the process.

ppid – parent process ID.

user – effective user name.

psr – processor that process is currently assigned to.

pcpu – cpu utilization of the process in “##.#” format. Currently, it is the CPU time used divided by the time the process has been running (cputime/realtime ratio), expressed as a percentage. It will not add up to 100% unless you are lucky.

thcount – number of kernel threads owned by the process.

cputime – cumulative CPU time, “[dd-]hh:mm:ss” format.

etime – elapsed time since the process was started, in the form [[dd-]hh:]mm:ss.

pmem – ratio of the processes resident set size to the physical memory on the machine, expressed as a percentage.

rss – resident set size, the non-swapped physical memory that a task has used (in kiloBytes).

comm – command name.

wchan – name of the kernel function in which the process is sleeping, a “-” if the process is running, or a “*” if the process is multi-threaded and ps is not displaying threads.

stat – multi-character process state. See section PROCESS STATE CODES for the different values meaning. See also s and state if you just want the first character displayed.



Here are the different values that the s, stat and state output specifiers (header “STAT” or “S”) will display to describe the state of a process.

D   Uninterruptible sleep (usually IO)

R   Running or runnable (on run queue)

S   Interruptible sleep (waiting for an event to complete)

T   Stopped, either by a job control signal or because it is being traced.

W   paging (not valid since the 2.6.xx kernel)

X   dead (should never be seen)

Z   Defunct (“zombie”) process, terminated but not reaped by its parent.

For BSD formats and when the stat keyword is used, additional characters may be displayed:

<   high-priority (not nice to other users)

N   low-priority (nice to other users)

L   has pages locked into memory (for real-time and custom IO)

s   is a session leader

l   is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)

+   is in the foreground process group


Note: (Source is here)

As for the virtual memory (VSIZE) of a given process, this refers to the sum total of the sizes of all mapped memory segments in the process’s address space. However, not all of these will be physically present – some may be paged in upon first access and as such will not register as memory in use until actually used. The resident size (RSIZE) is a more accurate view, as it only registers pages that are mapped in right now – although this may also not be accurate if a given page is mapped in multiple virtual addresses (which is very common when you consider multiple processes – shared libraries have the same physical RAM mapped to all processes that are using that library).


/proc filesystem (source is man page)

The proc filesystem is a pseudo-filesystem which is used as an interface to kernel data structures. It is commonly mounted at /proc. Most of it is read-only, but some files allow kernel variables to be changed.

It contains much useful information for database administrators, I will put here only some contents of this filesystem, which is more useful by my opinion.


This holds the complete command line for the process, unless the process is a zombie. In the latter case, there is nothing in this file: that is, a read on this file will return 0 characters. The command-line arguments appear in this file as a set of null-separated strings, with a further null byte (”) after the last string.


This is a symbolic link to the current working directory of the process. To find out the current working directory of process 20, for instance, you can do this:

$ cd /proc/20/cwd
$ pwd  

Note that the pwd command is often a shell built-in, and might not work properly. In bash, you may use pwd -P.

In a multithreaded process, the contents of this symbolic link are not available if the main thread has already terminated (typically by calling pthread_exit).


This file contains the environment for the process. The entries are separated by null bytes (”), and there may be a null byte at the end. Thus, to print out the environment of process 1, you would do:

$ (cat /proc/1/environ; echo) | tr '00' '\n'


Under Linux 2.2 and later, this file is a symbolic link containing the actual pathname of the executed command.

$ ls -l /proc/6753/exe

Usually this link is used to get current Oracle Home for running oracle process.


This is a subdirectory containing one entry for each file which the process has open, named by its file descriptor, and which is a symbolic link to the actual file.

Thus, 0 is standard input, 1 standard output, 2 standard error, etc.

/proc/[pid]/limits (since kernel 2.6.24)

This file displays the soft limit, hard limit, and units of measurement for each of the processe’s resource limits (see getrlimit). The file is protected to only allow reading by the real UID of the process.


A file containing the currently mapped memory regions and their access permissions.

The format is:   address, perms, offset, dev, inode, pathname

where “address” is the address space in the process that it occupies, “perms” is a set of permissions:

r = read
w = write
x = execute
s = shared
p = private (copy on write)

“offset” is the offset into the file/whatever, “dev” is the device (major:minor), and “inode” is the inode on that device. 0 indicates that no inode is associated with the memory region, as the case would be with BSS (uninitialized data).

/proc/[pid]/smaps (since Linux 2.6.14)

This file shows memory consumption for each of the processe’s mappings. For each of mappings there is a series of lines such as the following:

08048000-080bc000 r-xp 00000000 03:02 13130      /bin/bash

Size:               464 kB
Rss:                424 kB
Shared_Clean:       424 kB
Shared_Dirty:        0 kB
Private_Clean:       0 kB
Private_Dirty:       0 kB


The first of these lines shows the same information as is displayed for the mapping in /proc/[pid]/maps. The remaining lines show the size of the mapping, the amount of the mapping that is currently resident in RAM, the number of clean and dirty shared pages in the mapping, and the number of clean and dirty private pages in the

This file is only present if the CONFIG_MMU kernel configuration option is enabled.

To check interesting memory region:

 cat /proc/19005/smaps | grep 60000000-310200000 -A 8



The “proportional set size” (PSS) of a process is the count of pages it has in memory, where each page is divided by the number of processes sharing it. So if a process has 1000 pages all to itself, and 1000 shared with one other process, its PSS will be 1500

The amount of the mapping that is currently resident in RAM (RSS), the process’ proportional share of this mapping (PSS), the number of clean and dirty private pages in the mapping. Note that even a page which is part of a MAP_SHARED mapping, but has only a single pte mapped, i.e. is currently used by only one process, is accounted as private and not as shared.


Useful commands:

The sum of all shared memory segments used by oracle in MB:

ipcs -m | grep oracle | awk '{i+=$5}; END {print i/1024/1024}'


Sort processes by memory usage %:

ps -eo pmem,pcpu,pid,ppid,user,args | sort -g


Real physical memory used by the process in MB:

awk '/Pss/ {i+=$2} END {print i/1024}' /proc/[pid]/smaps

Sure, replace [pid] by the real process ID from the ps command.


Real physical memory used by the all processes under oracle user:

ps -eo pid,user | awk '/oracle/ {system("cat /proc/"$1"/smaps | grep Pss")}' | awk '{i+=$2}; END{print i/1024"Mb"}'

To get this number for all users, remove “/oracle/” from first awk.


List of oracle processes with their physical memory usage in MB, sorted:

ps -eo pid,user,pcpu,pmem,args | awk '/oracle/ {file="/proc/"$1"/smaps";while((getline line<file)>0){if(line~/Pss/){split(line,l);i+=l[2];}}OFMT="%.2f";i=i/1024;print i,"Mb",$1,$2,$3,$4,$5;i=0;}' | sort -g


Now lets get the list of all shared memory segments on the system:

-bash-3.2 $  ipcs -m

------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status      
0x00000000 18644994   root      644        80         2                       
0x00000000 18677764   root      644        16384      2                       
0x00000000 18710533   root      644        280        2                       
0x00000000 55181318   oracle    640        33554432   54                      
0x00000000 54853639   oracle    640        4096       0                       
0x00000000 54886408   oracle    640        4096       0                       
0xac81eb18 54919177   oracle    640        4096       0                       
0xe16a78ec 57540618   oracle    660        2149580800 36                      
0x00000000 55214091   oracle    640        2650800128 54                      
0x00000000 55050252   oracle    640        16777216   52                      
0x2ce46220 55246861   oracle    640        2097152    54                      
0x00000000 55083022   oracle    640        1090519040 52                      
0x8d43fe7c 55115791   oracle    640        2097152    52                      
0x840bfdc4 55902224   oracle    660        2518679552 296                     
0x443875ac 56492049   oracle    660        1277165568 54                      
0xd526f548 56360978   oracle    660        840957952  58                      
0xfc737618 57081875   oracle    660        2518679552 145

Now lets assume you want to know which processes are attached to the specific shared memory segment, for example to 55115791, execute following command, if no output try under the root user:

ps -eo pid,user,args | awk '/oracle/ {file="/proc/"$1"/maps";while((getline line<file)>0){if(line~/55115791/)print $1,$2,$3$4}}'

It will list you all the processes that are attached to this segment, to check another one just replace segment ID in the command.


Hope this commands will help you in your daily administration tasks.

(c) Aychin Gasimov, 03/2014, Munich, Germany


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: