Home  >  Article  >  Operation and Maintenance  >  What are the basic knowledge of linux operating system

What are the basic knowledge of linux operating system

coldplay.xixi
coldplay.xixiOriginal
2020-08-13 11:31:435851browse

Basic knowledge of the Linux operating system: 1. The operating system distinguishes between physical memory and virtual memory; 2. Understand the relationship between memory and hard disk; 3. Common vulnerabilities in each part, such as the CPU is prone to such bottlenecks. Server, dynamic web server; 4. Master some optimizations of Linux itself.

What are the basic knowledge of linux operating system

Basic knowledge of linux operating system:

1. General introduction to the operating system

•CPU: Just like the human brain, it is mainly responsible for the judgment of related matters and the actual processing mechanism.

Query command: cat /proc/cpuinfo

•Memory: The memory block in the brain, where the information collected from skin, eyes, etc. is recorded for CPU to make judgments . Query command: cat /proc/meminfo

Physical memory

Physical memory is the capacity of the memory stick we insert into the motherboard memory slot. When looking at the computer configuration, the main thing to look at is the physical memory

Virtual Memory

Virtual memory technology is used in Windows, that is, part of the hard disk space is used as memory. When the memory is fully occupied, , the computer will automatically call the hard disk to act as memory to relieve memory tension.

Relationship: Both virtual memory and physical memory may be used in Windows. In Linux, virtual memory will be used only when the physical memory is used up

•Hard disk: The memory block in the brain, Record important data so it can be used again in the future.

Query command: fdisk -l (requires root permission)

2. The relationship between memory and hard disk

The specific command will be introduced later

3. Operating system monitoring command>Write a separate copy

•vmstat

•sar

• iostat

•top

•free

•uptime

•netstat

•ps

•strace

•lsof

4. How to analyze the operating system

Actual process: Read data》Data>Hard disk》Virtual memory (swaP)》Memory》 cpu cache》Execution queue

Analysis direction, just the opposite

5. Vulnerabilities that often occur in various parts

•CPU: This type of bottleneck is prone to occur Mail servers, dynamic web servers

•Memory: Print servers, database servers, static web servers that are prone to such bottlenecks

•Disk I/O: Projects with frequent read and write operations

•Network bandwidth: Frequently uploading and downloading large amounts of projects

6. Some optimizations of Linux itself

1. System installation optimization

When installing a Linux system, disk partitioning and SWAP memory allocation directly affect system performance. Regarding the setting of virtual memory SWAP, there is no longer the so-called requirement that virtual memory be twice the physical memory. However, according to experience, if the memory is small (physical memory is less than 4GB), the SWAP swap partition size is generally set to twice the memory; If the physical memory is about 4GB and less than 16GB, you can set the SWAP size to be equal to or slightly smaller than the physical memory; if the memory is more than 16GB, in principle you can set SWAP to 0, but it is best to set a certain size of SWAP

• 2. Kernel parameter optimization

For example, if the system deploys an oracle database application, then you need to optimize the system shared memory segment (kernel.shmmax, kenerl.shmmni, kernel.shmall),

system Semaphore (kernel.sem), file handle (fs.file0max) and other parameters are optimized and set; if a WEB application is deployed, then the network parameters need to be optimized according to the characteristics of the web application, such as modifying net.ipv4.ip_local_port_range, net. ipv4.tc_tw_reuse, net.core.somaxconn and other network

Kernel parameters

• 3. File system optimization

The optional file systems under Linux are ext2, ext3 , xfs, ReiserFS

The Linux standard file system starts from VFS, then ext, ext2, ext2 is the standard file system on Linux, and ext3 is formed by adding logs on the basis of ext2. From VFS to ext3, the design ideas have not changed much. They were all designed based on the super block and inode design concepts of the early UNIX family. The XFS file system is an advanced log file system developed by SGI. It provides low-latency, high-bandwidth access to file system data by distributing disk requests, locating data, and maintaining cache consistency. Therefore, XFS is extremely scalable and very Robust, with excellent logging capabilities, strong scalability, and fast writing. ReiserFS is a high-performance log file system developed under the leadership of Hans Reiser. It manages data through a completely balanced tree, including file data, file names, log support, etc. Compared with ext2 and ext3, the biggest advantage is that access performance and security are greatly improved. It has the advantages of efficient and reasonable use of disk space, first-class log management mechanism, special search method, massive disk storage, etc.

4. Key knowledge

Physical memory and virtual memory

(1). How to check physical memory and virtual memory?

Top command can view the values ​​of physical memory and virtual memory

(2).Buffer

is a memory chip on the hard disk controller, which has extremely fast access speed. It is a buffer between the internal storage of the hard disk and the external interface. Since the internal data transmission speed of the hard disk is different from the external interface transmission speed, the cache plays a buffering role. The size and speed of the cache are important factors directly related to the transmission speed of the hard disk, and can greatly improve the overall performance of the hard disk.

(3).Cache

