Basic Linux Learning (iv)

Source: Internet
Author: User
Tags format definition disk usage pkill arch linux

XI. system Monitoring 11.1 system monitoring and Process control tools 11.1.1 Top

1) The function of the top command: The top command is a common performance analysis tool under Linux that shows the resource usage of each process in real time, similar to the Task Manager of Windows.

2) when using the top command to list the system state, the system defaults to refresh the display on the screen every 5 seconds.

Top-14:44:15 up 6:41, 1 user, load average:0.02, 0.03, 0.05

tasks:330 Total, 2 running, 328 sleeping, 0 stopped, 0 zombie

%CPU (s): 0.0 us, 0.3 sy, 0.0 NI, 99.7 ID, 0.0 wa, 0.0 hi, 0.0 si, 0.0th

KiB mem:1867636 Total, 1284776 free, 86760 used, 496100 Buff/cache

KiB swap:0 Total, 0 free, 0 used. 1622824 Avail Mem

PID USER PR NI VIRT RES SHR S%cpu%MEM time+ COMMAND

2859 Root 0 157816 2412 1552 R 0.7 0.1 0:00.22 Top

276 Root 0 0 0 0 S 0.3 0.0 0:32.77 kworker/0:1

1, the first line is the task queue information

14:44:15

Current time

Up 6:41

System run time, format last: minutes

1 user

Number of currently logged on users

Load average:0.02, 0.03, 0.05

System load. The three values were 1 minutes, 5 minutes, and 15 minutes ago to the present average.

2. Second to third behavior process and CPU information

tasks:29 Total

Total number of processes

1 Running

Number of processes that are running

328 sleeping

Number of processes for sleep

0 stopped

Number of processes stopped

0 Zombie

Number of zombie processes

Cpu (s): 0.0% US

Percentage of CPU occupied by user space

0.3% Sy

Percentage of CPU consumed by kernel space

0.0% ni

CPU percentage of processes that have changed priority in user process space

99.7% ID

Percentage of idle CPU

0.0% WA

Percentage of CPU time waiting for input and output

0.0% hi

Percent of CPU time consumed by hardware interrupts

0.0% si

Percentage of CPU time that software interrupts consume

3, 45th behavior memory information.

KiB mem:1867636 Total, 1284776 free, 86760 used, 496100 Buff/cache

KiB swap:0 Total, 0 free, 0 used. 1622824 Avail Mem

4. Process information

Column Name

Meaning

Pid

Process ID

PPID

Parent Process ID

Ruser

Real User Name

Uid

User ID of the process owner

USER

User name of the process owner

GROUP

Group Name of Process owner

Tty

The terminal name of the startup process. Processes that are not started from the terminal are displayed as?

PR

Priority level

NI

Nice value. Negative values indicate high priority, positive values indicate low priority

P

Last CPU used, only meaningful in multi-CPU environment

%cpu

CPU time consumption percentage last updated to current

Time

Total CPU time used by the process, in seconds

time+

Total CPU time used by the process, Unit 1/100 sec

%MEM

Percentage of physical memory used by the process

VIRT

The total amount of virtual memory used by the process, in kilobytes. Virt=swap+res

SWAP

The size, in kilobytes, of the virtual memory that the process is using, swapped out.

Res

The size, in kilobytes, of the physical memory that the process used and was not swapped out. Res=code+data

CODE

The amount of physical memory the executable code occupies, in kilobytes

DATA

The amount of physical memory that is used by parts other than executable code (data segment + stack), in kilobytes

Shr

Shared memory size, in kilobytes

Nflt

Number of page faults

Ndrt

The number of pages that were modified the last time it was written to.

S

Process state.

d= non-disruptive sleep state

R= Run

S= Sleep

t= Tracking/Stopping

z= Zombie Process

COMMAND

Command name/command line

Wchan

If the process is sleeping, the system function name in sleep is displayed

Flags

Task Flag, reference sched.h

5. CPU utilization and load average (System load)

CPU is used to work, according to this level to understand, each yard is a CPU

1), CPU utilization:

The last day of the class time is 8 hours, while the code of the number of farmers knocking 2 hours, 2/8=0.25, 25% is the yard in a day's time utilization (normal situation, CPU utilization <70%)

2), CPU load:

The company in a minute for a yard for a number of 3 tasks, and 1 minutes in the yard to do 6 tasks, then the yard load of one minute is 0.5

