Linux Basics Fourth Day

Source: Internet
Author: User
Tags arch linux

System Monitoring

Top Command : Displays the processes running on the system, which is one of the most important tools for system administrators, and is widely used to monitor the load on the server

The top command displays a lot of information about the system. We need to understand the meaning of the different parts of the output: the default runtime, the top command displays the following output:

1.1 System run time and average load:

1.2 Tasks:

The second line shows a summary of the task or process. The process can be in a different state.

1.3 CPU Status:

This shows the percentage of CPU time in different modes. These different CPU times represent:

1) US, User: Percentage of CPU usage

2) Sy,system: Percentage of CPU consumed by kernel space

3) ni,niced: CPU percentage of processes that have changed priority in user process space

4) ID: Percentage of idle CPU

5) WA: Percentage of CPU time waiting for input and output

6) Hi: Percentage of CPU time that hardware interrupts occupy

7) Si: Percentage of CPU time that the software interrupt consumes

8) ST: Percentage of CPU that this virtual machine was stolen by hypervisor

1.4 Memory Information:

The first line is physical memory usage, and the second line is virtual memory usage (swap space).

The physical memory is displayed as follows: All available memory, used memory, free memory, buffered memory

The swap section shows: all, used, idle, and buffered swap spaces

1.5 Process information:

Pid

Process ID

USER

User name of the process owner

PR

Priority level

NI

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

VIRT

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

Res

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

Shr

Shared memory size, in kilobytes

S

Process status

d= non-disruptive sleep state

R= Run

S= Sleep

t= Tracking/Stopping

z= Zombie Process

%cpu

CPU time consumption percentage last updated to current

%MEM

Percentage of physical memory used by the process

time+

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

COMMAND

Command name/command line

Free command: Displays the memory usage status.

                   1          2          3          4          5          -       used free     shared    buffers     cached2 Mem:      24677460   23276064    1401396          0     870540   120840083-/+ buffers/cache:   10321516   143559444 Swap:     25151484     224188   24927296

From the operating system's perspective:

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

Explanation of buffer and cache:

      • 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. We can 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]

All output values of the free command are read from the/proc/meminfo.

4) Master the function of the free command: Displays the memory usage status. (See the effect in CENTOS7 below)

When using the free command to view the Linux memory used by the system, used an item will cache also add the current size, which will cause free this column to display very little memory:

$ free -m               total        used        free      shared  buff/cache   availableMem:           1504        1491          13           0         855      869Swap:          2047           6        2041

In practice, however, cache it can be recycled according to the needs of the application, so free This column does not realistically show how much memory is "available". The actual system available memory should be available data-based.

linuxatemyramThe commands mentioned free may be older versions, and I tried RHEL 7.2 , Ubuntu 16.04 and Arch Linux this 3 Linux release, none of them appear to used contain cache the case:

$ free -m              total        used        free      shared  buff/cache   availableMem:          64325       47437        3150        1860       13737       14373

In addition, from the man free command can be obtained, the current calculation used of the value is to be lost free and buff/cache :

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

You can use -w command-line options to obtain buff and cache use the respective quantity:

$ free -wm              total        used        free      shared     buffers       cache   availableMem:          64325       48287        2476        1859        1430       12131       13524

It is important to note that there is free no memory currently being used by the program at all, and that it cache can be freed for other processes to use if necessary (not all, of course, cache can be freed, such as the memory currently being used ramfs ). To available actually show the memory that the system can currently provide to the application. The value that /proc/meminfo 3.14 is provided from the kernel version, MemAvailable 2.6.27 3.14 and between versions, is the value that the free program calculates itself, and available the value is the 2.6.27 available same as before the version free .

2. Process monitoring-ps in the system
1) Mastering the definition of process: a process is a dynamic execution of a program.
2) Master the definition of daemons: daemons are some processes that run in the background and provide system services.
3) Master the 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) Mastering the functions of the PS command: used to display the status of the current process.
Ps–aux Show all the user-related complete information
Monitoring of processes in the system pstree, kill

Centos7 default no Pstree, requires yum-y install Psmisc
1) Master the function of the Pstree command: Display the program in a tree-like chart.
2) Use examples of mastering Pstree commands:
For example: List the process state tree commands for a PID 4729 process: Pstree 4729
3) Master the function of the KILL command: Send a signal to one or more processes. The default send termination signal.
4) Flexible application KILL command to terminate process
Example: a command to terminate a process with a PID of 3852: Kill 3852
5) Flexible Application kill-9 command kill process
Example: A command to kill a process with PID 3906: kill-9 3906
3. Mastering the 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
4. Mastering the function of the Pkill command: Send a signal to the process by name or other attribute

12th Unit hard disk partition, format and file system management one

1. The corresponding relationship between hardware device and file name (see Linux System Management P297)
1) in the Linux system, each device is treated by a file.
2) Master the file names of various devices in Linux

2. Structure of hard disk and partition of hard disk (see Linux System Management P301)
1) understand why you want to partition your 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) Master the logical structure of the hard disk:
A hard drive can logically be divided into blocks, tracks, magnetic columns, and partitions.
3) Master the definition of the BLOCK: The block is the smallest unit of addressing (access) on the platter, and a block can store a certain byte of data.
4) Master the definition of the track: The track is a circle of a series of connected pieces of the tail.
5) Master the definition of magnetic column: The magnetic column consists of a stack of tracks, consisting of a track on each disc in the same radius.
6) Master the definition of partition: The partition is composed of a group of adjacent magnetic columns.
Partition of hard disk in 3.Linux system (see Linux System Management P303)
1) master the classification of hard disk partition: The partition of hard disk can be divided into primary partition, extended partition and logical partition.
2) Master the number of primary partitions: a maximum of 4 primary partitions can be divided on one hard disk.
3) To understand whether the Linux operating system's kernel supports the number of partitions on each hard disk or a certain limit, 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.
4. Use Fdisk and Partprobe commands to manage hard disk partitions (see Linux system Administration P394)
1) Mastering the function of the FDISK command: Create a disk partition.
2) Master the commands commonly used in the Fdisk commands 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) Mastering the function of the Partprobe command: Reinitialize the partition Table of the in-memory kernel.
5. Create file system (data management) (see Linux System Management P399)
1) Master the definition of formatting: the so-called format is to partition the hard disk space into a number of equal size data blocks (Blocks), as well as how many I nodes in this partition can be used and so on.
2) Master the definition of the file system: The file system is the method and data structure used by the operating system to clear the files on the disk or partition; that is, the method of organizing files on disk.
3) Understanding common 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) Master the function of the MKFS command: Format the disk.
5) Flexible application of commonly used 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
6. Set the label (partition name) for a partition (see Linux System Management P405)
1) Master the function of the E2label command: Set or view the label name of a device.
2) Flexible Application E2label Command set 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

Linux Basics Fourth Day

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.