OS utilities for Linux¶
This page introduces Linux operating system utilities that are useful for diagnosing KX Sensors system performance.
The following are useful operating system utilities within Linux that provide valuable insight into system operations. The following sections give a brief overview of these utilities. There is extensive documentation of these tools online, as they are available broadly at the O/S level and are not unique to KXS.
top¶
The top program provides a real-time view of a running system, showing system summary information as well as a list of processes or threads currently being managed by the Linux kernel. It is one of the most useful tools for system analysis. It comes pre-installed on every distribution and it is highly interactive.
Type the following command to launch top:
top
If you want to quit, simply press "q" from the keyboard.
The common command line syntax is as follows:
If you want to sort processes by CPU:
top -o %CPU
If you want to sort processes by memory:
top -o %MEM
If you want to list threads:
top -H
If you want to display the full path to the program:
top -c
If you want to list processes from a certain user:
top -u user1
dstat¶
dstat is a resource statistic tool. It combines the ability of iostat, vmstat, netstat and ifstat. dstat allows you to monitor the server resources in real-time. It is supported by most major Linux distributions such as RedHat, CentOS and Debian.
Type the following command to launch the tool:
dstat
When you run dstat without any options, it uses the -cdngy options by default. The -cdngy parameter represents:
c: cpu stats (total cpu usage)d: disk stats (disk/total)n: network stats (net/total)g: page stats (paging)y: system stats (system)
To show information about top cpu, top latency and top memory:
dstat --top-cpu-adv --top-latency --top-mem
To show information about cpu, disk (sda1) utilization and system load:
dstat -cdl -D sda1
If you wish to output dstat information to a file:
nohup dstat -tcdnygmp &
This command writes output to nohup.out in whichever directory the user is in.
dmesg¶
The dmesg utility is a Linux tool that lets you read the kernel ring buffer. The kernel ring buffer holds kernel information messages in a circular buffer. A circular buffer of fixed size is used to limit the resource requirements by overwriting the oldest entry with the next incoming message.
The basic syntax is: dmesg
If you want to limit the output to only errors:
dmesg |grep err
For example:
dmesg | egrep -i 'killed process' // To see kernel log message of killed process
dmesg -T | egrep -iE 'oom|6736' // To see kernel log message for oom killer for PID 6736
netstat¶
netstat is a command line tool for monitoring incoming and outgoing network packets statistics as well as interface statistics. The basic syntax is: netstat -a
Listing all active listening TCP ports:
netstat -lt
Display statistics by protocol:
netstat -s
lsof¶
This command is used to display list of all the open files and processes. The open files included are disk files, network sockets, pipes, devices and processes. The command to list the files is: lsof
List user-specific opened files:
lsof -u user1
List opened files by PID:
lsof -p 1234