⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prschedrun.c

📁 A small program to simulate priority scheduling in Unix.
💻 C
字号:
#define _XOPEN_SOURCE#define __USE_XOPEN#define __USE_SVID#include <stdio.h>#include <sys/types.h>#include <unistd.h>#include <stdlib.h>#include <sys/wait.h>#include <sys/timeb.h>#include <time.h>#include <math.h>#ifdef linux#include <getopt.h>#endif#include <string.h>#include "scheduler.h"double pareto(double a, double k, double p);void genData(int argc);#define PRIORITIES 10		/* to change the number of priority levels */                                /* do it here */#define MAXTIME 2000#define MINTIME  100int main(void){    init_q();               ///initializing the ready queues    genData(20);            //use modified genData to generate Process data    PCB_entry *PROCESS;    PROCESS = schedule_next();  //get the next process scheduled into the variable pointer to a process.    printf("The process scheduled next is %d ",PROCESS->proc_no);       // for debugging    re_insert(PROCESS, 0);  //submit for reduction if used full quantum.    list_q();               //check if any boosting is necessary	exit(EXIT_SUCCESS);}/* James Broberg's pareto generator */double pareto(double a, double k, double p) {	double z;  /* Uniform random number from 0 to 1 */	double rv; /* Random variable from Pareto dist to be generated  */   do {        z = drand48();   }   while ((z == 0) || (z == 1));   /* Generate the bounded Pareto rv using the inversion method  */   rv = -(z * pow(p, a) - z * pow(k, a) - pow(p, a)) / (pow(p, a) * pow(k, a));   rv = pow(rv, (-1 / a));   return rv;}void genData(int argc){	struct timeb   *tp;	struct timeb    TP;	int             priority, job_number;	int             distribution[(PRIORITIES + 2)];	int             i;	time_t          junk;	for(i = 0; i < PRIORITIES +2 ; i++)	  distribution[i] = 0;	tp = &TP;       /* Using ftime get a random seed value */	ftime(tp);	srand48((long) TP.time * (long) time(&junk) * (long) TP.millitm);  /* seed the random number	                                     * generator *//*	if (argc != 1) {		fprintf(stderr, "Insufficient number of command line arguments\n\n");		fprintf(stderr, "Usage: gen-data num\n\n");		fprintf(stderr, "Where: num is the number of \"jobs\" to create\n");		fprintf(stderr, "          valid values between 1 and 4096\n");		fprintf(stderr, "\n");		exit(EXIT_FAILURE);	}*/	/* the command line parsing is basic on this program -- it   * could be more sophisticated.   */	if (argc <= 0 || argc > 4096) {		fprintf(stderr, "Selected number of elements to be\n");		fprintf(stderr, "\tgenerated is out of range 1-4096\n");		exit(EXIT_FAILURE);	}  /* ready to go -- this generates the data */	for (job_number = 1; job_number <= argc; job_number++)	{		priority = (int) pareto(0.6 , 1, PRIORITIES + 1 );		if ( priority < 1 ) priority = 1;		if (priority > PRIORITIES ) priority = PRIORITIES;		if ( priority >= 0 && priority  < PRIORITIES + 1 )            distribution[priority - 1]++;        PCB_entry *proc;        int check = insert_new(proc);        if (check == -1) printf("Error creating process %d ", priority);        ready_q[priority-1]->initial_priority = priority;		if ( priority < 5 )		  {                ready_q[priority-1]->time_required = (int) pareto ( 0.5, MINTIME, MAXTIME);                ready_q[priority-1]->job_class = 1;		  }		else if ( priority < 9 )		  {                ready_q[priority-1]->time_required = (int) pareto ( 0.95, MINTIME, MAXTIME);                ready_q[priority-1]->job_class = 1;		  }		else		  {                ready_q[priority-1]->time_required =  (int) pareto ( 0.8, MAXTIME / 2, MAXTIME * 3);                ready_q[priority-1]->job_class = 1;		  }	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -