当前位置:网站首页>Operating system interview assault
Operating system interview assault
2022-07-01 18:19:00 【Xiao Zhu, Xiao Zhu will never admit defeat】
This article is a summary of some frequently asked interview questions in the operating system .
Other interview knowledge points are sorted out by surprise :
List of articles
- One 、 Processes and threads
- 1. process 、 Threads and collaborations
- 2. What are the states of a process ?
- 3. Several ways of communication between processes
- 4. Threads have several States ?
- 5. How to create threads
- 6. Runnable、Callable、Future Similarities and differences
- 7. run() and start() difference
- 8. guardian 、 User threads
- 9. See how the thread runs
- 10. Thread synchronization
- 11. What is context switching
- 12. How to reduce context switching
- 13. Thread scheduling strategy
- 14. Thread scheduler
- 15. Process scheduling policy ?
- 16. Mechanism of process synchronization
- 17. What is a deadlock ? The condition of deadlock ?
- Two 、 Storage
One 、 Processes and threads
1. process 、 Threads and collaborations
process Is the encapsulation of the runtime program , yes The basic unit of the system for resource scheduling and allocation , The concurrency of the operating system is realized ;
Threads Is a subtask of a process , yes CPU Basic unit of dispatch and dispatch , Used to ensure the effectiveness of the program The real time , Achieve concurrency within the process ;
A program has at least one process , A process has at least one thread , Threads depend on the process ;
Processes have independent memory units during execution , Multiple threads share the memory of the process .
coroutines : More lightweight than threads , Not managed by the operating system kernel , It's completely controlled by the program .
A program is interruptible within a subroutine , Turn to other subroutines , Come back at the right time and carry out .
benefits
Performance improvement , It doesn't consume resources like thread switching .
Mechanisms that do not require multithreaded locks , Because there's only one thread , There is no simultaneous write variable conflict . Therefore, control the shared resources in the collaboration process without locking , Just judge the status , Therefore, the execution efficiency is much higher than that of threads .
2. What are the states of a process ?
Ready state : The process has obtained the required resources other than the processor , Waiting to allocate processor resources ;
Running state : Occupy processor resources to run , The number of processes in this state is less than or equal to CPU Count ;
Blocked state : The process waits for some condition , Cannot execute... Until the conditions are met ;
3. Several ways of communication between processes
The Conduit (pipe) And named pipes (named pipe): Pipes can be used for communication between parent-child processes that have affinity , Famous pipeline In addition to the functions of the pipeline , It also allows Communication between unrelated processes ;
The signal (signal): Signal is a kind of complex communication mode , Used to notify the receiving process that an event has occurred ;
Message queue : Message queues are linked tables of messages , It overcomes the limitation of the signal quantity in the above two communication modes , Processes with write permission can add new information to the message queue according to certain rules ; Processes that have read access to the message queue can read information from the message queue ;
Shared memory : It can be said that this is The most useful way of interprocess communication . It allows multiple processes to access the same memory space , Different processes can timely see the other process in the shared memory data update . This approach relies on some kind of synchronization , Such as mutexes and semaphores ;
Semaphore : Mainly as a means of synchronization and mutual exclusion between processes and different threads of the same process ;
Socket : This is a more general inter process communication mechanism , It can be used for inter process communication between different machines in the network , Very widely used .
4. Threads have several States ?
newly build (NEW): A new thread object is created .Can run (RUNNABLE): After the thread object is created , Other threads ( such as main Threads ) Called the object's start() Method . The thread in this state is in the runnable thread pool , Waiting to be selected by thread scheduling , obtain cpu Right to use .function (RUNNING): Operational state (runnable) The thread of the cpu Time slice (timeslice) , Execute program code .Blocking (BLOCKED): Blocking state refers to the thread giving up for some reason cpu Right to use , That is to say, to give up cpu timeslice, Stop running temporarily . Until the thread becomes runnable (runnable) state , To have another chance to get cpu timeslice Go to run (running) state . There are three types of obstruction :( One ).
Waiting for a jam: function (running) Thread execution of o.wait() Method ,JVM The thread will be put into the waiting queue (waitting queue) in .( Two ).
Synchronous blocking: function (running) When the thread of gets the synchronization lock of the object , If the synchronization lock is held by another thread , be JVM The thread will be put into the lock pool (lock pool) in .( 3、 ... and ).
Other blockages: function (running) Thread execution of Thread.sleep(long ms) or t.join() Method , Or send out I/O When asked ,JVM It puts the thread in a blocking state . When sleep() Status timeout 、join() Wait for the thread to terminate or timeout 、 perhaps I/O When it's done , The thread goes back to runnable (runnable) state .Death (DEAD): Threads run()、main() Method execution ends , Or quit because of an exception run() Method , The thread ends its life cycle . Dead threads cannot be reborn .
5. How to create threads
There are four ways to create threads :
Inherit Thread classRealization Runnable InterfaceRealization Callable Interface: practice : Rewrite first Call Method , When starting a thread , Need to create a new one Callable Example , Reuse Future Task Instance wrap it , Finally, it is packaged into Thread example , call start Method start up .Use Executors Tool class creates thread poolnewFixedThreadPoo: Fixed size thread poolnewCachedThreadPool: Buffered thread poolnewSingleThreadExecutor: Single-threaded thread poolnewScheduledThreadPool: Task scheduling thread poolForkJoinPool: Divide and conquer thread pool
6. Runnable、Callable、Future Similarities and differences
The same thing :
- It's all interfaces
- Can write multithreaded programs
- All use Thread.start() Start thread
Difference :
Runnable Interface run Method has no return value . Callable Yes, After being executed by thread , Can return value , This return value can be Future Get .Future Represents an asynchronous task , It is the result of an asynchronous task that may not have been completed .
therefore :Callable Used to produce results ,Future Used to get results
FutureTask: Represents an asynchronous operation task , It can be introduced into Callable Concrete implementation class , You can wait for the results of this asynchronous operation task , Judge whether it has been completed , Cancel tasks, etc .
Runnable Interface run Only run when an exception is thrown , And can't capture processing ;Callable Interface call Method allows exception to be thrown, And you can get abnormal information .
7. run() and start() difference
- start() Method to start a thread ,run() Method is used to execute the thread's runtime code , It is called thread body .
- run() Just an ordinary function in a thread , Can be called repeatedly , and start() It can only be called once
summary : call start Method can start a thread and put it into a ready state , and run Method knowledge thread A normal method call of , Or in the main thread .
8. guardian 、 User threads
User threads : Run in the foreground , Carry out specific tasks , Such as the main thread of the program , All the sub threads connected to the network are user threads .
The guardian thread : Running in the background , For other foreground threads . Once all user threads have finished running , The daemons will follow JVM Finish the work together .( Such as garbage collection thread )
9. See how the thread runs
Windows
Task manager view or Kill
open cmd Command line window , Use
tasklist + taskkill Order to kill the process . As follows :jps taskkill /F /PID 33736 (F It's a strong kill )linux
ps -feView all processesID、 current state 、 Starting time 、 Occupy CPU Time 、CPU Percentage occupied 、 Percentage of memory used 、 The size of the occupied virtual memory 、 Size of resident memoryps -fT -p <PID>Look at a process (PID) All threads ofkillKill processtop In capitals HToggles whether threads are displayedtop -H -p <PID>Look at a process (PID) All threads ofJava
Be careful : Need to go to the corresponding
java\libRun belowjspView all Java commandjstack<PID>View a certain Java process (PID) Status of all threadsjconsoleView a certain Java The operation of threads in the process ( The graphical interface )
10. Thread synchronization
The mutex Synchronized/Lock: Adopt mutually exclusive object mechanism , Only threads with mutexes have access to public resources . Because there's only one mutex , So it can ensure that the public resources will not be accessed by multiple threads at the same time
Semaphore Semphare: It allows multiple threads to access the same resource at the same time , But you need to control the maximum number of threads accessing this resource at the same time
event ( The signal ),Wait/Notify: Keep multithreading synchronized by notifying operations , It can also easily realize the comparison operation of multithread priority
11. What is context switching
12. How to reduce context switching
13. Thread scheduling strategy
14. Thread scheduler
15. Process scheduling policy ?
16. Mechanism of process synchronization
17. What is a deadlock ? The condition of deadlock ?
1) The concept of deadlock
2) Deadlock occurs
3) Deadlock handling
4) Positioning deadlocks
Two 、 Storage
1. What's the difference between pagination and segmentation ?
1) Segment storage management
2) Page storage management
3) Difference between the two
2. What is virtual memory ?
1) The history of memory development
2) Virtual memory
3) Page replacement algorithm
4) The application and advantages of virtual memory
3. Bumpy / shake
4. Locality principle
Reference resources :
The operating system has been completely —— Double non landing Alibaba series
interview / The second bullet of the written test —— Operating system interview question collection
边栏推荐
- Is it safe to open a stock account by mobile phone? What do you need to bring with you to open an account?
- golang中的select详解
- Flex layout
- t10_ Adapting to Market Participantsand Conditions
- Can hero sports go public against the wind?
- What are the six steps of the software development process? How to draw software development flow chart?
- New patent applications and transfers
- 股票万1免5证券开户是合理安全的吗,怎么讲
- Blackwich: the roadmap of decarbonization is the first step to realize the equitable energy transformation in Asia
- Thinkphp6 - CMS multi wechat management system source code
猜你喜欢

