Last week learning content review

1.Tcp stick package problem

2.udp

Difference: non-stick package, is not reliable, high transmission efficiency, for small amount of data transmission, data transmission is not required to establish a link sequence does not require

Usage scenarios, requirements of high speed, but less demanding data integrity, DNS, arcade game

Network Programming: currently unable to handle multiple concurrent clients

process:

A program called the running process

Process from the operating system

In the third-generation operating system, the birth of technology to more than

Multi-channel technology in order to improve the utilization of computer resources, is the third generation before walking through batch processing mode to perform tasks

Spatial multiplexing

A plurality of data programs stored in the same period in memory

Memory area to be isolated from each other, physical isolation, you are not freely accessible

Time-multiplexed

Switching + Save

When a process encounters an IO operation, they switch to another process to execute, to record the state of the currently running before switching

Switching conditions:

IO operation encountered

Running time is too long, time slice runs out

When to start a process

When performing a task, execution time is too long, in order to improve efficiency, we can use this task to the child process to complete

The difference between Linux and Windows to open a child process

linux 会把数据完整copy给子进程 ,作为子进程的初始状态
windows 会重新导入父进程的代码来获取需要数据,这样一来创建进程的代码又被执行了一次,造成递归创建进程
所以要将开启子进程的代码放到 if __name__ == "__main__":中 保证创建进程的代码只被父进程执行
如何开启子进程
1.导入 multiprocessing 中的 Process
实例化Process类 用target来指定要执行任务函数
调用start来开启进程
2.创建一个类,继承Process,覆盖run方法,将任务代码放到run中

进程之间内存相互隔离

僵尸进程 有害
子进程结束了,父进程还在运行,子进程会占用pid 并且将保留最后的运行状态在内存中
在linux中 父进程需要调用wait/waitpid来获取子进程的残留信息,并清理它
python中已经封装好了 wait 操作不需要我们自己来清理

如果出现很多僵尸进程
清除僵尸进程的方法就是 杀死父进程

孤儿
父进程已经挂了 ,子进程还在运行,会被移交给操作系统来管理

常用属性:
join 父进程等待子进程运行结束 其实是提高子进程的优先级
is_alive 是否存活
getpid 获取自己的进程id
name 进程的名字
daemon
terminate 终止这个子进程 有延迟
start 启动进程 有延迟
因为开启和关闭进程 都是操作系统来完成

进程的状态
运行 -io> 阻塞 -> 就绪态
运行 -时间片用完了(运行时间过长)> 就绪态

阻塞
当程序遇到了IO操作,就进入了阻塞态
非阻塞
程序正在运行中,没有任何IO操作
指的是程序的运行状态

并行
多个程序同时运行,是真正的同时执行,仅在多核中会出现

并发
多个事件同时发生了,看起来像是都在运行,本质上是切换执行

程序员永恒的话题
提高程序的效率 减少IO 力求尽可能多占用CPU

Guess you like

Origin www.cnblogs.com/huanghongzheng/p/10967713.html