"Linux process Management, System monitoring"

Source: Internet
Author: User
Tags cpu usage disk usage pkill

I. Process Management

Foreground process: Generally refers to a process that occupies standard input and/or standard output
Background process: Do not occupy
The default open process is the foreground process
CTRL + C Interrupt
CTRL + Z transfer from front to back
BG Daemon number lets it run in the background
Ls-r/& Let it be in the background

Make a process in the background
1.ctrl+z the foreground process into the background, the default to the background after the stop state
If you want to run the background process in the background using BG # (#表示后台进程编号), CTRL + C does not work at this time
2. When the process is started, use the & symbol to prefix the command and run the process in the background.

Use the FG command to recall a process that has been called into the background to run back to the foreground
FG # (#表示后台进程编号)

Jobs Lists background processes
+: Process that will default action
-: The process of the second operation

Kill background process: Kill-9 PID

Red Hat 5 support kill%1 kills a process

PRI: Priority

Renice: Adjusting NI values
Renice-10 PID

Nice: Specify the NI value directly when executing the command
Nice-n +15 vim. BASHRC

Trap captures the specified signal, but does not complete the function of the signal itself, but executes the command part (the signal name must be capitalized)
Trap ' command ' sig_specify
Trap ' echo ' not exists ' SIGINT snaps to CTRL + C, output not exists

Scheduling execution of a process
Daemon (System service), interruptible sleep state process
Ls/etc/init.d

Kill: A signal is added to the process or process group after the PID
2: Interrupt signal, CTRL + C
9: Forced termination mechanism
15: Terminate the process, the default signal
Kill-l
2) SIGINT (interrupt) 9) SIGKILL (forced termination mechanism) SIGTERM


Pkill: Add process name, end process
Pkill vim

Killall:kill processes by name
A little more efficient than pkill.

Second, System Monitoring command PS view process

Instant point information for the output process state
Options:
A: All terminal-related processes
U: Show process by user name and start time order
x: All processes unrelated to the terminal

USER PID%cpu%MEM VSZ RSS TTY STAT START time Commandroot1  0.0  0.5   2824  1400? Ss .: -   0: on/sbin/Initroot2  0.0  0.0      0     0? S .: -   0:xx[Kthreadd]root3  0.0  0.0      0     0? S .: -   0:xx[migration/0]user: Process owner PID: Process ID%CPU: CPU usage consumed%MEM: Memory usage vsz: occupied virtual memory size RSS: Memory size used TTY: Terminal's secondary appliance number (minor device numbers of TTY) STAT: Process status: Start: Time to start the process; CPU time; command: Name and parameters of the commands;

