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 Answer (30 points)

1, the current computer system generally uses a hierarchical structure to store data, please introduce the typical computer storage system is generally divided into which several levels, why the use of tiered storage data can effectively improve the execution efficiency of the program. (10) The so-called storage system hierarchy, is a variety of storage capacity, access speed and price of storage in a hierarchical structure of multi-layer storage, and through the management software and auxiliary hardware organically combined into a unified whole, so that the stored programs and data distributed in a variety of storage levels. At present, three-level hierarchical structure is usually used in computer systems to form Storage system, which consists of cache, main memory and auxiliary memory.
Storage System multilevel hierarchy, from the top down three level, its capacity gradually increased, the speed of gradual reduction, the cost is reduced. The whole structure can be regarded as two levels: they are main memory a secondary storage level and cache one main memory level. Each 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 main memory can be stored as a whole, and the addressable storage space is much larger than the primary storage space. Because of the large auxiliary storage capacity and low price, the overall average price of the memory system is reduced. Because the cache access speed and CPU speed comparable to the work, so cache a main memory level can reduce the speed gap between main memory and CPU, from the overall increase in memory system access speed. Despite the high cache cost, because of the small capacity, it will not make the overall price of the storage system to increase a lot.
To sum up, a large storage system is composed of various types of storage devices, is a multi-level hierarchical storage system. The system has the same speed as the CPU, and has great capacity, and the cost is lower. The cache solves the problem of the storage system speed, while the secondary memory solves the storage system capacity problem. The use of multi-level hierarchical memory system can effectively solve the memory speed, capacity and price contradictions.

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

When a process ends its own life by invoking the Exit command, it is not actually destroyed, but rather leaves behind a data structure called the zombie process (Zombie) (System call exit, which acts as a process exit, but is limited to turning a normal process into a zombie process, It 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, can not be scheduled, only in the process list to retain a location, record the process of 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, and 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, it remains zombie, if the parent process ends, Then the init process will automatically take over the subprocess and bury it, it can still be cleared. But if the parent process is a loop and does not end, then the child process will remain zombie, which is why there are sometimes many zombie processes in the system.

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

3, a brief description of the Unix/linux system using the socket library to write a server-side program, please use the corresponding socket communication function (10 points)

TCP Socket Communication
The server-side process is as follows:
1. Create ServerSocket
2. Initialization of SERVERADDR (server address)
3. Bind the socket and serveraddr to bind
4. Start Listening Listen
5. Into the while loop, continuous accept access to the client socket, read and write operations write and read
6. Close ServerSocket
Client process:
1. Create Clientsocket
2. Initialization of SERVERADDR
3. Link to server Connect
4. Use write and read for read and write operations
5. Close Clientsocket


This list is a summary of the functions or methods provided by a Berkeley Socket API library:
Socket () Creates a new type of socket with an integer value identified by the type and assigns system resources to it.
Bind () is typically 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 side to allow a bound TCP socket to enter 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.
Accept () is used on the server side. It accepts an access request from a remote client to create a new TCP connection, creating a new socket that is associated with the corresponding socket address for the connection.
Send () and recv (), or write () and read (), or recvfrom () and SendTo (), for sending and receiving data to and from remote sockets.
Close () is used for system release of resources assigned to a socket. If it is TCP, the connection is interrupted.
GetHostByName () and gethostbyaddr () are used to resolve host names and addresses.
Select () is used to trim a list of sockets that are 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.
SetSockOpt () is used to set a specific socket option for the specified socket.

Two, algorithms and programming questions

1, write a function using C + +, implement string inversion, require no system functions, and the minimum time complexity, function prototype: char* reverse_str (char* str). (15) Get the first and last pointers, then swap the elements that are pointed at the beginning and end, point to the next, point the tail pointer to the previous one, swap the element that the pointer points to, and then repeat until the head and tail pointer meet.

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


Seems to have been confused, too sleepy. began to write in disorder. It is written to first 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.