(1) The parent process first At the end of the child process, the child process becomes an orphan process.
(2) Linux system regulations: All orphan processes become child processes of a special process (process 1, which is the init process).
(1) .bss
section: stores uninitialized global variables and static variables that are initialized to 0.
(2).data
section: stores global variables, static variables, and const constants that are not initialized to 0.
Programmer In the program, malloc is used to dynamically apply for memory from the heap space of the virtual memory, and free is used to release the memory. If the program has a large number of malloc/free operations and runs for a long time, the heap space of the virtual memory can easily cause memory fragmentation
Memory fragmentation means that there is a lot of discrete free memory left in the heap space, but it cannot satisfy malloc's allocation request. Memory fragmentation is divided into external fragmentation and internal fragmentation. The following figure describes the memory allocation of part of the heap space. The heap space is divided into many allocation blocks in units of 4 bytes. The white blocks represent free memory, and the light blue and dark blue blocks represent allocated memory. Assume that the smallest unit of memory allocation is an allocation block (4 bytes).
Stack: automatically allocated by the system
Heap: Manual application by the programmer
Stack: The memory size of the stack area is fixed, as long as If the requested memory is less than the remaining memory in the stack area, the allocation can be successful, otherwise the stack will overflow.
Heap: The memory size of the heap area is determined by the computer’s virtual memory,
(1) Semaphores are used for thread synchronization, and mutex locks are used for thread mutual exclusion.
(2) The semaphore can be a non-negative integer, which can realize multi-thread synchronization of multiple similar resources; the mutex can only be 0/1, which can only be used for mutually exclusive access to one resource.
(3) The semaphore can be released by one thread and obtained by another thread; the locking and unlocking of the mutex must be used by the same thread respectively, and attention must be paid to the use of multiple mutexes by multiple threads Unify the order, otherwise deadlock may occur.
What is deadlock Lock? What causes deadlock?
(1) Deadlock refers to a deadlock (waiting for each other) caused by multiple processes competing for resources. Without external force, these processes will not be able to move forward.
(2) Reason: ① Insufficient system resources. ② Improper allocation of resources. ③The order of process advancement is inappropriate.
What are the four necessary conditions for deadlock?
(1)Mutual exclusion condition: A resource can only be used by one process at a time, and other processes can only wait.
(2)Request and retention conditions: The process has obtained at least one resource, but has made a new resource request, and the resource has been occupied by other processes. At this time, the process is Blocking, but still holding on to the acquired resources.
(3)Nondeprivation condition: The resources obtained by the process cannot be deprived by other processes and can only be released by itself.
(4)Loop waiting condition: Several processes form a relationship of cyclic waiting for resources end to end.
Note: The above four conditions are indispensable.
How to deal with deadlock?
(1) Prevent deadlock: By setting some restrictions, destroy the necessary conditions for deadlock.
(2) Avoid deadlock: During the resource allocation process, use some method to prevent the system from entering an unsafe state, thereby avoiding deadlock.
(3) Detect and remove deadlock: Allow deadlock to occur, but after passing the system detection, take some measures to clear the deadlock.
How to prevent deadlock?
(1)Destroy the "request and hold conditions":
①Static allocation, that is, each process applies for all the resources it needs when it starts executing:
②Dynamic allocation, that is, each process does not occupy the system when it applies for the resources it needs resource.
(2)Destroy the "inalienable condition": During a process's blocking and waiting period, the resources it occupies are implicitly released and then used by other processes, while the blocked and waiting resources can only be obtained All resources required to restart.
(3)Destroy the "cyclic waiting condition": Adopt the orderly allocation of resources, number all resources, use relatively large numbers for scarce resources, and a process can only obtain a smaller number. Only resources with larger numbers can apply for resources with larger numbers
The above is the detailed content of Operating system interview high-frequency test points. For more information, please follow other related articles on the PHP Chinese website!