当前位置:网站首页>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 .
边栏推荐
- Pycharm package import error without warning
- Multipass Chinese document - remove instance
- 天才制造者:獨行俠、科技巨頭和AI|深度學習崛起十年
- LISP programming language
- Machine learning final exercises
- Basic query
- Wechat applet exits the applet (navigator and api--wx.exitminiprogram)
- Condition query
- ModuleNotFoundError: No module named ‘numpy‘
- Some parameter settings and feature graph visualization of yolov5-6.0
猜你喜欢

A new paradigm for large model application: unified feature representation optimization (UFO)

Mise en œuvre du routage dynamique par zuul

Nabicat连接:本地Mysql&&云服务Mysql以及报错

Dameng database backup and restore

1.12 learning summary
![[H5 development] 02 take you to develop H5 list page ~ including query, reset and submission functions](/img/39/64df931d5ec54d7d19ae444fa372ba.jpg)
[H5 development] 02 take you to develop H5 list page ~ including query, reset and submission functions

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

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

Image translation /gan:unsupervised image-to-image translation with self attention networks

86.(cesium篇)cesium叠加面接收阴影效果(gltf模型)
随机推荐
Dameng database backup and restore
Stm8 MCU ADC sampling function is triggered by timer
2022.2.11
MySql如何删除所有多余的重复数据
Interpretation of yolov5 training results
Multipass Chinese document - use instance command alias
Condition query
5. <tag-栈和常规问题>补充: lt.946. 验证栈序列(同剑指 Offer 31. 栈的压入、弹出序列)
Multipass中文文档-提高挂载性能
dijkstra
NVM installation and use and NPM package installation failure record
Nabicat连接:本地Mysql&&云服务Mysql以及报错
PSIM software learning ---08 call of C program block
1.14 learning summary
2022.2.13
Multipass Chinese document - remote use of multipass
Multipass Chinese documents - improve mount performance
2022.1.23
[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
Multipass中文文档-使用实例命令别名