If the company in 5 minutes for a number of farmers to arrange 100 tasks, and 5 minutes in the yard can only do 50 tasks, then the code farm 5 minutes of load of 2.0, that is, overloaded operation

CPU load <=1: can handle normally

CPU Load >1: overload operation

If there are 4 cores, equivalent to 100 tasks to 4 yards to dry, if each yard load is 100%, then the overall CPU load of 4.0 is very normal phenomenon

      

Multi-core CPU, load average should <= CPU cores * 0.7

3), why to have 1 minutes, 5 minutes, 15 minutes three kinds of CPU load?

In fact, the reason is to give 3 values, is to hope that we can combine to see. Or want to show a dynamic chart-like data, such as the last minute to show the load 120%. The last 5 minutes and 15 minutes show a load of 50%. Maybe you don't have to worry too much. But if you find that the load on the system is maintained at more than 120%, you have to improve the hardware configuration.

CPU utilization and high CPU load are bad phenomena, but there is also the possibility of low utilization and heavy load conditions:

For a yard distribution of 100 projects, there is no doubt that the yard load is very high, but the code farmers in the specific to do a project, may encounter the need to buy machines, or query data, such as time-consuming problems, the real code of the time may be very short, and this time is the real time the yard to work for the company, If every project has a similar problem, then the 100 items added together, the code farmer really does not have too much time to work, which results in low utilization.

4), in both cases, a process cannot be logically run:

1. Process hangs is its own cause, encountering I/O blocking, it will let the CPU to allow other processes to execute, so that the CPU has been working

2. Regardless of the process, it is the operating system level that may invoke other processes to use the CPU because one process takes up too much time, or a priority, and so on.

Thus there are three states of a process

11.1.2 Free

function of the command: Displays the usage status of the memory. (View effect in CENTOS6, use two-dimensional array to represent fo as free output)

1 2 3 4 5 6

1 total used free shared buffers Cached

2 mem:24677460 23276064 1401396 0 870540 12084008

3-/+ buffers/cache:10321516 14355944

4 swap:25151484 224188 24927296

1, from the operating system angle:

Physical Memory fo[2][1]=24677460kb

Memory used by physical memory fo[2][2]=23276064kb

can use memory f[2][3]=1401396kb

Equation: fo[2][1] = fo[2][2] + fo[2][3]

Shared memory F[2][4]=0, which represents memory shared by several processes (data sharing)

f[2][5]=870540 represents the buffers size that has been allocated but not yet used

F[2][6]=12084008 represents the buffers size that has been allocated but not yet used

2. Buffer and Cache interpretation:

A Buffer is something that have yet to being "written" to disk.

A Cache is something that have been "read" from the disk and stored for later use.

That is, buffer is used to store the data to be output to disk (block device), and the cache is to store the data read from disk. Both are designed to improve IO performance and are managed by the OS.

Linux and other mature operating systems (such as Windows), in order to improve the performance of IO read, always have to cache some data, which is why Fo[2][6] (cached memory) is relatively large, and fo[2][3] relatively small reason. To do a simple test:

1) Release the data that was consumed by the system cache;

Echo 3>/proc/sys/vm/drop_caches

2) read a large file and record the time;

3) close the file;

4) Reread the large file and record the time;

The second reading should be much faster than the first time.

The second line of the free output is the use of system memory from an application perspective.

    • For fo[3][2], or-buffers/cache, indicates how much memory an application thinks the system is using;
    • For fo[3][3], or +buffers/cache, indicates how much memory an application thinks the system has;

Because the memory consumed by the system cache and buffer can be quickly recycled, fo[3][3] is usually much larger than fo[2][3].

It also uses two equations:

    • FO[3][2] = fo[2][2]-fo[2][5]-fo[2][6]
    • FO[3][3] = fo[2][3] + fo[2][5] + fo[2][6]

   Free all output values of the command are from/proc/meminfo read out in the .

3, the function of the free command:

Displays the usage status of the memory. (See the effect in CENTOS7 below)

http://www.linuxatemyram.com/mentions using the free command to see the Linux system using memory, used will add the current cache size, which will cause the free column to show very little memory:

$ free-m

Total used free shared buff/cache available

mem:1504 1491 13 0 855 869

swap:2047 6 2041

In practice, however, the cache can be recycled based on the needs of the application, so the free column does not really show how much memory is "available". The actual system available memory should be based on the available data.

The free command mentioned by Linuxatemyram may be the older version, and the 3 Linux distributions, RHEL 7.2,ubuntu 16.04 and Arch Linux, do not appear used include the cache:

