Baidu 2014 campus recruitment-R & D Engineer pen questions (Jinan Station)

Source: Internet
Author: User

Reprinted from: http://blog.csdn.net/yaoyuandejiushizhu/article/details/11879047

I. Short answer (30 points)

1. The current computer system generally uses hierarchies to store data. Please introduce the typical computer storage systems in which layers are generally divided. Why does the adoption of hierarchies to store data effectively improve the program execution efficiency? 10 points)

The hierarchical structure of the storage system refers to the hierarchical structure of memory with different storage capacities, access speeds, and prices, management Software and auxiliary hardware are combined to form a unified whole, so that the stored programs and data are distributed in a variety of storage layers. Currently, a three-level hierarchy is usually used in computer systems to form a storage system, which consists of high-speed buffer memory Cache, primary memory, and secondary memory.
In the multi-level hierarchy of the storage system, the storage system is divided into three levels from top to bottom. The capacity increases gradually, the speed decreases gradually, and the cost decreases progressively. The entire structure can be viewed as two layers: The primary and secondary storage layers and the cache and primary storage layers. Each type of memory in this hierarchy is no longer an isolated memory, but an organic whole. Under the management of auxiliary hardware and computer operating systems, they can take the primary storage and secondary storage layers as a whole, forming a larger addressable storage space than the primary storage space. Because of the large storage capacity and low price, the overall average price of the storage system is reduced. Because the Cache access speed can be comparable to the CPU operation speed, the cache primary storage level can narrow the speed gap between the primary storage and the cPu, and improve the overall access speed of the memory system. Although the Cache cost is high, the overall cost of the storage system will not be increased much because of the small capacity.
To sum up, a large storage system is composed of various types of storage devices and is a multi-level hierarchical storage system. The system has a high speed and a high capacity similar to the CPU, and the cost is low. The high-speed cache solves the speed problem of the storage system, while the secondary storage solves the capacity problem of the storage system. The multi-level hierarchical storage system can effectively solve the contradiction between the storage speed, capacity and price.

2. How does a zombie process generate in Unix/Linux? What are the dangers? How to avoid it? (10 points)

When a process calls the exit command to end its own life, it is not actually destroyed, but left a data structure system called exit, called Zombie, which is a Zombie process, it is used to exit a process, but it is only limited to converting a normal process into a zombie process and cannot completely destroy it ).
In the status of a Linux Process, a zombie process is a very special one. It has abandoned almost all the memory space, no executable code, and cannot be scheduled, only one location is retained in the process list, and information such as the exit status of the process is recorded for collection by other processes. In addition, zombie processes no longer occupy any memory space. It requires its parent process to collect dead parts for it. If its parent process does not have the SIGCHLD signal processing function installed, it calls wait or waitpid () to wait until the child process ends, if the signal is not explicitly ignored, it will remain in zombie state. If the parent process ends, the init process will automatically take over the child process and send a zombie to it, it can still be cleared. However, if the parent process is a loop and does not end, the child process will remain zombie, which is why many zombie processes sometimes exist in the system.

To avoid zombie:
1) In SVR4, IF signal or sigset is called to set SIGCHLD configuration to ignore, no zombie sub-process will be generated. In addition, you can set the SA_NOCLDWAIT flag to prevent sub-processes from freezing.
In Linux, you can also use this function to call signal (SIGCHLD, SIG_IGN) at the beginning of a program );
2) Call fork twice.
3) Use waitpid to wait for the sub-process to return.

3. Briefly describe the process of using the socket library to write server programs in Unix/Linux systems. Please use the corresponding socket communication functions (10 points)

TCP socket communication
The server process is as follows:
1. Create a serverSocket
2. initialize the serverAddr server address)
3. bind the socket and serverAddr
4. Start listening to listen
5. Enter the while LOOP, constantly accept access client socket, read and write operations write and read
6. Disable serverSocket
Client process:
1. Create a clientSocket
2. initialize serverAddr
3. connect to the server
4. read and write operations using write and read
5. Disable clientSocket


This list is a summary of functions or methods provided by a Berkeley Socket API Library:
Socket () creates a new socket of the determined type. The type is identified by an integer and system resources are allocated to it.
Bind () is generally used on the server side to associate a socket with a socket address structure, such as a specified local port and IP address.
Listen () is used on the server to bring a bound TCP socket to the listening state.
Connect () is used by clients to assign a free local port number to a socket. If it is a TCP socket, it will try to obtain a new TCP connection.
Accept () is used on the server. It accepts an access request from a remote client to create a new TCP connection, creates a new socket, and is associated with the corresponding socket address of the connection.
Send () and recv (), or write () and read (), or recvfrom () and sendto (), used to send and receive data to/from a remote socket.
Close () is used to release resources allocated to a socket. If it is TCP, the connection will be interrupted.
Gethostbyname () and gethostbyaddr () are used to parse host names and addresses.
Select () is used to trim the socket list with the following conditions: read, write, or error.
Poll () is used to check the socket status. The socket can be tested to check whether it can be written, read, or error.
Getsockopt () is used to query the current value of a specific socket option of a specified socket.
Setsockopt () is used to set a specific socket option for the specified socket.

2. algorithm and Program Design Questions

1. Use C/C ++ to write a function to reverse the string. You do not need to use any system function and the minimum time complexity. The function prototype is char * reverse_str (char * str ). (15 points)

Obtain the first and last pointers, exchange the elements pointed to by the first and last pointers, direct the first pointer to the next, forward the last pointer to the first one, exchange the elements pointed to by the pointer, and then execute the operation again, until the beginning and end of the pointer meet.


2. Given a string (1, (2, 3), (4, (5, 6), 7) in the following format, the element in the brackets can be numbers or another bracket, implement an algorithm to eliminate nested parentheses. For example, convert the above expression to: (1, 2, 3, 4, 5, 6, 7). If the expression is incorrect, report an error. (15 points)

Stack and queue implementation

650) this. width = 650; "src =" http://img.blog.csdn.net/20130921192342109? Watermark/2/text/plain/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA ==/ dissolve/70/gravity/SouthEast "style =" border: none; "alt =" SouthEast "/>

It seems that it was too difficult. Then we started to write it in disorder. First, find the maximum value of the query_topic_info array and the adwords_topic_info array, and return the product.


This article from the "Yi fall Dusk" blog, please be sure to keep this source http://yiluohuanghun.blog.51cto.com/3407300/1299814

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.