惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Exploit Database - CXSecurity.com
F
Fortinet All Blogs
U
Unit 42
F
Full Disclosure
雷峰网
雷峰网
博客园 - 司徒正美
云风的 BLOG
云风的 BLOG
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
The Cloudflare Blog
Last Week in AI
Last Week in AI
罗磊的独立博客
D
DataBreaches.Net
C
Check Point Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
O
OpenAI News
C
CXSECURITY Database RSS Feed - CXSecurity.com
aimingoo的专栏
aimingoo的专栏
S
Security @ Cisco Blogs
大猫的无限游戏
大猫的无限游戏
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
SegmentFault 最新的问题
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Hacker News
The Hacker News
Webroot Blog
Webroot Blog
Security Latest
Security Latest
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Google DeepMind News
Google DeepMind News
酷 壳 – CoolShell
酷 壳 – CoolShell
N
News | PayPal Newsroom
P
Proofpoint News Feed
B
Blog RSS Feed
MongoDB | Blog
MongoDB | Blog
C
Cybersecurity and Infrastructure Security Agency CISA
N
News and Events Feed by Topic
Google Online Security Blog
Google Online Security Blog
H
Help Net Security
Spread Privacy
Spread Privacy
T
Threat Research - Cisco Blogs
GbyAI
GbyAI
I
Intezer
Application and Cybersecurity Blog
Application and Cybersecurity Blog
M
MIT News - Artificial intelligence
Vercel News
Vercel News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
IT之家
IT之家
MyScale Blog
MyScale Blog
腾讯CDC

GoodBoyboy 's Blog|惬意小屋-点滴记忆

新设计了一个Astro主题 Cap,一个基于PoW的自托管验证码系统 公益服务迁移通知 一种基于argon2id算法与shamir算法的内存PoW(工作量证明)解密游戏 记忆里的屋子(一) Ubuntu 26.04 Btrfs+LUKS2安装 主域名服务不稳定通知 腾讯元宝客户端实习二面凉经 腾讯元宝客户端实习一面面经 对越来越多AI博文的看法 GoodBoyboy Blog、Talk联动成功 只有失去了才会懂得珍惜,但幸好我还没有失去 滴滴Android客户端一面凉经 GoodBoyboy 's Talk上线! Easy Drop——一个基于Gin开发的高性能、轻量级说说平台 Perfect Pic —— 一个基于 Gin 开发的高性能、轻量级图床 尘封了八年的祝福 欢迎OPPO Pad 4 Pro加入设备大家庭 官方Android11 Box系统的OrangePi 3B新增红外模块教程 家里也换成光纤了qwq 姜还是老的辣 布洛芬效果真不错 再见2025,你好2026 Canokey导入S/MIME邮箱证书并使用Thunderbird发送邮件 1.90$申请 WISeID S/MIME 邮箱证书 新购Intel AX210网卡 OpenPGP邮件加密——关于测试邮件握手的思考 疯狂动物城2太好看了(无具体剧透) 效果是真的好,劲也是真的大 不买立省100% 十月小记 新增外设漫步者G1500bar 欢迎招行万事达加入卡包大家庭 博客十周年啦🎉 ESP32 S3开发小结 ESP32 S3外设小记 Arduino+VSCode开发ESP32-S3 EPS32-S3刷入MicroPython EPS32 S3刷入Picokeys Debian13安装Nvidia驱动 现在小孩都这么早熟么。。。 《动物迷城》二周目通关! Bing索引终于恢复了 家里蹲大学开始招生! 家里蹲大学即将建校,欢迎各位莘莘学子来本校深造(doge 骑车去兜风~ OAuth2授权码、客户端凭证、PKCE、设备码授权流程详解 基于OIDC实现Authentik与阿里云RAM角色的联合身份认证 GitHub release以及Git Commit常用模板 实验室生活 阿里云角色SSO对接authentik进行单点登录 白嫖一年Gemini Pro 突然发现自己可能乳糖不耐受? Android第三方Passkey管理器探索 多线程我太爱你了,你个“大可爱” [公告]现评论区已支持使用emoji表情符号😊 Debian GRUB踩坑记——out of memory 为Debian KDE更换显示字体为思源黑体 Debian补全办公常用字体 Debian12 KDE Edge输入法问题 Debian KDE Plasma 5调整外接显示器亮度 Debian开玩Minecraft Debian KDE使用指纹传感器验证身份
进程调度——时间片轮转
GoodBoyboy · 2025-11-23 · via GoodBoyboy 's Blog|惬意小屋-点滴记忆

