进程调度—先来先服务

#include <malloc.h>
#include <stdio.h>
#include <string.h>

typedef struct table
{ 
	int key;				/*进程ID号*/
	int sequence;			/*进程进入队列顺序号*/
	char message[10];		/*进程说明信息*/
	struct table *next;
}node;

/*
	定义函数,建立进程链表
*/
node *creat(void)	
{
	node *head;
	node *p1, *p2;
	int n = 0;
	p1 = p2 =(node *)malloc(sizeof(node));
	
	scanf("%d%d", &p1->key, &p1->sequence);
	gets(p1->message);
	head = NULL;

	while (p1->key != 0) {	//输入0表示结束
		++n;
		if (n == 1)
			head = p1;
		else 
			p2->next = p1;
		p2 = p1;
		p1 = (node *)malloc(sizeof(node));
		scanf("%d%d", &p1->key, &p1->sequence);
		gets(p1->message);
	}
	p2->next = NULL;
	return head;
}

/*
	模拟当前就绪进程队列中最先进入进程出队并输出的调用过程
*/
node *fcfs(node *head)	
{
	node *p, *q;
	p = head;
	printf("key=%d,sequence=%d,message=%s\n",p->key,p->sequence,p->message);
	q = p;
	p = p->next;
	free(q);
	return p;
}

void print(node *head)	//输出链表
{
	node *p;

	printf("\n The table is : \n");
	p = head;
	while (p) {
		printf("%d, %d, %s\n", p->key, p->sequence, p->message);
		p = p->next;
	}
}

int main(void)
{
	int count = 0;
	node *p, *q;

	printf("新建的进程控制表为:\nkey sequence message\n");
	p = creat();		//输入进程控制表
	print(p);
	
	while (p) {
		++count;
		printf("\n第%d次被调度的就绪进程为:\n",count);
		q = fcfs(p);
		p = q;
	}
	return 0;
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值