How many questions can you answer about Linux? --Answer 14-20 questions

Source: Internet
Author: User
Tags epoll

Whatis the difference between select and poll? Whatis the difference between P Oll and Epoll?

(1) The difference between Select and poll: (see: http://blog.csdn.net/mituan2008/article/details/6695177 )

The fundamental difference is that the fd_set of select () is a bitmask (bit mask), so the fd_set has a fixed length. The kernel is not limited by this length when it is compiled, because select () allows the application to customize the size of the fd_setsize, but this adds additional expense.

You need to customize the POLLFD struct array when calling poll () and you need to specify the size of the array, so there is no limit to the principle.

(2) The difference between select and poll, Epoll (see http://www.cnblogs.com/Anker/p/3265058.html )

A. The Select,poll implementation requires itself to constantly poll all FD collections until the device is ready, during which time the sleep and wake-up times may be alternating. While Epoll actually needs to call Epoll_wait to constantly poll the ready linked list, there may be multiple sleep and wake alternates, but when it is device ready, call the callback function, put the ready FD into the Ready list, and wake the process into sleep in epoll_wait. While both sleep and alternate, select and poll traverse the entire FD collection while "Awake", while Epoll is "awake" as long as it is OK to determine if the ready list is empty, which saves a lot of CPU time. This is the performance boost that the callback mechanism brings.

B. Select,poll each call to the FD collection from the user state to the kernel state copy once, and to put the current to the device waiting queue once, and Epoll as long as a copy, and the current to wait for the queue is hung only once (at the beginning of epoll_wait , note that the wait queue here is not a device waiting queue, just a epoll internally defined wait queue. This can also save a lot of overhead.

C. Several major drawbacks of select:

Each time a select is called, the FD collection needs to be copied from the user state to the kernel state, which is very expensive when FD is large;

At the same time, each call to select needs to traverse all the FD that is passed in the kernel, which is also very large when the FD is many;

The number of file descriptors supported by Select is too small and the default is 1024.

D. The implementation of poll is very similar to select, except that it describes the FD collection in different ways, the number of descriptors is unrestricted, poll uses the POLLFD structure rather than the fd_set structure of the Select, and the others are similar.

15. Talk about the understanding of section-page management? When will the segment fault (segment error, missing pages exception) occur?

What is section-page management? Reference:http://blog.csdn.net/xiucaijiang/article/details/6818359

(http://zhan.renren.com/h5/entry/3602888497996214030

In fact, better to explain in ULK3 page376: Fault Handling program for pages

The purpose of introducing section-page management is to obtain the advantages of fragmentation in terms of logic and the advantages of paging in managing storage space.

(1) The segmented method is used to allocate and manage the virtual memory. Divide the process address space into segments, and each paragraph has its own segment name, dividing each section into several pages.

(2) Use the paging method to assign and manage the actual storage. That is, the entire main memory is divided into equal size storage block, can be loaded into any page of the job.

(3) The representation of the logical address structure: a logical address is represented by three parameters: segment number s; page number p; page address D.

(4) Paragraph table, page table, Segment table address register. For address translation, the system establishes a segment table for each process and creates a page table for each segment in the Process segment table. The system has a segment table address register to indicate the process's segment table start address and Segment table length.

Advantages and disadvantages of section-page management:

Advantages

(1) It provides a large amount of virtual storage space.

(2) Can effectively use main memory, for the organization of multi-Channel program operation provides convenience.

Disadvantages

(1) Increase the hardware cost, the complexity of the system and the management of the opening and elimination.

(2) There is a risk of jitter in the system.

(3) There is a fragment inside.

(4) There are various forms to occupy main memory space.

Segment-page Storage management technology is the most versatile and flexible solution for current large and medium-sized computer systems.

When will the segment fault appear? What are the mechanisms in the kernel?

Professional explanation Please refer to ULK3 page376: Fault handling program, brother now not how to understand.

What is a hash table used for?

Hash tables are also called hash lists, which group data according to key value for quick insertion and lookup

What is the implementation principle of the. core file?

Please refer to this blog:

http://blog.csdn.net/xuzhina/article/category/1322964

This dude wrote dozens of articles about core dump principles, and I'm not c-c,c-v here.

If the interviewer asks, say so (see http://www.cnblogs.com/hazir/p/linxu_core_dump.html):

when the program runs abnormally terminates or crashes, the operating system records the memory state of the program and saves it in a file, a behavior called Core Dump (translated into "core dumps" in Chinese). We can assume that core dump is a "memory snapshot", but in fact, in addition to the memory information, there are some key program run states also dump down, such as register information (including program pointers, stack pointers, etc.), memory management information, other processor and operating system status and information. Core dump is very helpful for programmers to diagnose and debug programs, because some program errors can be difficult to reproduce, such as a pointer exception, and the core dump file reproduces the scenario when the program goes wrong.

18.fork return 0 and greater than 0 are processes respectively?

the return value of 0 is a child process, the return value greater than 0 is the parent process, and the return value greater than 0 is the process number of the child process. Error Return-1
Function Description: An existing process can call the fork function to create a new process. A new process created by Fork is called a subprocess (child process). The fork function is called once but returns two times. The only difference of two returns is that the child process ID is returned in the parent process with a value of 0. A child process is a copy of the parent process that obtains a copy of the parent process's data space, heap, stack, and so on. Note that the child process holds a "copy" of the above storage space, which means that the storage space is not shared between parent and child processes, and that only the code snippets are shared between them.

What is the heap and stack used to do when the program executes?

BSS segment Data segment text segment heap heap and stack stack

BSS segment: BSS segment (BSS segment)usually refers to a program that is used to storeUninitialized Global Variablesarea of memory. BSS is the abbreviation for English block Started by symbol. BSS segments belong to static memory allocations.
  
Data segment: Data segmentusually refers to a program that is used to storeInitialized Global Variablesarea of memory. The data segment belongs to static memory allocation.
  
Code Snippet: Snippet (code segment/text segment)usually refers to aStore program execution Codearea of memory. The size of this area is determined before the program runs, and the memory area is usually read-only, and some schemas allow the code snippet to be writable, which allows the program to be modified. In a code snippet, it is also possible to include some read-only constant variables, such as String constants.
  
Heap:heaps are used tostores the memory segments that are dynamically allocated during a process run, its size is not fixed, can be dynamically expanded or reduced. When the process callsmallocWhen the function allocates memory, the newly allocated memory is dynamically added to the heap (the heap is expanded), and the freed memory is removed from the heap (heap is scaled down) when the memory is freed using functions such as free
  
Stacks (Stack): Stacks are also called stacks,is a local variable created temporarily by the user store program, that is, the variables defined in the parentheses "{}" (but not the static declared variables, static means that the variables are stored in the data segment). In addition, when a function is called, its arguments are also pressed into the process stack that initiates the call, and the return value of the function is stored back to the stack when the call ends. Due to the advanced first-out features of the stack, the stack is particularly handy for saving/recovering call sites. In this sense, we can think of the stack as a memory area where temporary data is stored and exchanged.

What are the differences between threads and processes?

(http://www.cnblogs.com/flashsky/articles/642720.html)

A thread is an execution unit within a process and a scheduler within a process.
Differences from the process:
(1) Address space: The address space of the thread sharing process, and the process has its own independent address space;
(2) Resource ownership: A resource for a thread-sharing process, which is a resource allocation and owned unit
(3) The thread is the basic unit of the processor dispatch, but the process is not.
4) Both can be executed concurrently.

Further expansion:

Processes and threads are the basic units that the operating system realizes, and the system uses this basic unit to realize the concurrency of the system to the application. The difference between a process and a thread is:

In short, a program has at least one process, and a process has at least one thread.
The thread's dividing scale is smaller than the process, which makes the multi-thread procedure high concurrency.
In addition, the process has a separate memory unit during execution, and multiple threads share memory, which greatly improves the efficiency of the program operation.
Threads are still different from the process during execution. Each separate thread has a program run entry, sequence of sequence execution, and exit of the program. However, threads cannot be executed independently, and must be dependent on the application, which provides multiple threads of execution control.
From a logical point of view, the meaning of multithreading is that in an application, multiple execution parts can be executed concurrently. However, the operating system does not consider multiple threads as separate applications to implement scheduling and management of processes and resource allocation. This is the important difference between processes and threads.

A process is a program with a certain independent function about a single run activity on a data set, a process that is an independent unit of the system's resource allocation and scheduling.
A thread is an entity of a process that is the basic unit of CPU dispatch and dispatch, which is a smaller unit that can run independently than a process. The thread itself basically does not own the system resources, only has a point in the operation of the necessary resources (such as program counters, a set of registers and stacks), However, it can share all of the resources owned by the process with other threads that belong to one process.
One thread can create and revoke another thread, and can execute concurrently between multiple threads in the same process.

How many questions can you answer about Linux? --Answer 14-20 questions

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.