前言

时间片轮转调度是一种最古老,最简单,最公平且使用最广的算法,又称RR调度。每个进程被分配一个时间段,称作它的时间片,即该进程允许运行的时间。

更多介绍请看-> 时间片轮转_百度百科

自己用C简单实现了一下模拟时间片轮换,列队采用单向链表,在PCB释放上稍显啰嗦,如果用双向链表或者改用C++的vector容器的话代码会清晰很多。

代码

应该没什么奇怪的Bug了(确信

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <stdio.h>
#include <stdlib.h>

typedef enum pstate
{
READY,
RUNNING,
FINISHED
} pstate;

typedef struct PCB
{

int pid;

pstate state;

int arrivetime;

int runtime;

int prior;

struct PCB *next;
} PCB;

int main()
{
srand(20);

int pian = 3;

int p_num = 5;

int pid_count = 1;
PCB *head = (PCB *)malloc(sizeof(PCB));
head->pid = -1;
head->prior = -1;
head->next = NULL;
PCB *current = head;
while (p_num > 0)
{
PCB *new_pcb = (PCB *)malloc(sizeof(PCB));

new_pcb->pid = pid_count;
pid_count++;
new_pcb->state = READY;
new_pcb->arrivetime = rand() % 20;
new_pcb->runtime = rand() % 10 + 1;
new_pcb->prior = rand() % 10 + 1;
new_pcb->next = NULL;

current->next = new_pcb;
current = current->next;
p_num--;
}


int now_time = 0;
while (1)
{
PCB *ahead_current = head;
current = head->next;

if (current == NULL)
{
break;
}


PCB *ahead_pcb = NULL;
PCB *max_prior_pcb = head;
while (current != NULL)
{
if (current->arrivetime <= now_time && current->state == READY && current->prior >= max_prior_pcb->prior)
{
max_prior_pcb = current;
ahead_pcb = ahead_current;
}
ahead_current = current;
current = current->next;
}


if (max_prior_pcb->pid < 0)
{
printf("当前时间为:%d 等待程序到达中……\n",now_time);
now_time += 1;
continue;
}



max_prior_pcb->state = RUNNING;
printf("当前执行程序:PID:%d 到达时间:%d 剩余时间:%d 优先级:%d\n", max_prior_pcb->pid, max_prior_pcb->arrivetime, max_prior_pcb->runtime, max_prior_pcb->prior);

if (max_prior_pcb->runtime <= pian)
{

now_time += max_prior_pcb->runtime;

max_prior_pcb->runtime = 0;

max_prior_pcb->state = FINISHED;
printf("当前程序执行完成:PID:%d 剩余时间:%d 状态:已完成 当前时间:%d\n\n", max_prior_pcb->pid, max_prior_pcb->runtime,now_time);

ahead_pcb->next = max_prior_pcb->next;
free(max_prior_pcb);
}
else
{

now_time += pian;

max_prior_pcb->runtime = (max_prior_pcb->runtime - pian);

max_prior_pcb->state = READY;
printf("当前程序时间片已耗费完:PID:%d 剩余时间:%d 状态:等待继续 当前时间:%d\n\n", max_prior_pcb->pid, max_prior_pcb->runtime,now_time);
}
}
printf("所有程序已执行完毕:花费时间:%d\n", now_time);
}

cardcode

Invitation

created:09/04/2015

Welcome to MyBlog

Use this card to join MyBlog and participate in a pleasant discussion together .

Welcome to GoodBoyboy 's Blog,wish you a nice day .

赞助