#include "list.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
int number = 0;
enum State {Running, Ready, Blocked};
LIST *lowest;
LIST *low;
LIST *high;
LIST *medium;
LIST *wait;
struct PCB
{
int pid;
int priority;
enum State state;
};
void input ()
{
char input1;
struct PCB *pointer1;
pointer1= (struct PCB*) malloc(sizeof(struct PCB));
while(1){
printf("Enter an associated letter= ");
scanf(" %c", &input1);
if (input1=='C')
{
printf("Give the priority of the process you want to create = ");
scanf ("%d", &pointer1->priority);
Create(&pointer1->priority);
}
}
free(pointer1);
}
void Create(int *arg)
{
struct PCB *pcbpointer;
pcbpointer = (struct PCB*) malloc(sizeof(struct PCB));
++number;
pcbpointer->pid =number;
pcbpointer->state= Ready;
if (arg == 0){
ListLast(high);
ListAdd(high, pcbpointer);
printf("Processor created with high priority\n");
}
else if (arg == 1){
ListLast(medium);
ListAdd(medium, pcbpointer);
printf("Processor created with priority 1\n");
}
else if (arg == 2){
ListLast(low);
ListAdd(low, pcbpointer);
printf("Processor created with priority 2\n");
}
free(pcbpointer);
}
int main()
{
high= ListCreate();
medium= ListCreate();
low= ListCreate();
input();
return 0;
}
我的创建中存在很多问题...我正在尝试使用输入部分中传递的优先级参数创建一个进程并将该进程添加到适当的列表
我是这些东西的新手,可能用指针不太好......如果我的代码中的某些东西很奇怪,那就让我感觉不舒服
另外要提一下,我正在尝试将我的列表用作队列,我会转到最后一个使当前指针指向它的元素...然后将过程添加到它。 如果有人能提供帮助,我会很高兴...提前致谢