没有合适的资源?快使用搜索试试~ 我知道了~
实验一任务二.docx
资源详情
资源评论
资源推荐
实验一任务二
实验名称
进程调度-代码阅读并调试实验
实验目的
实验过程
任务一
1. #include<stdio.h>
2. #include<stdlib.h>
3. #include<conio.h>
4. #include<string.h>
5. #definegetpch(type)(type*)malloc(sizeof(type))
6.
7.
8.
9. /*
定义
PCB
模块
*/
10. structpcb
11. {
12. charname[10];
13. charstate;
14. intsuper;//
优先数
15. intntime;//
预计运行完成时间
16. intrtime;//
运行时间
17. intwait;
18. structpcb*link;//
链接下一个进程
19. }*ready=NULL,*p;//
20. typedefstructpcbPCB;
21.
22.
23. voidsort()/*
对进程根据优先级进行排序
*/
24. {
25. PCB*first,*second;
26. intinsert=0;
27.
28. if((ready==NULL)||((p->super)>(ready->super)))/*1
若没有进程
在进行,则将
p
直接插入
*/
29. {
30. p->link=ready;
31. ready=p;
32. }
33. else
34. {
35. first=ready;
36. second=first->link;
37. while(second!=NULL)
38. {
39. if((p->super)>(second->super))
40. {
41. p->link=second;
42. first->link=p;
43. second=NULL;
44. insert=1;
45. }
46.
47. else
48. {
49. first=second;
50. second=second->link;
51. }
52. }
53. if(insert==0)first->link=p;
54. }
55. }
56.
57.
58. voidinput()
59. {
60. inti,num;
61. system("cls");
62. printf("\n�������������:");
63. scanf("%d",&num);
64. for(i=0;i<num;i++)
65. {
66. printf("\n���5�No.%d:\n",i);
67. p=getpch(PCB);
68. printf("\n���������:");
69. scanf("%s",p->name);
70. printf("\n�������������:");
71. scanf("%d",&p->super);
72. printf("\n�����������ʱ��:");
73. scanf("%d",&p->ntime);
74. printf("\n");
75. p->rtime=0;
76. p->state='w';//
77. p->wait=0;
78. p->link=NULL;
79. sort();
80. }
81. }
82.
83.
84. intspace()
85. {
86. intl=0;
87. PCB*pr=ready;
88. while(pr!=NULL)
89. {
90. l++;
91. pr=pr->link;
92. }
93. return(l);
94. }
95. voiddisp(PCB*pr)/*
显示进程信息
*/
96. {
97. printf("\nqname\tstate\tsuper\tndtimeruntime\twa
it\n");
98. printf("|%s\t",pr->name);
99. printf("|%c\t",pr->state);
100. printf("|%d\t",pr->super);
101. printf("|%d\t",pr->ntime);
102. printf("|%d\t",pr->rtime);
103. printf("|%d\t",pr->wait);
104. printf("\n");
105. }
106.
107. voidcheck()
108. {
109. PCB*pr;
110. printf("\n****��ǰ�������еĽ�����:%s",p->name);
111. disp(p);
112. pr=ready;
113. printf("\n****��ǰ��������״Ϊ:\n");
114. {
115. disp(pr);
116. pr=pr->link;
117. }
118. }
剩余10页未读,继续阅读
林带鱼QAQ
- 粉丝: 50
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0