Face questions exercises

1. Please select your talk

Reference answer:

select Before use, the need to monitor the position of the descriptor corresponding to 1 bit, and then pass it to select, when there is any event, will select all the returned descriptors, the application needs to check their traverse there descriptor on which an event occurs, inefficient, and its ongoing copy descriptor in kernel mode and user mode, a large overhead

 

2. Tell us fork, wait, exec function

Reference answer:

Parent process generates a child process using fork out a copy of a copy of the parent process, only this time a copy of the parent process page tables, both processes are reading the same piece of memory, when there is the process of using the time to write realistic copy mechanism to allocate memory, exec function elf can load a file to replace the parent process, from the parent and child processes can run a different program. fork returns child process from the parent process pid returns 0. calling the parent wait blockage will occur from the child until the child process status change, the implementation of successful return 0, -1 error. exec successful execution of the child process starts running from the new program, no return value, failed to return -1 

 

Reference answer:

1. blocking IO: caller calls a function, the function returns to wait and do nothing during the non-stop to check This function does not return, and so the next move must be returned by this function to
2 non-blocking IO : Non-blocking wait, get tested every once in a while IO event is ready. They may not be ready to do something else.
3. The drive signal IO: drive signal IO: linux carried out with the drive signal socket IO, install a signal handler, the process continues to run is not blocked when the time is ready IO, process receives a SIGIO signal. Then deal with IO event.
4.IO multiplexing / multiplexer IO: linux realize IO multiplexing model with select / poll function, these two functions also make the process of blocking, and blocking IO but the difference is that these two functions can block more than at the same time a IO operations. But also simultaneously to a plurality of read operations, write operations IO function is detected. Know when the data is read or written, it really calls the IO operation function
5. asynchronous IO: linux can be invoked aio_read function tells the kernel descriptor buffer pointer and the buffer size, and the notification file offset manner, and then It returns immediately, when the copying of data to the kernel buffer, and then notify the application.

 

Please answer this question why the operating system kernel mode and user mode points

Reference answer:

For security. In some instructions the cpu, some instructions if wrong, will cause the entire system to crash. After the sub-kernel mode and user mode, when the user needs to operate these instructions, the core to provide the API, you can fall into the kernel through system calls, let the kernel to perform these operations.

 

How to design server, so that the requesting client is capable of receiving a plurality of

Reference answer:

Multi-threading, thread pools, io multiplexing

 

+ New thread infinite loop approach a bit low if you connect, how to improve?

 

Reference answer:

Well in advance to create a thread pool, with producer-consumer model, create a task queue, the queue as a critical resource, a new connection, hung on to the task in the queue, the queue is empty all threads sleep. Improved infinite loop: use of such technology select epoll

 

What Will the ready state in the process of waiting for?

Reference answer:

 

C ++ locks you know a few?

Reference answer:

Mutex lock includes, condition variables, and read-write lock spinlock

 

It is scheduled to run right to use the cpu

 

 

Please say something about Socket Programming send () recv () accept () socket () function?

send function to send data to the other end of the TCP connection. A client typically transmits a request to the server with the send function, and the server typically sends a response to the client program with the send function, the copy function is to send the data to be transmitted to the buffer, responsible for the transmission protocol.

recv function to connect the other end of the data from the TCP receiving, when the application calls the recv function, recv wait data transmitted in the buffer s protocol transfer is completed, and then read the contents received from the buffer to the application layer .
accept function by receiving a connection, the kernel maintains a semi-connection queue and a completed connection queue, when the queue is empty, the accept function blocking, not empty when the accept function removed from the top of a completed connection, returns a file descriptor.

 

 

 

Guess you like

Origin blog.csdn.net/wwxy1995/article/details/94411633