Linux Administrator Should Know To Use PS Command With Example
Linux System administrator should have very proficient in Linux performance monitoring and tuning. For performance monitoring, Linux system administrator should understand how various Linux component and processes works (like CPU, Memory, I/O, Network) ps (process status) is a command use to display current running processes on Unix operating systems. This command is commonly used for process monitoring. Whenever you feel that system become slow, this is the very useful command to troubleshoot. If you have process which seems to hang and you want to stop the process, then you need pid of the process, so that you can terminate by using kill command.
Enter ps faux –cumulative to quickly list all running processes. Output will resemble the following:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.1 1516 520 ? Ss May30 0:05 init [2] root 1559 0.0 0.1 1564 536 ? Ss May30 0:00 /sbin/syslogd root 1579 0.0 0.2 2512 1228 ? S May30 0:00 /bin/sh /usr/bin/ root 1598 0.0 0.1 2512 560 ? S May30 0:00 \_ /bin/sh /usr/ mysql 1599 0.0 3.2 97960 16464 ? S May30 0:02 \_ /usr/sbin root 1600 0.0 0.0 1496 504 ? S May30 0:00 \_ logger -p daemon 1673 0.0 0.0 1696 368 ? Ss May30 0:00 /usr/sbin/atd root 1676 0.0 0.1 1776 748 ? Ss May30 0:02 /usr/sbin/cron root 1683 0.0 0.8 10516 4216 ? S May30 0:00 /usr/sbin/apache www-data 1696 0.0 0.3 10520 1988 ? S May30 0:00 \_ /usr/sbin/apa www-data 1697 0.0 0.3 10520 1960 ? S May30 0:00 \_ /usr/sbin/apa root 11830 0.0 0.1 3472 896 ? Ss May30 0:03 /usr/sbin/sshd root 28133 0.0 0.3 14576 2000 ? Ss 02:38 0:00 \_ sshd: root@pt root 28166 0.0 0.2 2568 1412 pts/0 Rs 02:38 0:00 \_ -bash root 13826 0.0 0.1 2500 816 pts/0 R+ 03:49 0:00 \_ ps fa
Column Names
Commonly-used columns:
1. USER – Username – The name of the user associated with the process
2. PID – Process ID – The unique numeric identifier assigned to the process
3. %CPU – Percentage of CPU – Time used (total CPU time divided by length of time the process has been running)
4. %MEM – Percentage of RAM – Memory used (memory used divided by total memory available)
5. VSZ – Virtual Memory Size – Size of the process in virtual memory expressed in KiB
6. RSS – ???
7. TTY – Terminal controlling the process
8. STAT – Process State – Possible values:
* R – Running
* S – Sleeping (may be interrupted)
* D – Sleeping (may not be interrupted) – used to indicate process is handling input/output
* T – Stopped or being traced
* Z – Zombie or “hung” process
9. START – The date or time at which the process started
10. TIME – Cumulative CPU time used by the process and the child processes started by the process
11. COMMAND – Command used to start the process
Example:1
[root@localhost ~]# ps PID TTY TIME CMD 3371 pts/2 00:00:00 bash 3476 pts/2 00:00:00 ps
Using process Option you can identify the process id, UID, PID, PPID, time and program.
Options
-e using this Option you find every process on the system.
Example 2:
[root@localhost ~]# ps -e | head PID TTY TIME CMD 1 ? 00:00:00 init 2 ? 00:00:00 migration/0 3 ? 00:00:00 ksoftirqd/0
-ef using this option you can get the information like owner of the process, process id, process parent id and name of the program.
Example : 3
[root@localhost ~]# ps -ef | head UID PID PPID C STIME TTY TIME CMD root 1 0 0 07:39 ? 00:00:00 init [5] root 2 1 0 07:39 ? 00:00:00 [migration/0] root 3 1 0 07:39 ? 00:00:00 [ksoftirqd/0] root 4 1 0 07:39 ? 00:00:00 [watchdog/0]
u display user-oriented format and it’s easy to understand, which process is taking percentage of CPU, Mem, etc.
Example: 4
[root@localhost ~]# ps u USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 2375 0.0 0.0 1624 456 tty1 Ss+ 07:40 0:00 /sbin/mingetty tty1 root 2378 0.0 0.0 1624 432 tty2 Ss+ 07:40 0:00 /sbin/mingetty tty2 root 2379 0.0 0.0 1628 464 tty3 Ss+ 07:40 0:00 /sbin/mingetty tty3 root 2380 0.0 0.0 1628 440 tty4 Ss+ 07:40 0:00 /sbin/mingetty tty4 root 2381 0.0 0.0 1624 436 tty5 Ss+ 07:40 0:00 /sbin/mingetty tty5 root 2392 0.0 0.0 1628 440 tty6 Ss+ 07:40 0:00 /sbin/mingetty tty6 root 2679 0.0 0.1 4488 1380 pts/1 Ss+ 07:43 0:00 bash root 3371 0.0 0.1 4492 1392 pts/2 Ss 07:45 0:00 -bash root 3659 0.0 0.0 4216 936 pts/2 R+ 08:32 0:00 ps u
Category: Linux Administration