CPU cache (Cache Memory) is a temporary memory located between the CPU and the memory. Its capacity is much smaller than the memory but the exchange The speed is much faster than memory. The emergence of cache is mainly to solve the contradiction between the CPU operation speed and the memory read and write speed. Because the CPU operation speed is much faster than the memory read and write speed, this will cause the CPU to spend a long time waiting for data to arrive or write data to the memory. . The data in the cache is a small part of the memory, but this small part is about to be accessed by the CPU in a short period of time. When the CPU calls a large amount of data, it can avoid the memory and call it directly from the cache, thereby speeding up the reading speed.

(4).CPU interrupt

When the CPU finishes executing a current instruction, if the peripheral sends an interrupt request to the CPU, then the CPU will respond if the , an interrupt response signal will be issued, and interrupts will be turned off at the same time, indicating that the CPU is no longer accepting interrupts from another device. At this time, the CPU will find which device the source of the interrupt request is and save the contents of the CPU's own program counter (PC). He will then transfer to the interrupt service routine that handles that interrupt source. After the CPU saves the on-site information and performs equipment services (such as exchanging data), it will restore the on-site information. After these actions are completed, open the interrupt and return to the next instruction of the originally interrupted main program.

(5). Context switching

Context Switch or environment switching

In a multi-tasking system, context switching refers to the CPU An event that occurs when control is transferred from a running task to another ready task.

In the operating system, when the CPU switches to another process, it is necessary to save the state of the current process and restore the state of the other process: the currently running task changes to the ready (or suspended, deleted) state, and another one is selected. The specified ready task becomes the current task. Context switching includes saving the running environment of the current task and restoring the running environment of the task to be run.

The process context is represented by the PCB (process control block, also called PCB, task control block) of the process, which includes process status, CPU register values, etc.

Usually save the current state of the CPU by performing a state save, and then perform a state restore to restart the operation.

Context switching can have a negative impact on performance. However, some context switches are more expensive than others; one of the more expensive context switches is the cross-core context switch. A thread can run on a dedicated processor or across processors. Threads served by a single processor have processor affinity (Processor Affinity), which is more efficient. Preempting and scheduling threads on another processor core can cause cache misses as a result of cache misses and excessive context switches to access local memory. In short, this is called "cross-core context switching".

6. Processes and threads

Process concept

Process is the basic representation of resource allocation Unit is the basic unit of scheduling operation. For example, when a user runs his or her own program, the system creates a process and allocates resources to it, including various tables, memory space, disk space, I/O devices, etc. Then, put the process into the process's ready queue. The process scheduler selects it and allocates CPU and other related resources to it before the process actually runs. Therefore, the process is the unit of concurrent execution in the system.

Thread concept

A thread is the smallest unit for performing operations in a process, which is also the basic unit for executing processor scheduling. If a process is understood as a task logically completed by the operating system, then a thread represents one of the many possible subtasks to complete the task

The relationship between process and thread

(1) A thread can only belong to one process, and a process can have multiple threads, but there is at least one thread. (2) Resources are allocated to processes, and all threads of the same process share all resources of the process.

(3) The processor is assigned to threads, that is, the threads are actually running on the processor.

(4) Threads need to cooperate and synchronize during execution. The threads of different processes must use message communication to achieve synchronization.

Related learning recommendations: linux video

##Note:

1.Linux is a case-sensitive system. For example, Mozilla, MOZILLA, mOzilla and mozilla are four different commands (but only the fourth mozilla is a truly valid command). Also, my_filE, my_file, and my_FILE are three different files. The user's login name and secret are also case-sensitive (this is because the tradition of UNIX systems and C language has always been case-sensitive).

2. The file name can have up to 256 characters, and can contain numbers, periods ".", underscores "_", horizontal bars "-", plus other characters that are not recommended.

3. Files with "." in front of the file name are generally not displayed when entering the "ls" or "dir" command. These files can be regarded as hidden files. Of course, you can also use the command "ls -a" to display these files.

4. "/" is equivalent to "\" under DOS (the root directory, which means the parent directory of all other directories, or a spacer symbol between directories and between directories and files). For example, cd /usr/doc.

5. Under Linux system, all directories are displayed under a single directory tree (different from the drive identification of DOS system). This means that all files and directories on all physical devices are combined under a single directory tree.

6. In the configuration file, lines starting with # are comment lines. When modifying the configuration file, try not to delete the old settings - you can add "#" to the original settings to turn them into comment lines. Always add some comments about the modifications corresponding to the modification places. You will find that in future management Benefit a lot from it.

7.Linux is an inherited multi-user operating system. Your personal settings (and those of other users) are placed in your home directory (usually /home/your_user_login_name). The file names of many configuration files begin with ".", so users generally cannot see these files.

8. System-wide settings are generally placed in the directory /etc.

9. Similar to other multi-user operating systems, under Linux, files and directories have their own owners and access permissions. Generally speaking, you are only allowed files to your home directory (/home/your_user_login_name). Learn some relevant knowledge about file permission management, otherwise you will definitely find Linux to be very troublesome.

10. Command parameter options are generally guided by "-", followed by one character (or "--", when the option exceeds one character). In this way, "-" is a bit like "/" under DOS. For example, enter the command rm --help.

Related recommendations: Programming video course

The above is the detailed content of What are the basic knowledge of linux operating system. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn