Linux Starce & Top
Linux Starce & Top
Since every process (except the very first one init) in a Linux system has a parent, it sometimes makes
things easier to understand if all processes are displayed in a tree structure. You'll be glad to know there
exists a command line utility callled pstree - that displays a tree of processes.
Below is the example of the “pstree” command with few supplied options..
Process Highlighted
with PID
options used, what they mean indeed are briefly explained Below..
-n : Sort processes with the same ancestor by PID instead of by name. (Numeric sort.)
-p : Show PIDs. PIDs are shown as decimal numbers in parentheses after each process name
1- Get the process ID by querying the process table
One can use the `ps` command to wean out the process to see what it is doing along with its
PID(process ID) and the command running on the particular PID and check the state of the process,
there are multiple argument available with the `ps` command..
2- Tracing Tool:
strace is a diagnostic, debugging and instructional userspace utility for Linux. It is used to monitor and
tamper with interactions between processes and the Linux kernel, which include system calls, signal
deliveries, and changes of process state.
System administrators, diagnosticians and trouble-shooters will find it invaluable for solving problems
with programs for which the source is not readily available since they do not need to be recompiled in
order to trace them. The operation of strace is made possible by the kernel feature known as ptrace.
In the simplest case, strace runs the specified command until it exits. Intercepts and records the system
calls which are called by a process and the signals which are received by a process.
The name of each system call, its arguments and its return value are printed to standard error or to the
file specified with the -o option.
Each line in the trace contains the system call name, followed by its arguments in parentheses and its
return value
$ strace –p <running_process_id>
Example..
$ strace –p 1220
$ strace <command>
Example..
$ strace df –h
c. Trace Count time, calls, and errors for each system call.
Example..
Example..
RHEL 6.7+ and RHEL 7 with strace 4.7 or above:
Older RHEL releases with strace below version 4.7. This includes all releases of RHEL 4, RHEL 5, and
RHEL 6.6 or below:
After using the above instruction , you need to enter control-C to stop the capture of data lets say, after
5 second or whatever length of time you need to capture.
Moreover, there are couple more strace tricks which may benefit while looking for specific details to
figure out the things, below are few of them. The man page for strace provides details on all the
capabilities and options of this powerful diagnostic and profiling tool.
$ strace -i your-program instruction pointer is at the time of the system call
Linux provides facilities to monitor the utilization of memory resources under /proc filesystem
/proc/meminfo capture the state of the physical memory
How to use top to quickly list the process consuming most of the system resources?
For each listed process, the top command displays the process ID (PID), the effective user name of the
process owner (USER), the priority (PR), the nice value (NI), the amount of virtual memory the process
uses (VIRT), the amount of non-swapped physical memory the process uses (RES), the amount of shared
memory the process uses (SHR), the process status field S), the percentage of the CPU (%CPU) and
memory (%MEM) usage, the accumulated CPU time (TIME+), and the name of the executable file
(COMMAND).
For example:
However, you can the run the top command in the batch mode as below which displays a listing of the
most CPU-intensive tasks on the system. The b flag puts it into batch mode to facilitate writing the
output to disk. The c flag tells it to display the full command line for each process instead of just the
program name. The d flag tells it to delay 30 seconds between refreshes and the n flag tells it to stop
after five refreshes.
$ top -bc -d 30 -n 5
There are multiple option and argument are available with the top command which you can use to
determine the specific thing from it, likewise few tricks mentioned below which may provide you a quick
help isolating an issue. For more detail listing of arguments and options available you may use help or
man pages to refer.
$ top -p <Process_ID> To capture and monitor the running state of a particular process
How to use vmstat (virtual memory statistics) to provide information about block IO and CPU activity
in addition to memory?
Example: vmstat 1 5
In the Below output you can see CPU’s statistics by per CPY basis to drill down the different values which
helps in identifying the cpu-wise information’s.
The above all commands are very useful for taking different resource statistics which are ported along
with Unix/Linux systems, However, there is a cool python based utility has been introduced called
“dstat” which provides almost all these features available in a single bundle and very handy and useful
for debugging the Linux system call and resource related issues.
Below will show us the TCP statistics on the server viz how many listening , established connection etc
along with memory faults major and minor ..
Thanks.
Karn Kumar