$ free-m

Total used free shared buff/cache available

mem:64325 47437 3150 1860 13737 14373

In addition, it can be obtained from the man-free command, and the current calculation of the used value is to be reduced by the Buff/cache:

Used used memory (calculated as Total–free–buffers–cache)

You can use the-w command-line option to get the number of buff and cache used individually:

$ free-wm

Total used free shared buffers cache available

mem:64325 48287 2476 1859 1430 12131 13524

It is important to note that free represents memory that is not currently being used by the program at all, and that the cache can be freed for other processes to use if necessary (not all caches can, of course, be freed, such as memory currently used as RAMFS). And available really shows the memory that the system can now provide to the application. /proc/meminfo provides the value of memavailable from the 3.14 kernel version, and the free program calculates the value of available between 2.6.27~3.14 versions. Earlier than version 2.6.27, the value of available is the same as free.

11.1.3 PS

(See Linux System Management P363)

1) Process definition: A process is a dynamic execution of a program.

2) Daemon definition: daemons are some processes that run in the background and provide system services.

3) Definition of parent and child processes: When a process creates another process, the 1th process is called the parent process of the new process, and the new process is called a child process.

4) PS Command function: Used to display the status of the current process.

Ps–aux Show all the user-related complete information

11.1.4 Pstree, Kill

Centos7 Default No Pstree , need yum-y install Psmisc

1) function of the Pstree command: Displays the program in a tree-like chart.

2) Examples of the use of PSTREE commands:

For example: List the process state tree commands for a process with PID 4729:

Pstree 4729

3) function of the KILL command: sends a signal to one or more processes. The default send termination signal.

4) Apply the KILL command to terminate the process

For example: The command to terminate a process with PID 3852:

Kill 3852

5) Apply the kill-9 command to kill the process

For example: The command to kill a process with PID 3906:

Kill-9 3906

11.1.5 Pgrep

1. Function of the pgrep command: Find a process by name or other property

For example, the command to find a process named Firefox is:

Pgrep Firefox

11.1.6 Pkill

function of the Pkill command: signal to process by name or other attribute

For example, the command to kill a process named Firefox is:

Pkill Firefox

12, hard disk partition, format and management of the file system 12.1 The correspondence between hardware device and file name

(See Linux System Management P297)

1) in a Linux system, each device is treated with a single file.

2) file names for various devices in Linux

12.2 Structure of hard disk and partition of hard disk

(See Linux System Management P301)

1) Why to partition the hard disk:

A) easier to manage and control the system because the relevant files and directories are placed in a single partition.

b) The system is more efficient.

c) can limit the user's share of the hard disk (the size of the disk space).

d) Easier backup and recovery.

2) The logical structure of the hard disk: A hard disk can logically be divided into blocks, tracks, magnetic columns and partitions.

3) block definition: A block is the smallest unit of addressing (access) on a platter, and a block can store data of a certain byte.

4) Definition of track: The track is a circle of a series of connected pieces of the tail.

5) Magnetic column definition: The magnetic column is composed of a stack of tracks, by the same radius on each disc surface of the track.

6) Definition of partition: The partition is composed of a group of adjacent magnetic columns.

12.3 Partitioning of hard disks in Linux systems

(See Linux System Management P303)

1) Classification of hard disk partition: The partition of hard disk can be divided into primary partition, extended partition and logical partition.

2) Number of primary partitions: a maximum of 4 primary partitions can be divided on one hard disk.

3) The Linux operating system's kernel supports a limited number of partitions on each hard drive, and the Linux kernel can support up to a maximum on each hard disk:

A) Divide 15 partitions (partitions) on the SCSI hard disk.

b) Divide 63 partitions (partitions) on the IDE hard disk.

12.4 using the Fdisk and Partprobe commands to manage hard disk partitions

(See Linux System Management P394)

1) The function of the FDISK command: Create a disk partition.

2) commands commonly used in the FDISK command list:

A) D: Delete an (already existing) partition, where D is the 1th letter of the Delete.

b) L: Lists the type of partition (already existing), where L is the 1th letter of the list.

c) m: Lists all commands used in Fdisk, where M is the 1th letter of the menu.

d) N: Add a new partition where n is the 1th letter of new.

e) P: Lists the contents of the partitioned table, where p is the 1th letter of print.

f) Q: Exit Fdisk, but do not store the changes, where Q is the 1th letter of quit.

