在linux0.11中进程创建后直接变为就绪态,最后一个状态必为退出态。
在第一个就绪态到退出态前一个状态,他们的状态转换必须满足如下条件。
就绪-运行
运行-就绪
运行-睡眠
睡眠-就绪
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
int main() {
FILE *fp,*fp1;
int pid; int ji;
struct {
int sum;
int jifi[800];
char statu[800];}w[20];
fopen_s(&fp,"1.txt", "r");
for (int i = 7; i <= 19; i++) {
w[i].sum = -1;}
char stat;
while (fscanf_s(fp, "%d %c %d", &pid, &stat,1, &ji)!=EOF)
{
if (pid >= 7 && pid <= 19) {
w[pid].sum++;
w[pid].jifi[w[pid].sum] = ji;
w[pid].statu[w[pid].sum] = stat;
}
}int flag = 0;
for (int i = 7; i <= 19; i++) {
flag = 0;
for (int j = 0; j <= w[i].sum; j++) {
if (w[i].statu[0] != ‘N‘||w[i].statu[1] != ‘J‘) {
printf("pid:%d进程出错\n", i); flag = 1; break;
}
else if (w[i].statu[w[i].sum] != ‘E‘) {
printf("pid:%d进程出错\n", i); flag = 1; break; }
else if (j>=2&&j< w[i].sum) {
if (!((w[i].statu[j - 1] == ‘R‘&&w[i].statu[j] == ‘J‘) || (w[i].statu[j - 1] == ‘J‘&& w[i].statu[j] == ‘R‘) || (w[i].statu[j - 1] == ‘R‘&&w[i].statu[j] == ‘W‘) || (w[i].statu[j - 1] == ‘W‘&&w[i].statu[j] == ‘J‘)))
{
printf("pid=%d进程状态出错\n", i); flag = 1; break;
}
}
}if (flag == 0)printf("pid:%d进程状态记录准确\n",i);
}
fclose(fp);
return 0;}