当前位置:网站首页>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 class
Realization Runnable Interface
Realization 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 pool
newFixedThreadPoo
: 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 + taskkil
l Order to kill the process . As follows :jps taskkill /F /PID 33736 (F It's a strong kill )
linux
ps -fe
View 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 memory
ps -fT -p <PID>
Look at a process (PID) All threads ofkill
Kill processtop In capitals H
Toggles whether threads are displayedtop -H -p <PID>
Look at a process (PID) All threads ofJava
Be careful : Need to go to the corresponding
java\lib
Run belowjsp
View all Java commandjstack<PID>
View a certain Java process (PID) Status of all threadsjconsole
View 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
边栏推荐
- Check log4j problems using stain analysis
- Win10+vs2019 Community Edition compiling OpenSSL
- Penetration practice vulnhub range Nemesis
- 徽商期货是正规期货平台吗?在徽商期货开户安全吗?
- Yolov5 practice: teach object detection by hand
- The method of real-time tracking the current price of London Silver
- Is it safe to open a stock account by mobile phone? What do you need to bring with you to open an account?
- Equipment simulation and deduction training system software
- Setting up a time server requires the client to automatically synchronize the time of the server at 9 a.m. every day
- Common design parameters of solid rocket motor
猜你喜欢
Definition of rotation axis in mujoco
. Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes
Set the style of QT property sheet control
Heavy disclosure! Hundreds of important information systems have been invaded, and the host has become a key attack target
How to use JMeter function and mockjs function in metersphere interface test
Penetration practice vulnhub range Nemesis
ACM mm 2022 video understanding challenge video classification track champion autox team technology sharing
Thinkphp6 - CMS multi wechat management system source code
Fresh, 2022 advanced Android interview must know 100 questions (interview questions + answer analysis)
Explain in detail the process of realizing Chinese text classification by CNN
随机推荐
Cassette helicopter and alternating electric field magnetic manometer DPC
Zabbix报警执行远程命令
The latest intelligent factory MES management system software solution
Apache iceberg source code analysis: schema evolution
Penetration practice vulnhub range Tornado
Basic usage of shell script
Is online stock account opening safe? Is it reliable?
Record 3 - the state machine realizes key control and measures the number of external pulses
golang中的select详解
SCP -i private key usage
Small exercise -- subnet division and summary
ACL 2022 | decomposed meta learning small sample named entity recognition
Mujoco XML modeling
Talk about the favorite tools used by project managers
Is it safe to open an ETF account online? What are the steps?
Intel's open source deep learning tool library openvino will increase cooperation with local software and hardware parties and continue to open
ACM mm 2022 video understanding challenge video classification track champion autox team technology sharing
徽商期货是正规期货平台吗?在徽商期货开户安全吗?
Work and leisure suggestions of old programmers
Htt [ripro network disk link detection plug-in] currently supports four common network disks