g) T: Change the ID of the partition system, where T is the 1th letter of the title.

h) W: Exit Fdisk and store the changes, where W is the 1th letter of write.

3) function of the Partprobe command: Re-initialize the partition table of the kernel in memory.

12.5 Creating a file system (data management)

(See Linux System Management P399)

1) format definition: The so-called format is to partition the hard disk space into a number of equal size data block (Blocks), and set the partition of how many I nodes can be used and so on.

2) file system definition: The file system is the method and data structure used by the operating system to clear the files on a disk or partition; that is, the method of organizing files on disk.

3) commonly used file system types

Standard file systems in the Ext2:linux system

Ext3: A log-file system

EXT4: An extended journaled file system for EXT3 systems

LVM: Logical Disk Volume management

ISO9660: The only universal Disc File system available

4) Function of MKFS command: Format disk.

5) Common formatting commands:

Mkfs. File system Type

For example, the command to format a partition/dev/sdb1 as a EXT4 file system is:

Mkfs.ext4/dev/sdb1

12.6 Set Label (partition name) for a partition

(See Linux System Management P405)

1) function of the E2label command: Set or view the label name of a device.

2) Use the E2label command to set the label:

A) For example: The command to view the label of the/DEV/SDB1 partition is:

E2label/dev/sdb1

b) For example: Set the label of the/DEV/SDB1 partition to the command of the WG:

E2LABEL/DEV/SDB1 WG

12.7 file system mount and unload

(See Linux System Management P406)

1) Mount definition: Mount refers to a device (typically a storage device) that is attached to an existing directory.

2) Mount command function: Implementation of file system mount.

3) Mount the file system with the Mount command:

For example: Mount the/DEV/SDB1 partition to a command on the/WG directory:

Mount/dev/sdb1/wg

4) Function of umount command: Implement file system uninstall.

5) Use the Umount command to implement the file system uninstallation:

For example, the command to uninstall the file system on/WG:

Umount/wg

Umount-l/WG #-l parameter, forced unload

12.8 concept of virtual memory and its setting and management

(See Linux System Management P414)

1) Definition of virtual memory: the so-called virtual memory is a piece of hard disk space is used as memory, also known as swap partition (swap).

2) The type of Linux swap partition is: 0x82

3) function of the Mkswap command: Set the swap partition.

4) Use the Mkswap command to set up an example of swap partition usage:

For example, to set the partition/DEV/SDB2 as a command for the swap partition:

Mkswap/dev/sdb2

5) function of the Swapon command: Start the swap partition.

6) function of the Swapon–a command: Start all swap partitions.

7) function of the Swapon–s command: Lists the status of all system swap partitions that are currently in use.

8) Examples of usage of the Swapon command:

For example: Enable the Swap partition/DEV/SDB2 command:

Swapon/dev/sdb2

12.9 inode Node

(See Linux System Management P170)

Inode node Definition: The I node is actually a data structure that holds basic information about an ordinary file, directory, or other file system object.

12.10 Symbolic (soft) links

(See Linux System Management P174)

1) Definition of symbolic Link: a symbolic link is a file that points to another file.

2) An example of the use of the LN command to create a soft connection:

A) Create a dog_ wolf.boy symbolic link to the Wolf/dog.wolf.baby file and place the command in the Bodydog directory:

Ln–s Wolf/dog.wolf.baby Bodydog/dog_ Wolf.boy

12.11 Hard Links

(See Linux System Management P179)

1) The definition of a hard link: A hard link is a file name and an I-node correspondence between, can also be considered a hard link to the corresponding file added an additional path name.

2) The LN command creates a hard-connect usage Example:

A) Create a hard-link command named WOLF.DOG2 in the backup directory for the Wolf/wolf.dog file:

ln Wolf/wolf.dog BACKUP/WOLF.DOG2

12.12 file types in Linux systems

(See Linux System Management P183)

1) Common types of files in Linux systems:

-: Normal files (regular file), also known as regular files.

D: catalog (directory).

L: symbol (soft) link.

B: Block Special file (b is the 1th character of Block), generally refers to block device, such as hard disk.

C: Character special file (c is the 1th character of character), generally refers to a character device, such as a keyboard.

12.13 Checking disk space

(See Linux System Management P185)

1) function of the DF command: Displays the number of disk usage and idle areas in the file system.

-A Show All disks

-H Unit conversion

2) function of the du command: Displays the directory and file size a h ibid.

Basic Linux Learning (iv)

Related Article

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.