Baidu 2014 Campus Recruitment-Research and development engineer Pen test

Source: Internet
Author: User
Tags bind function prototype signal handler socket port number

One, Jane answers (30 points)

1, the current computer system will generally use hierarchical structure to store data, please describe the typical computer storage system is generally divided into several levels, why the use of hierarchical storage data can effectively improve the execution efficiency of the program. (10 points) the so-called storage system hierarchy, is a variety of storage capacity, access speed and price of the memory hierarchically composed of multi-layer memory, and through the management software and auxiliary hardware organically combined into a unified whole, so that the stored procedures and data are distributed in various types of memory. At present, the three-level hierarchy is usually used in computer systems to form a storage system, which consists of cache cache, main memory and auxiliary memory.
In the multilevel hierarchy structure of storage system, the capacity is gradually increased, and the cost is reduced progressively by three levels from top to bottom. The whole structure can be seen as two levels: they are the main memory of a secondary storage level and cache a main memory level. Every memory in this hierarchical system is no longer an isolated memory, but an organic whole. Under the management of the auxiliary hardware and the computer operating system, the primary memory can be stored as a storage unit, and the addressable storage space is much larger than the main storage space. Because of the large secondary storage capacity and low price, the overall average price of the memory system is reduced. Because the cache access speed can be comparable to the CPU speed, so cache a main memory level can reduce the speed gap between main memory and CPU, improve the memory system's access speed overall. Although the cache cost is high, it does not increase the overall cost of the storage system because of its small capacity.
To sum up, a large storage system is composed of a variety of different types of storage devices, is a multi-level hierarchical structure of the storage system. The system is similar to the CPU speed, but also has a great capacity, and the cost is low. The cache solves the speed problem of the storage system, and the secondary memory solves the storage system capacity problem. The memory system with multilevel hierarchy can effectively solve the contradiction between the speed, capacity and price of memory.

How the zombie process is generated in the 2,unix/linux system. What is the harm. How to avoid. (10 points)

When a process calls the Exit command to end its own life, it is not actually destroyed, but rather leaves behind a data structure called the zombie process (Zombie) (System call exit, which is the function of making the process exit, but only to turn a normal process into a zombie process, and cannot be completely destroyed).
In the state of the Linux process, the zombie process is a very special one, it has abandoned almost all memory space, no executable code, and can not be scheduled, just keep a position in the process list, record the process's exit status and other information for other processes to collect, in addition, The zombie process no longer occupies any memory space. It needs its parent process to bury it, if his parent process does not install the SIGCHLD signal handler call wait or Waitpid () waits for the child process to end, and does not explicitly ignore the signal, then it remains zombie state, if the parent process is over, Then the init process will automatically take over the child process, and for it to corpse, it can still be cleared. But if the parent process is a loop and does not end, then the child process will remain zombie state, which is why there are sometimes many zombie processes in the system.

Ways to avoid Zombie:
1) in SVR4, if you call signal or Sigset to set the SIGCHLD configuration to ignore, no zombie subprocess will be generated. In addition, using the SVR4 version of Sigaction, you can set the SA_NOCLDWAIT flag to avoid child process zombies.
This can also be used in Linux, where the function signal (sigchld,sig_ign) is called at the beginning of a program;
2) call Fork two times.
3) Wait for the child process to return with Waitpid.

3, describe the process of using socket library to write server-side program in Unix/linux system, please use corresponding socket communication function (10 points) respectively.

TCP Socket Communication
The server-side process is as follows:
1. Create ServerSocket
2. Initialize SERVERADDR (server address)
3. Bind sockets and SERVERADDR to bind
4. Start monitoring Listen
5. Enter the while loop, constantly accept access to the client socket, read and write operations write and read
6. Close ServerSocket
Client process:
1. Create Clientsocket
2. Initialize SERVERADDR
3. Linking to server Connect
4. Read and write operations using write and read
5. Close Clientsocket


This list is a summary of the functions or methods provided by the Berkeley Socket API library:
The socket () creates a new socket that determines the type, identifies it with an integer value, and allocates system resources to it.
Bind () is typically used on the server side, associating a socket with a socket address structure, such as a specified local port and IP address.
Listen () is used on the server side so that a bound TCP socket enters the listening state.
Connect () is used by the client to assign a free local port number to a socket. If it is a TCP socket, it will attempt to obtain a new TCP connection.
The Accept () is used on the server side. It accepts an access request from a remote client that creates a new TCP connection, creates a new socket, and associates the corresponding socket address for that connection.
Send () and recv (), or write () and read (), or recvfrom () and SendTo (), for sending and receiving data to/from a remote socket.
Close () is used by the system to release resources assigned to a socket. In the case of TCP, the connection is interrupted.
GetHostByName () and gethostbyaddr () are used to resolve host names and addresses.
Select () is used to reshape a socket list: Ready to read, ready to write, or have errors.
Poll () is used to check the status of sockets. Sockets can be tested to see if they can be written, read, or have errors.
GetSockOpt () is used to query the current value of a specific socket option for a specified socket.
The setsockopt () is used to set a specific socket option for the specified socket.

Two, algorithm and programming problem

1, write the function in C + +, implement string inversion, require not to use any system functions, and the time complexity is minimal, function prototype: char* reverse_str (char* str). (15 points) gets the first and last pointer, then swaps the element that the head and tail pointer points to, points to the next, points the tail pointer to the previous one, swaps the element that the pointer points to, and then repeats until the end-to-end pointer encounters.

2, given a string of the following format (1, (2,3), (4, (5,6), 7)), the element in parentheses can be a number or another parenthesis, implement an algorithm to eliminate nested parentheses, such as the above expression into: (1,2,3,4,5,6,7), if the expression is wrong, please give an error. (15 points) using stacks and queue implementations


It seemed that he was ignorant and too sleepy. began to write. It is written first to find the maximum value of the Query_topic_info array and the Adwords_topic_info array, and then return the product


Original: http://blog.csdn.net/yaoyuandejiushizhu/article/details/11879047

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.