transform. Forward and vector3 Differences in the use of forward

Intel's open source deep learning tool library openvino will increase cooperation with local software and hardware parties and continue to open

Happy new year | 202112 monthly summary

Common design parameters of solid rocket motor

Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash

Petrv2: a unified framework for 3D perception of multi camera images

What impact will multinational encryption regulation bring to the market in 2022

Fresh, 2022 advanced Android interview must know 100 questions (interview questions + answer analysis)

Apache iceberg source code analysis: schema evolution

Work and leisure suggestions of old programmers
随机推荐
[splishsplash] about how to receive / display user parameters, MVC mode and genparam on GUI and JSON
The method of real-time tracking the current price of London Silver
Mujoco model learning record
手机开户股票开户安全吗?那么开户需要带些什么?
Setting up a time server requires the client to automatically synchronize the time of the server at 9 a.m. every day
Batch export all pictures in PPT in one second
Mujoco's biped robot Darwin model
传感器尺寸、像素、DPI分辨率、英寸、毫米的关系
Development cost of smart factory management system software platform
To improve the efficiency of office collaboration, trackup may be the best choice
t10_ Adapting to Market Participantsand Conditions
Slider verification code identification gadget display
JS how to convert a string with a delimiter into an n-dimensional array
June issue | antdb database participated in the preparation of the "Database Development Research Report" and appeared on the list of information technology and entrepreneurship industries
Equipment simulation and deduction training system software
Key points on February 15, 2022
Apk signature process introduction [easy to understand]
EasyCVR设备录像出现无法播放现象的问题修复
证券开户安全么,有没有什么样的危险呢
Good looking UI mall source code has been scanned, no back door, no encryption