Esempio n. 1
0
int main(int argc, char *argv[])
{
	int i, nProc, nSchedule;
	GQueues *gq;
	int ret;

	int tServing, tArriving;

	int pid;

	int nTime = 0;

	int RRflag;


	for (i = 0; i < 0; i++)
		pid = 1;


	gq = (GQueues *)malloc(sizeof(GQueues));
    if (gq == NULL)
		return 1;
    
	ret = InitGQueues(gq);
	if (ret != 0)
		return 2;
 
	
	/* 录入数据 */
Retry0:
	printf("Please input the number of processes: "); 
	scanf("%d",&nProc);
	if (nProc < 0 || nProc > MAX_PCB_NUM) {
		printf("Error! the number must be less than %d", MAX_PCB_NUM);
		goto Retry0;
	}

	for (i = 0; i < nProc; ++i) {
		
		printf("No. %d\n", i);
		printf("\t Serving time: ");
		scanf("%d", &tServing);
		printf("\t Arriving time: ");
		scanf("%d", &tArriving);

		allocPcb(gq, i, tServing, tArriving);
	}


Retry1:
	printf("Please input the choice of scheduling[0(RR)/1(SPF)]: ");
	scanf("%d", &nSchedule);
	if (nSchedule < 0 || nSchedule > 1) {
		printf("Error, please retry\n");
		goto Retry1;
	}

	/* 实验测试 */
	RRflag = 0;
	do {
		/* 调度就绪队列 */
		switch (nSchedule)
		{
		case RR:
			invokeRR(&(gq->qReady), RRflag);
			break;
		case SPF:
			invokeSpf(&(gq->qReady));
			break;
		default:
			break;
		}

		/* 运行 */
		printf("nTime = %d,\t", nTime++);
		pid = running(gq->qReady.head);
		printf("pid = %d\n", pid);

		/* 就绪队列的队头是否运行完毕?*/
		RRflag = finishReadyHead(gq);

		/* 是否全部运行完毕?*/
		if (gq->qReady.head == NULL)
			break;
	} while (1);

	/* 结束实验,清理内存 */
	DestroyGQueues(gq);

	//getch();

	return 0;

}
Esempio n. 2
0
int main(int argc, char ** argv) {
    int nSchedule = SPF;
    int RRflag = 0;
    int pid;
    printf("this is done by 冉惟之, std. id : 2013060105023\n");
    if (argc == 2) {
        if (!strcmp(argv[1], "RR")) {
            nSchedule = RR;
        }
        else if (!strcmp(argv[1], "SPF")) {
            nSchedule = SPF;
        }
        else {
            printf("invalid argument : %s\n", argv[1]);
            return -2;
        }
    }
    else {
        printf("too few arguments\n");
        return -1;
    }
    GQueues *gq = (GQueues *) malloc(sizeof(GQueues));
    InitGQueues(gq);

/* 根据录入进程数据,分配PCB */
    allocPcb(gq, 0, 3, 0);
    allocPcb(gq, 1, 6, 2);
    allocPcb(gq, 2, 4, 4);
    allocPcb(gq, 3, 5, 6);
    allocPcb(gq, 4, 2, 8);

/* 输入进程调度方式 */

    do {
        /* 调度就绪队列 */
        switch (nSchedule)
        {
            case RR:
                invokeRR(&(gq->qReady), RRflag);
                break;
            case SPF:
                invokeSpf(&(gq->qReady));
                break;
            default:
                break;
        }

        /* 就绪队列的队头是否运行完毕?*/
        RRflag = finishReadyHead(gq);
        /* 是否全部运行完毕?*/
        if (gq->qReady.head == NULL)
            break;

        /* 运行 */
        pid = running(gq->qReady.head);
        printf("now running %d\n", pid);
    } while (1);

    /* 结束实验,清理内存 */
    DestroyGQueues(gq);
}