当前位置:网站首页>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 .
边栏推荐
- 天才制造者:独行侠、科技巨头和AI|深度学习崛起十年
- pycharm 导包错误没有警告
- 1.18 learning summary
- How MySQL deletes all redundant duplicate data
- #微信小程序# 在小程序里面退出退出小程序(navigator以及API--wx.exitMiniProgram)
- 超高精度定位系统中的UWB是什么
- MySql如何删除所有多余的重复数据
- 22.2.8
- BACK-OFF RESTARTING FAILED CONTAINER 的解决方法
- [ide (imagebed)]picgo+typora+aliyunoss deployment blog Gallery (2022.6)
猜你喜欢
PowerShell runtime system IO exceptions
Schematic diagram of UWB ultra high precision positioning system
Pycharm package import error without warning
torchvision_ Transform (image enhancement)
What is UWB in ultra-high precision positioning system
PSIM software learning ---08 call of C program block
Use fill and fill in Matplotlib_ Between fill the blank area between functions
天才制造者:獨行俠、科技巨頭和AI|深度學習崛起十年
1.19 learning summary
Differences between TCP and UDP
随机推荐
Hash problem
One of token passing between microservices @feign's token passing
PowerShell runtime system IO exceptions
5. <tag-栈和常规问题>补充: lt.946. 验证栈序列(同剑指 Offer 31. 栈的压入、弹出序列)
2022.2.13
1.18 learning summary
一个从坟墓里爬出的公司
Multipass Chinese document - use packer to package multipass image
Pycharm package import error without warning
LeetCode 19. 删除链表的倒数第 N 个结点
Multipass Chinese document - remote use of multipass
文件上传与安全狗
Schematic diagram of UWB ultra high precision positioning system
Record a circular reference problem
pycharm 导包错误没有警告
YOLOV5训练结果的解释
ModuleNotFoundError: No module named ‘numpy‘
Créateur de génie: cavalier solitaire, magnat de la technologie et ai | dix ans d'apprentissage profond
[H5 development] 03- take you hand in hand to improve H5 development - single submission vs batch submission with a common interface
1.16 learning summary