[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
一、本章重点
1、linux进程状态
2、孤儿进程
3、linux进程优先级
01 linux进程状态
先介绍一些概念:运行状态、阻塞状态、终止状态、挂起状态
1、运行状态:指pcb放入在运行队列中,随时可以被cpu进行调度。
2、阻塞状态:由于某种资源不就绪,pcb被放入该资源的等待队列中,如:放入磁盘的等待队列,显示器的等待队列。
3、终止状态:指进程已经执行完毕,永远不会被cpu调度,随时都可被cpu释放pcb等内存资源。
4、挂起状态:由于内存不够,操作系统会将暂时不用的内存资源置换到磁盘中,等用的时候再加载到内存中。
linux系统进程状态有一下几种:
1 r:进程pcb被放入运行队列中,随时可被cpu进行调度。
2 s:对应进程阻塞状态,进程pcb被放入等待队列,等待资源就绪。
3
d:一种特殊的阻塞状态,它等待的资源是磁盘资源,处于这种状态的进程无法被操作系统杀死(除非关机才能杀死),当进程要写入一份很重要的数据到磁盘时,该进程需要等待磁盘帮它存好数据,如果此时恰好内存空间严重不足,操作系统就会选择杀掉一些s状态的进程,因此当某些进程等待磁盘时,需要将该进程设置为d状态。(很难模拟)
4 T:暂停状态,类似于下载软件的暂停。
5 t:暂停状态,类是于调试遇到断点。
6
z:僵尸状态,当子进程退出时,需要维护一种僵尸的状态,此时它刀枪不入,无法被杀死,只有父进程通过进程等待才能让子进程资源被释放,如果一直不释放,子进程会一直维护task_struck,因此会有内存泄露
。
7 x:终止状态,随时准备被操作系统回收资源。(很难模拟)
02孤儿进程
由僵尸进程延伸而来,父进程等待子进程回收子进程的pcb,当父进程先于子进程退出,那么子进程就会变成孤儿,然后就会被1号进程所领养,1号进程其实就是操作系统。
03Linux进程优先级
1、什么是进程优先级?
答:进程获取资源的先后顺序。
2、为什么有进程优先级?
答:进程太多,资源太少。
3、进程优先级由PRI和NI确定
修改NI步骤
1、top
2、r
3、输入PID
4、输入NI值
NI的范围是[-20,19],PRI的范围是[60,99]。