操作系统时间片轮转法进程CPU调度
2015-07-10 14:35
471 查看
#include <stdio.h> #include <stdlib.h> #include <iostream> using namespace std; typedef struct{ char name[10]; int arrtime; int worktime; }DataType; typedef struct node{ DataType data; struct node *next; }ListNode; typedef ListNode *LinkList; LinkList head; void create_insert_LinkList(int flag1) { ListNode *p1, *p2, *p; p = (ListNode*)malloc(sizeof(ListNode)); head = p; p->next = NULL; while (flag1 > 0) { p = (ListNode*)malloc(sizeof(ListNode)); cout << "进程名:"; cin >> p->data.arrtime; cout << "运行时间:"; cin >> p->data.worktime; cout << "***********" << endl; p->next = NULL; p1 = head; p2 = p1->next; while (p2->next != NULL&&p2->data.arrtime < p1->data.arrtime) { p1 = p2; p2 = p2->next; } p1->next = p; p->next = p2; flag1 = flag1 - 1; } } void pcb_LinkList(int flag2) { LinkList H; ListNode *rear, *q, *p; int RR, rr, time, m, n; p = (ListNode*)malloc(sizeof(ListNode)); p = NULL; H = p; cout << "定义时间片大小:"; cin >> RR; cout << "****************"; rr = RR; H = head->next; head->next = head->next->next; rear = H; rear->next = NULL; time = H->data.arrtime; while (flag2 != 0) { n = 0; while (rr != 0) { rr = rr - 1; time = time + 1; if (head->next != NULL) { if (head->next->data.arrtime <= time) { if (H = NULL) { H = head->next; head->next = head->next->next; rear = H; rear->next = NULL; } else { rear->next = head->next; head->next = head->next->next; rear = rear->next; rear->next = NULL; } } } if (H != NULL) { H->data.worktime = H->data.worktime - 1; m = 1; n = n + 1; if (H->data.worktime == 0) { cout << "在第" << time - n << "s" << endl; cout << "进程" << H->data.name << "运行" << n << "s" << "状态:C" << "完成时间:" << time << endl; cout << endl; H = H->next; flag2 = flag2 - 1; m = 0; n = 0; } } } if (m == 1) { cout << "在第" << time - n << "s" << endl; cout << "进程" << H->data.name << "运行" << n << "s" << "状态:R" << endl; cout << endl; } if (H == NULL) { if (head->next != NULL) { time = head->next->data.arrtime; } } else { if (H->next != NULL&&m == 1 && n == RR) { q = H; H = H->next; rear->next = q; rear = rear->next; rear->next = NULL; } } rr = RR; } } int main() { cout << "时间片轮转法模拟" << endl; cout << endl; int flag; cout << "输入进程数目:"; cin >> flag; cout << "***************" << endl; create_insert_LinkList(flag); pcb_LinkList(flag); cout << "运行结束" << endl; return 0; }
相关文章推荐
- sizeof、strlen
- 【程序员联盟】官网上线啦!coderunity.com
- Js 小技巧
- 汇编语言:第六章 编写多个段的程序
- mysql查找表名
- ORACLE创建定时任务
- skip_grant_tables与半同步的冲突
- Android的ListView中判断其内容已滚动到最顶部或者最底部
- 谁也不该供着谁
- 如何优化UITableView的性能
- Pig基础学习【持续更新中】
- 基于CDH5部署Spark记录
- linux双网卡绑定
- linux双网卡绑定
- Windows下登录UNIX或Linux服务器主机的软件
- 网络编程I/O功能介绍
- string 至 Color 转换演示示例:
- .net反射(原:http://www.cnblogs.com/knowledgesea/archive/2013/03/02/2935920.html)
- 修改jmeter jvm参数
- java JDBC应用(一)——PraparedStatement对象