我正在尝试为CPU调度程序模拟器实现循环算法,但使用链表结构。
我已经编写了这段代码,但似乎无法正常运行:
//Round Robin scheduling
void roundRobin(){
bubbleSortArrivalTime();
struct process *temp;
int totalTimeCnt=0;
int totalTime;
int quantum=4;
int i;
for(temp=proc; temp!=NULL; temp=temp->next){
totalTime+=temp->burstTime;
}
do{
for(i=1; i<LISTSIZE; i++){
if(i==1){
set_nth_process_burstTime(proc, i, get_nth_process_burstTime(proc,i)-quantum);
//set_nth_process_waitingTime(proc, i, get_nth_process_burstTime(proc,i-1)+get_nth_process_waitingTime(proc, i-1));
totalTime+=4;
}
else{
set_nth_process_burstTime(proc, i, get_nth_process_burstTime(proc,i)-quantum);
set_nth_process_waitingTime(proc, i, get_nth_process_burstTime(proc,i-1)+get_nth_process_waitingTime(proc, i-1));
totalTime+=4;
}
}
}while(totalTimeCnt!=0);
method="Method selected: Round Robin Scheduling";
}
我的链接列表的结构如下:
struct process{
int burstTime,arrivalTime, priority,pname;
float waitingTime, turnArroundTime;
struct process *next;
}*proc=NULL;
其中proc
被定义为全局。
我已经实现了一些get和set函数来轻松访问任何元素:
void set_nth_process_burstTime(struct process*header, int position, int value)
void set_nth_process_waitingTime(struct process *header, int position, float value)
int get_nth_process_waitingTime(struct process *header, int position)
int get_nth_process_priority(struct process *header,int position)
int get_nth_process_arrivalTime(struct process *header,int position)
int get_nth_process_burstTime(struct process *header,int position)
请问您如何正确实施Round Robin?它没有给出正确的结果。
答案 0 :(得分:0)
while(1)
{
process_1();
process_2();
process_3();
...
}
除此之外的任何事情都将归因于特定项目的一些特殊考虑因素。
实现scheduler
+ dispatcher
,具有多个所需的执行间隔,优先级,条件状态,老化等是一种完全不同的架构。
对于round robin
,上面的while()
循环就是它。
对于一个真实的项目,您还需要:
答案 1 :(得分:0)
var Crawler = require("crawler");
var url = require('url');
var fs = require('fs');
var writeStream = fs.createWriteStream('./output');
writeStream.write('<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">');
var strBuff = '<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">';
var Router = require('routes');
var router = Router();
var noop = function(){};
var peroid = {
'/':'hourly',
'/results':'hourly',
'/tips': 'hourly',
'/tips/:country':'hourly',
'/tips/:country/:venue':'hourly',
'/support':'hourly',
}
function addToMap(url) {
var key = router.match(url.replace('https://www.yourwebsite.com',''));
if(!key) {
key = {};
key.route = '/';
} else {
console.log('match ', url);
}
var route = key.route;
var freq = peroid[route];
var buf = '<url>\n<loc>'+url+'</loc>\n <changefreq>'+freq+'</changefreq>\n<priority>0.5</priority>\n</url>';
strBuff += '<url>\n<loc>'+url+'</loc>\n <changefreq>'+freq+'</changefreq>\n<priority>0.5</priority>\n</url>';
writeStream.write(buf);
}
function saveTofile() {
console.log('end');
writeStream.write('\n</urlset>');
writeStream.end();
}
router.addRoute("/", noop);
router.addRoute("/tips", noop);
router.addRoute("/tips/:country", noop);
router.addRoute("/tips/:country/:venue", noop);
router.addRoute("/support", noop);
router.addRoute("/algorithm", noop);
var cache = {};
var c = new Crawler({
maxConnections : 25,
skipDuplicates: true,
// This will be called for each crawled page
onDrain: function () {
console.log('ondrain');
saveTofile();
},
callback : function (error, result, $) {
if(error || !$) {
console.log(error, result.uri);
return;
}
$('a').each(function(index, a) {
var toQueueUrl = $(a).attr('href');
if(!toQueueUrl) {
return;
}
if((toQueueUrl && toQueueUrl[0] !== '/') || toQueueUrl.indexOf('/api/') !== -1 || toQueueUrl.indexOf('.pdf') !== -1) {
//console.log('not crawliing', toQueueUrl);
return;
}
if(cache.hasOwnProperty(toQueueUrl) || !toQueueUrl) {
return;
}
//console.log(toQueueUrl);
c.queue('https://www.yourwebsite.com'+toQueueUrl);
addToMap('https://www.yourwebsite.com'+toQueueUrl);
cache[toQueueUrl] = 1;
var keyz = Object.keys(cache);
if(! (keyz.length % 100) ) {
console.log('total', keyz.length);
}
});
}
});
c.queue('https://www.yourwebsite.com');