一:源程序:
#include "stdlib.h"
#include "stdio.h"
#include "conio.h"
struct jincheng_type
{
int pid;
int youxian;
int daxiao;
}; //进程模拟。
struct jincheng_type jiuxu[20]; //就绪数组。
struct jincheng_type guaqi[20]; //挂起数组。
struct jincheng_type cpu; //运行进程。
int NUM1=0,NUM2=0,first=0;
void create()
{
if(NUM1>=20)
{
printf("\n就绪进程已满,请先删除或挂起进程\n");
}
else
{
if(first==0)
{
printf("\n这是你第一次输入进程信息,它将直接调入CPU运行!");
printf("\n请输入新进程的pid\n");
scanf("%d",&cpu.pid);
printf("请输入新进程的优先级\n");
scanf("%d",&cpu.youxian);
printf("请输入新进程的大小\n");
scanf("%d",&cpu.daxiao);
first++;
}
else
{
printf("\n请输入新进程的pid\n");
scanf("%d",&jiuxu[NUM1].pid);
printf("请输入新进程的优先级\n");
scanf("%d",&jiuxu[NUM1].youxian);
printf("请输入新进程的大小\n");
scanf("%d",&jiuxu[NUM1].daxiao);
NUM1++;
}
}
}
//新建进程。
void run()
{
printf("\n现在正在运行的进程的资料如下:\n");
printf("PID码为:%d;\n优先级为:%d;\n大小为:%d.",cpu.pid,cpu.youxian,cpu.daxiao);
}
//查看运行进程。
void huanchua()
{
int i,p,m,n,t;
p=jiuxu[0].youxian;
for(i=0;i
{
if(p>jiuxu[i].youxian)
{
p=jiuxu[i].youxian;
}
}
for(i=0;i<20;i++)
{
if(p==jiuxu[i].youxian)
{
m=cpu.daxiao;
cpu.daxiao=jiuxu[i].daxiao;
n=cpu.pid;
cpu.pid=jiuxu[i].pid;
t=cpu.youxian;
cpu.youxian=jiuxu[i].youxian;
break;
}
else continue;
}
for(i;i {
jiuxu[i].daxiao=jiuxu[i+1].daxiao;
jiuxu[i].pid=jiuxu[i+1].pid;
jiuxu[i].youxian=jiuxu[i+1].youxian;
}
jiuxu[i].daxiao=m;
jiuxu[i].pid=n;
jiuxu[i].youxian=t;
}
void huanchub()
{
int i,p;
printf("\n请输入想要挂起的进程的PID码:\n(在以下中选:");
for(i=0;i {
printf("%d ",jiuxu[i].pid);
}
printf(")\n");
scanf("%d",&p);
for(i=0;i {
if(p==jiuxu[i].pid)
{
guaqi[NUM2].daxiao=jiuxu[i].daxiao;
guaqi[NUM2].pid=jiuxu[i].pid;
guaqi[NUM2].youxian=jiuxu[i].youxian;
NUM2++;
break;
}
else continue;
}
for(i;i {
jiuxu[i].daxiao=jiuxu[i+1].daxiao;
jiuxu[i].pid=jiuxu[i+1].pid;
jiuxu[i].youxian=jiuxu[i+1].youxian;
}
NUM1--;
}
void huanchuc()
{
int i;
jiuxu[NUM1].daxiao=guaqi[0].daxiao;
jiuxu[NUM1].pid=guaqi[0].pid;
jiuxu[NUM1].youxian=guaqi[0].youxian;
NUM1++;
for(i=0;i {
guaqi[i].daxiao=guaqi[i+1].daxiao;
guaqi[i].pid=guaqi[i+1].pid;
guaqi[i].youxian=guaqi[i+1].youxian;
}
NUM2--;
}
void huanchud()
{
int i,p,m,n,t;
printf("\n请输入想要运行的进程的PID码:\n(在以下中选:");
for(i=0;i {
printf("%d ",jiuxu[i].pid);
}
printf(")\n");
scanf("%d",&p);
for(i=0;i {
if(p==jiuxu[i].pid)
{
m=cpu.daxiao;
cpu.daxiao=jiuxu[i].daxiao;
jiuxu[i].daxiao=m;
n=cpu.pid;
cpu.pid=jiuxu[i].pid;
jiuxu[i].pid=n;
t=cpu.youxian;
cpu.youxian=jiuxu[i].youxian;
jiuxu[i].youxian=t;
break;
}
else continue;
}
}
void huanchue()
{
int i,p;
printf("\n请输入想要调入就绪的进程的PID码:\n(在以下中选:");
for(i=0;i