========================================= Process stat State ==================================D Unable to interrupt the sleep state (usually IO process); R Running, in the interruptible queue, S in hibernation, stationary, T stop or be traced, suspend execution, W enters memory swap (invalid from kernel 2.6); X dead process; Z zombie process does not exist but temporarily cannot be eliminated; W: There is not enough memory paging to allocate the process Wchan is waiting for <: High priority process N: Low priority process L: There is memory paging allocated and locked in the memory body (instant system or a I/+ in the background of the process group;

Priority of the process
1. Duration of CPU processing
2. Opportunities for CPU loading processing

The smaller the number, the higher the priority

0-139
0-99: The system is defined by default
100-139: User can adjust the

Nice adjust nice offset, modify priority -20~+19

Ordinary users can only add nice values, only nice values with positive integers
Administrator Root can use the nice value of negative numbers

The smaller the number, the higher the priority
120 0

PS Head -2USER       PID commandroot         1 /sbin/init

Pstree: Shows the parent-child relationship between processes pstreeinit─┬─abrtd├─acpid├─atd├─auditd───{auditd}├─automount───4*[{automount}]├─console-kit-dae─── the*[{console-kit-da}] ├─crond├─dbus-daemon───{dbus-Daemon}├─hald───hald-runner─┬─hald-addon-Acpi│├─hald-addon-Inpu│└─hald-addon-rfki├─Login───bash├─master─┬─pickup│└─qmgr├─mdadm├─5*[mingetty]├─rpc.idmapd├─rpc.statd├─rpcbind├─rsyslogd───3*[{rsyslogd}]├─sshd───sshd───bash───pstree└─udevd───2*[UDEVD]

Pgrep
View the PID of a process

Pgrep PS
36

Top
top: Modal commands, full screen, dynamic display of process information, by default every three seconds refreshed once   M: Based on memory usage, from large to small sort display   P: sorted by CPU processing time display   T: Sort by run time show      L: whether to show open time and average load information   m: whether to display memory and swap partition information   T: whether to display task volume and CPU information      K-PID; end Process   Q: Exit the      Top interface -D time: Modify the automatic refresh times
Top- the:xx: +(System time) up2: the(Boot time),2Users, load average (load average, 1 minutes, 5 minutes, 15 minutes):0.07,0.07,0.01Tasks:111Total1Running theSleeping,0Stopped0Zombie (Zombie) CPU (s) (only one CPU):0.3%us,0.3%sy,0.0%ni ( Nice),99.0%ID(Idle),0.0%wa (wait),0.0%hi (hard Swap),0.3%si (soft swap),0.0%stmem:249620k Total, 243048k used, 6572k Free, 23696k buffers (buffer storage meta data information) swap:524280k total, 0k used, 524280k Free, 144352k cached (Buffer storage data information)

Netstat

Common parameters
-A (All) displays all options and does not show listen related by default
-T (TCP) displays only TCP-related options
-U (UDP) displays only UDP-related options
-N refuses to display aliases, showing all numbers converted to numbers.
-l list only service status in Listen (listening)

-P Displays the program name that establishes the associated link
-R display routing information, routing table
-e display extended information, such as UID, etc.
-S statistics according to each protocol
-C executes the netstat command every other fixed time.

Hint: The status of listen and listening can only be seen with-a or-l

Vmstat: Statistics for virtual memory

Vmstat 1 10: Refresh once every second, show 10 times

Vmstatprocs-----------Memory-------------Swap-------io------System-------CPU-----R B swpd FreeBuff cache si so bi boinchCS US SyIDWA St0  0      0   6084  24184 144384    Wu    0     0     at    +    -  0  1 98  1  0

R: Indicates the running queue, if the running queue is too large to indicate that your CPU is busy, it generally causes high CPU utilization

B: Number of processes that are blocking

SWPD: The size of virtual memory used, if greater than 0, indicates that your machine is out of physical memory, if not the cause of program memory leakage, then you should upgrade the memory or the memory-consuming task to other machines

Free: The size of the idle physical memory

Buff: System-occupied cache size

Cache: Directly used to remember the files we opened, to buffer the file

Si: The size of the virtual memory read from disk per second, if this value is greater than 0, indicates that physical memory is not sufficient or memory leaks

US: User CPU time

SY: System CPU Time

So: the size of virtual memory written to disk per second, if this value is greater than 0, ibid.

SY: System CPU time, if too high, indicates a long system call time, for example, the IO operation is frequent.

ID: Idle CPU time, in general, ID + US + sy = 100

WT: waits for IO CPU time.

Lsof

To list open files

It is often used to display all open files and processes as a list. Open files include disk files, network sockets, pipelines, devices, and processes. One of the main scenarios for using this command is when you cannot mount a disk and display an error message that you are using or opening a file. With this command, you can easily see which file is in use.

Network Packet Analyzer: tcpdump

Tcpdump is one of the most widely used network packet analyzers or packet monitoring programs that capture or filter TCP/IP packets that are received or transmitted on a specified interface on a network. It also has an option to save the captured package to a file for later analysis.

-H: View command Help

-I: Network interface

-C: Number of output packages required

Process monitoring: Htop

Htop is a very advanced interactive real-time Linux process monitoring tool. It is very similar to the top command, but it has richer features such as user-friendly management of processes, shortcut keys, vertical and horizontal display of processes, and so on.

Monitoring Linux disk I/O: iotop

The Iotop command is also very similar to the top command and the Htop program, but it has the ability to monitor and display real-time disk I/O and process statistics. This tool is useful when you are looking for specific processes and lots of disk read and write processes.

Input/output statistics: Iostat

Iostat is a simple tool for collecting statistics on the input and output status of display system storage devices. This tool is often used to track performance issues with storage devices, including devices, local disks, and remote disks, such as using NFS.

%user: The percentage of CPU that is used to run at the user level.

%nice: The CPU time consumed by the priority process, which is the percentage of all CPUs.

%system: The percentage of CPU that is used to run at the system level (kernel).

%iowait:cpu the percentage of CPU that is consumed while waiting for hardware I/O.

%steal: The percentage of the virtual CPU's unconscious wait time when the hypervisor maintains another virtualized processor.

%idle:cpu the percentage of idle time.


TPS: The number of I/O requests sent per second.

KB_READ/S: Number of blocks read per second.

KB_WRTN/S: Number of blocks written per second.

Kb_read: The total number of blocks that were started to read in now.

KB_WRTN: The total number of blocks started to write now.

Real-time LAN IP monitoring: Iptraf

Iptraf is an open source real-time network (LAN) monitoring application running on the Linux console. It collects a lot of information, such as IP traffic monitoring over the network, including TCP tokens, ICMP details, TCP/UDP traffic separation, TCP connection packets, and bytes. It also collects common information and details about the state of the interface: TCP, UDP, IP, ICMP, non-IP,IP checksum error, interface activity, and so on.

Service Management Program: sysv-rc-conf

The Linux system runs at a specified run level at any time, and the different run level programs and services are different, the work to be done and the purpose to achieve is different, the system can switch between these operational levels to accomplish different tasks. Sysv-rc-conf is a powerful service manager for viewing the runlevel of programs and services.

Monitor the network bandwidth used by each process: Nethogs

Nethogs is a very small program of Open source code (similar to the top command under Linux), which closely monitors the network activity of each process on the system. It also tracks the real-time network bandwidth used by each program or application.

Monitoring network bandwidth: iftop

Iftop is another open source system monitoring application running in the console that shows a list of application network bandwidth usage (source host or destination host) on the system over the network interface, which is updated periodically. Iftop is used to monitor network usage, while ' top ' is used to monitor CPU usage. Iftop is a member of the ' top ' tool family that monitors the selected interface and displays the current network bandwidth usage among the two hosts.

<= =: Indicates the direction of the traffic.
TX: Send Traffic
RX: Receive Traffic
Total: Overall flow
Cumm: Total traffic running iftop to current time
Peak: Traffic Peaks
Rates: Represents the average traffic for the past 2s 10s 40s, respectively

Interface operation:

Press H to toggle whether help is displayed;

Press N to toggle the display of the IP or host name of the machine;

Press S to toggle whether the host information of the machine is displayed;

Press D to toggle whether the host information of the remote target hosts is displayed;

Press T to toggle the display format to 2 lines/1 lines/Only send traffic/show receive traffic only;

Linux System Monitoring Tool--conky

Conky is a system monitoring software used in the desktop environment, can monitor the system running status, network status and other parameters on the desktop, and can be freely customized, but for beginners may be more difficult to get started.

Conky is a free software for system monitoring of X Windows systems, free software that can be used in FreeBSD, OpenBSD, and various Linux releases. Conky is highly configurable and can monitor many system parameters such as CPU, memory, swap memory, hard disk usage etc., temperature of various hardware, system process (top), network status, battery level, system information and mail sending and receiving, various music players MPD, XMMS2, bmpx , audacious) control. Unlike other system monitors that require a high-level parts toolbox (widget toolkits) to render their information, conky can be rendered directly under the X window, which means that conky can consume less resources under the same configuration.

Linux System Monitoring Tool--nagios

Nagios is a monitoring system that monitors the system's operational status and network information. Nagios can monitor the specified local or remote host and service, as well as provide exception notification functionality. [Nagios can run on the Linux/unix platform, while providing an optional browser-based web interface to allow system administrators to view network status, system issues, logs, and more.

The features that Nagios can monitor are:

1, monitoring network services (SMTP, POP3, HTTP, NNTP, ping, etc.);

2, monitor the host resources (processor load, disk utilization, etc.);

3, simple plug-in design allows users to easily expand their services to detect methods;

4, parallel service inspection mechanism;

5, with the ability to define the hierarchical structure of the network, with the "parent" host definition to express the relationship between the network host, this relationship can be used to identify and clarify the host outage or unreachable state;

6, when the service or host problems arise and resolve the alarm sent to the contact person (via email, SMS, user-defined mode);

7, can define some processing procedures, so that it can be in service or host failure to play a preventive role;

8, automatic log scrolling function;

9, can support and implement redundant monitoring of the host;

10, the optional web interface for viewing the current network status, notification and fault history, log files and so on;

"Linux process Management, System monitoring"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.