Operating System Review

1 select,poll和epoll

In fact, all of the I / O are polling method, but to achieve the level of difference in terminology.

This problem may be a bit further, but believe that we can answer that question is I / O multiplexers have a good understanding of where tornado is the use of epoll.

Select substantially has three disadvantages:

  1. The number of connections is limited
  2. Find pairing slow
  3. Data copied to the user space by the kernel

The first drawback improved poll

epoll changed three drawbacks.

select model:

He said the popular point is that each client connected to the file descriptor is a socket, have been placed in a collection, after calling select function which has been monitoring the file descriptors have read these, if there is a readable description Fu then our work processes go read the resource. PHP has built-in functions to complete the select system call

 

 

poll model:

Realization poll and select are very similar, the difference is essentially a data structure into fd collection is not the same. select within a process can be maintained up to 1024 connections, poll done on the basis of strengthening, can maintain any number of connectors.

But there is a way to select and poll big problem is that we select is not hard to see through to find out whether readable or writable way in rotation, for example, if there are one million simultaneous connections are not disconnected, but only a client sends the data, so there is need to loop it so many times, resulting in a waste of resources

 

 

epoll model: 

select and poll epoll is an enhanced version, the same poll epoll as an unlimited number of file descriptors.

epoll kernel is based on reflection, when there is an active socket, the system will call a callback function that we set in advance. The poll and select are traversing.

But it is not a good epoll than select / poll all cases, such as in the following scene:

In the case of most clients are active, the system will wake up all the callback function, it will lead to higher loads. As we have to deal with so many connections, it would be better to select traversed simple and effective.

 

 

epoll in the underlying implementation of its own cache area, and the establishment of a red-black tree is used to store socket, another maintains a linked list is used to store event ready.

work process: 

  When executed epoll_create, created a red-black tree and the ready list, the implementation of epoll_ctl, if the increase in socket handle, check whether there is a red-black tree, there is a return immediately, there is added to the tree trunk, and then up to the kernel callback function for when the event comes to interrupt the list ready to insert data. Epoll_wait execution immediately returns to Ready linked list data can be.

 

epoll can be understood as event poll, different from the busy polling and non-discriminatory poll, epoll which flow will occur how the I / O event let us know. So we actually say epoll event-driven (each event associated with fd), and at this time we are operating in these streams are meaningful. (Complexity is reduced to O (1))

 

(2) select, poll each call must be set to fd from user mode to kernel mode copied once, as long as one copy epoll.

 

(1) an array of a large number of fd is copied in its entirety between user mode and kernel address space, whether or not such a replication is not meaningful.  

(2) to select, as the poll return, the need to poll to get ready pollfd descriptor

 

2 Scheduling Algorithm

  1. First come, first served
  2. Short job first
  3. Highest priority scheduling
  4. Round-robin
  5. Multilevel feedback queue scheduling

Real-time scheduling algorithm:

  1. By the time the first priority EDF
  2. Lowest priority laxity LLF

 

3. Some often test command

lsof: list open file 

You can list information is the process open files. Files can be opened

 

1. Ordinary, 2. 3. The network file directory file system 4. The character device file (function) shared library 6. pipes, named pipes 7. symbolic link

8. The word stream socket underlying network socket, UNIX domain socket

9. In linux inside, most of the things that are treated as files ... .. There are many other

 

Tencent interview test too:

1) lists the file information for a program to open

lsof -c mysql

2) a list of all network connections

lsof -i

3). List who is using a port

lsof -i :3306

4) View who is using a file

lsof   /filepath/file

 

2. Check whether the file contains certain strings

find and grep

grep command is a powerful text search tools, grep searches string can be a regular expression, file mode allows text to find. If a matching pattern is found, grep prints all lines containing pattern.

find commonly used to re-search eligible files under a particular directory, it can also be used to search for specific user owner of the file.

1) grep "xxx" -Rln /pwd

Find pwd directory contains "xxx" file

2) find .|xargs grep -ri "IBM" -l 

3) find . -name *.py* -exec grep "clientSocket" {} \+

 

View the process tree

ps axjf

 

All processes Linux system originally came from init, it is the source of all processes, its PID is always 1.

ps auxf

 

free -h

Memory Status

df -h

System Disk Usage

Guess you like

Origin blog.csdn.net/u011510825/article/details/92377361