Operating system interview questions

Source address: https://blog.csdn.net/zhou753099943/article/details/51771220
1. What is the difference between a process and a thread?
Analysis: (1) Process is an independent unit of resource allocation and scheduling, while thread is the basic unit of CPU scheduling
          (2) The same process can include multiple threads, and the threads share the resources (registers, stacks, and contexts) of the entire process, and one process includes at least one thread.
          (3) The creation of the process calls fork or vfork, and the creation of the thread calls pthread_create. After the process ends, all threads it owns will be destroyed, and the end of the thread will not affect the end of other threads in the same process.
          (4) A thread is a two-level light process. Its creation and destruction take much less time than a process. All execution functions in the operating system are performed by creating threads.
          (5) Synchronization and mutual exclusion are generally required when executing in threads, because they share all the resources of the same process
          (6) Threads have their own private attributes TCB, thread id, registers, hardware context, and processes also have their own private attributes process control block PCB, these private attributes are not shared, and are used to mark the flag of a process or a thread
2. Deadlock? Cause of deadlock? Necessary for deadlock? How to deal with deadlock?
Analysis: (--) A deadlock state caused by mutual waiting for resources, if there is no external intervention, this state will continue forever
          (--) Insufficient system resources, competing resources, and inappropriate order of requested resources
          (2) Mutual exclusion, non-preemption, circular waiting, request and hold
          (3) Because mutual exclusion is immutable, only one of the other three conditions can be destroyed to release the deadlock. Methods: deprive resources and kill one of the threads
3. Windows memory management methods: segment storage, page storage, segment page storage
Parse:
4. What are the states of the process?
Analysis: (1) run (running state): a running process or a process being treated in a waiting queue, the waiting process can run as long as it gets the CPU
          (2) Sleep (interruptible sleep state): equivalent to blocking or waiting
          (3) D (uninterruptible sleep state): process on disk
          (4) T (stop state): This state cannot be seen intuitively, because resources are released after the process stops, so it will not stay in linux
          (5) Z (zombie state): The child process ends with the parent process first, but the parent process does not call wait or waitpid to recycle the resources of the child process, so the child process becomes a zombie process. process resources, then process No. 1 will recycle
5. What is the IPC communication method?
Parsing: (1) Pipes (anonymous pipes (process communication of pipe affinity), named pipes (mkfifo/mknod))
          (2) Message queue: It is message-based and uses unrelated inter-process communication. Main functions: msgget, msgsend, msgrecv, msgctl
          (3) Semaphore: equivalent to a mutex, operated by p, v, main functions: semget, semop, semctl
          (4) Shared memory: It is the fastest inter-process communication, so it is often a set semaphore or mutex to achieve synchronization, shmget, shmat, shmdt, shmctl
6. What is virtual memory?
Analysis: It is to load the process part into the memory, so that a large program can run in a memory smaller than it. Its main implementation is realized by swapping in and out of the program, because 0~ 3G is used by users, 3~4G is used by memory, and the mapping from logical addresses to physical addresses is realized by mapping.
 
7. What is the difference between virtual address, logical address, linear address and physical address?
Resolution: The segmentation mechanism converts a logical address to a linear address; then, the paging mechanism converts a linear address to a physical address.
(1) Virtual address: the address mapped from virtual memory
(2) Logical address: The segment of the program is formed by adding an offset. The address obtained by taking the address in the C/C++ program is the logical address.
(3) Linear address: It is the intermediate layer from logical address to physical address. Linear address is only available when paging mechanism is enabled. If there is no paging mechanism, then linear address is physical address.
(4) Physical address: It is the actual hardware address in memory,
Logical address (start segment) --> linear address (start paging) --> physical address

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325074322&siteId=291194637