当前位置:网站首页>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 .
边栏推荐
- Comment enregistrer une image dans une applet Wechat
- Image translation /gan:unsupervised image-to-image translation with self attention networks
- 1.11 learning summary
- Tips for using idea
- One of token passing between microservices @feign's token passing
- 钟珊珊:被爆锤后的工程师会起飞|OneFlow U
- Solution to back-off restarting failed container
- Svn error command revert error previous operation has not finished; run ‘ cleanup‘ if
- Sklearn Library -- linear regression model
- 5. < tag stack and general problems > supplement: lt.946 Verify the stack sequence (the same as the push in and pop-up sequence of offer 31. stack)
猜你喜欢

1.24 learning summary

2.< tag-动态规划和常规问题>lt.343. 整数拆分

A company crawling out of its grave

Statsmodels Library -- linear regression model

图像翻译/GAN:Unsupervised Image-to-Image Translation with Self-Attention Networks基于自我注意网络的无监督图像到图像的翻译

1.17 learning summary

5. < tag stack and general problems > supplement: lt.946 Verify the stack sequence (the same as the push in and pop-up sequence of offer 31. stack)

Guanghetong and anti international bring 5g R16 powerful performance to the AI edge computing platform based on NVIDIA Jetson Xavier nx

钟珊珊:被爆锤后的工程师会起飞|OneFlow U

2.9 learning summary
随机推荐
1.20 learning summary
Dbeaver installation and configuration of offline driver
86. (cesium chapter) cesium overlay surface receiving shadow effect (gltf model)
JWT token authentication verification
一个从坟墓里爬出的公司
ROS notes (07) - Implementation of client and server
微服务之间的Token传递之一@Feign的token传递
Is education important or ability important in software testing
DBeaver 安装及配置离线驱动
图像翻译/GAN:Unsupervised Image-to-Image Translation with Self-Attention Networks基于自我注意网络的无监督图像到图像的翻译
Comment enregistrer une image dans une applet Wechat
Essential foundation of programming - Summary of written interview examination sites - computer network (1) overview
MySql如何删除所有多余的重复数据
2.< tag-动态规划和常规问题>lt.343. 整数拆分
Dameng database backup and restore
Difference between return and yield
ModuleNotFoundError: No module named ‘numpy‘
2022.2.16
Hash problem
Modify the case of the string title(), upper(), lower()