当前位置:网站首页>Status of processes and communication between processes
Status of processes and communication between processes
2022-06-26 04:59:00 【The story of Ula】
State of process :
In the process of running the program , Because the scheduling algorithm of the operating system controls , The program goes into several States : be ready , Running and blocking . Process status shows the change of process execution , These states change with process execution and external conditions . The life cycle of a process can be divided into a set of States , These depict the whole process . Process state is the life state of a process .
1. be ready (Ready):
The process has obtained the required resources other than the processor , Just waiting to allocate resources , As long as the processor is allocated, the process can execute .
The readiness process can be queued by multiple priorities , for example : When a process is ready due to running out of time , Queued to priority . When the process consists of I/O operation When finished and in the ready state , High priority queue .
2. function (Running):
The process occupies processor resources , The number of processes in this state is less than or equal to the number of processors , When no other process can execute ( For example, all processes are in a blocking state ), The system usually automatically executes idle processes of the system .
3. Blocking (Blocked):
The system waits for a condition due to a process ( Such as I/O Operation or process synchronization ), Cannot continue until conditions are met . Even if the processor resources are allocated to the process before this event occurs , The process cannot continue .
State transition :
be ready ------> perform :
A process in a ready state , When the process scheduler has allocated processors , The process changes from ready state to execution state . When the running process is blocked , The scheduler selects a process with the highest priority to occupy the processor .
perform ------> be ready :
A process in an execution state is in its execution , He had to give up the processor because one of the event slices assigned to him had run out , So the process changes from the execution state to the ready state .
perform ------> jam :
When an executing process cannot continue because it is waiting for an event to occur , It changes from the execution state to the blocking state .
jam ------> be ready :
A blocked process , If the event it is waiting for has happened , So the process changes from a blocked state to a ready state .
Communication between processes ——Queue:
We know the process multiprocessing Modular Queue Implement data transfer between multiple processes ,Queue It's a message queuing program .
put() Method :
from multiprocessing import Queue(3)
# Create a queue , Specify the maximum capacity , If not specified, it is infinite .
q = put("A")
q = puy("B")
q = put("C")
# The queue is full , At this point the program will be blocked , Until it leaves the space
q = put("D")
get() Method :
from multiprocessing import Queue(3)
# Create a queue , Specify the maximum capacity , If not specified, it is infinite .
q = put("A")
q = puy("B")
q = put("C")
# The queue is full , At this point the program will be blocked , Until it leaves the space
q = put("D")
q = get() # "A"
q = get() # "B"
q = get() # "C"
# The queue is empty , Program blocking , Until new data is added
q =get()
Use Queue:
Write two child processes in the parent process , A write operation , A read .
from multiprocessing import Process, Queue
import time
import random
# Write data process
def write(q):
for value in ["A", "B", "C"]:
print(" write in %s Into the Queue.." % value)
q.put(value)
time.sleep(random.random())
# Data reading process
def read(q):
while True:
if not q.empty():
value = q.get()
print(" obtain %s stay Queue" % value)
time.sleep(random.random())
else:
break
if __name__ == '__main__':
# Parent process creation Queue, To each subprocess
q = Queue()
pw = Process(target=write, args=(q,))
pr = Process(target=read, args=(q,))
# Start subprocess
pw.start()
# Wait for the subprocess that writes the data to end
pw.join()
pr.start()
pr.join()
print(" All data is written and read ")
q.qsize(), Get queue length ( The amount of data in the queue )
get_nowait() Throw exceptions
empty() Determine whether the queue is empty True Means empty
full() Determine whether the queue is full 
You can't be too low , Because my father once held you above his head .
边栏推荐
- 2022.2.11
- Is education important or ability important in software testing
- Modify the case of the string title(), upper(), lower()
- 1.24 learning summary
- [H5 development] 01 take you to experience H5 development from a simple page ~ the whole page implementation process from static page to interface adjustment manual teaching
- How MySQL deletes all redundant duplicate data
- 6.1 - 6.2 公钥密码学简介
- 22.2.8
- ModuleNotFoundError: No module named ‘numpy‘
- Multipass Chinese document - remove instance
猜你喜欢

2022.1.24

1.18 learning summary

Why do many Shopify independent station sellers use chat robots? Read industry secrets in one minute!

Record a circular reference problem
![[H5 development] 03- take you hand in hand to improve H5 development - single submission vs batch submission with a common interface](/img/37/84b7d59818e854dac71d6f06700cde.jpg)
[H5 development] 03- take you hand in hand to improve H5 development - single submission vs batch submission with a common interface

File upload and security dog

广和通联合安提国际为基于英伟达 Jetson Xavier NX的AI边缘计算平台带来5G R16强大性能

Machine learning final exercises

1.19 learning summary

图像翻译/GAN:Unsupervised Image-to-Image Translation with Self-Attention Networks基于自我注意网络的无监督图像到图像的翻译
随机推荐
Is education important or ability important in software testing
YOLOv5-6.0的一些参数设置和特征图可视化
Problem follow up - PIP source change
BACK-OFF RESTARTING FAILED CONTAINER 的解决方法
Yolov5 super parameter setting and data enhancement analysis
6.1 - 6.2 公鑰密碼學簡介
0622-马棕榈跌9%
Using Matplotlib to add an external image at the canvas level
22.2.8
[H5 development] 01 take you to experience H5 development from a simple page ~ the whole page implementation process from static page to interface adjustment manual teaching
1.20 learning summary
Guanghetong and anti international bring 5g R16 powerful performance to the AI edge computing platform based on NVIDIA Jetson Xavier nx
Zuul 實現動態路由
Svn error command revert error previous operation has not finished; run ‘ cleanup‘ if
Floyd
1.16 learning summary
Why do many Shopify independent station sellers use chat robots? Read industry secrets in one minute!
2022 talent strategic transformation under the development trend of digital economy
numpy 随机数
202.2.9