当前位置:网站首页>Short work priority SJF
Short work priority SJF
2022-07-28 07:19:00 【▀】
SJF Scheduling algorithm :
Short assignments ( process ) Priority scheduling algorithm SJ(P)F, It refers to the algorithm of priority scheduling for short jobs or short processes . They can be used for job scheduling and process scheduling respectively . Short job preferred (SJF) The scheduling algorithm is to select one or several jobs with the shortest estimated running time from the backup queue , Put them in memory to run . The short process takes precedence (SPF) The scheduling algorithm is to select a process from the ready queue with the shortest estimated running time , Assign the processor to it , Make it execute immediately and continue until it is finished , Or when an event occurs and is blocked, it will be rescheduled when the processor is abandoned .
In order to and FCFS Scheduling algorithms are compared , We still use FCFS Examples used in the algorithm , And to switch to SJ(P)F Algorithm rescheduling , Then conduct performance analysis . From... In the above figure (a) and (b) It can be seen that , use SJ(P)F After algorithm , Whether it is the average turnover time or the average weighted turnover time , There are obvious improvements , Especially for short assignments D, The turnover time is changed from ( use FCFS When the algorithm )11 Reduced to 3; The average weighted turnaround time is from 5.5 drop to 1.5. This explanation SJF Scheduling algorithm can effectively reduce the average waiting time of jobs , Improve system throughput .
SJ(P)F Scheduling algorithm also has shortcomings that cannot be ignored :
- This algorithm is disadvantageous to long jobs , Such as homework C The turnaround time is determined by 10 to 16, Its weighted turnover time is from 2 to 3.1. More serious , If there is a long homework ( process ) Enter the backup queue of the system ( Ready queue ), Because the scheduler always prioritizes those ( Even the late comers ) Short assignments ( process ), It will lead to long work ( process ) Not scheduled for a long time .
- The algorithm does not consider the urgency of the job , As a result, urgent operations cannot be guaranteed ( process ) It will be dealt with in time .
- Because of the homework ( process ) The length of is only based on the estimated execution time provided by the user , And users may intentionally or unintentionally shorten the estimated running time of their jobs , As a result, the algorithm may not be able to achieve short job priority scheduling .
Reference and :https://blog.csdn.net/houchaoqun_xmu/article/details/55539362
Code
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<queue>
#include<list>
#include<thread>
#include<mutex>
#include<Windows.h>
using namespace std;
#define MAX_TIME 99999
int g_time = 0;
mutex g_mutex_time;
struct process_node
{
int prcess_id; // Process number
int _start; // Entry time
void(*main_doing)(int args, char *ptr_argv[]);// Tasks completed by this process
int begin; // Starting time
int finish; // Completion time
int _function; // Run time required
int function; // Time that has been running
bool complete; // Whether it is completed or not true complete
};
list<process_node*>q_list;// Process queue
void showlist()
{
for (auto ib = q_list.begin(); ib != q_list.end(); ib++)
{
cout << (*ib)->prcess_id << " ";
}
cout << "\n";
}
void main_doing(int args, char *ptr_argv[])
{
cout << args << " This is a running instance " << endl;
Sleep(200);
}
void Come_Init_Prcess(void(*main_doing)(int args, char *ptr_argv[]), int _function) // The simulation process arrives and initializes
{
static int id = 0;
process_node *p = new process_node;
p->prcess_id = ++id;
p->_start = g_time;
p->main_doing = main_doing;
p->_function = _function;
p->begin = MAX_TIME;
p->finish = MAX_TIME;
p->function = 0;
p->complete = false;
q_list.push_back(p);
}
void Time_End_Work(process_node & current_process)// Work before the end of the time slice
{
if (current_process.function >= current_process._function)// Judge whether it is finished
{
current_process.complete = true;
current_process.finish = g_time;
cout << " process " << current_process.prcess_id << " To complete the task " << endl;
q_list.remove(¤t_process);
}
}
void One_End_Process(process_node & current_process)
{
int current_point = g_time;
cout << " current time " << current_point << endl;
while (current_point + current_process._function >= g_time)
{
current_process.main_doing(current_process.prcess_id, NULL);
}
current_process.function += g_time - current_point;
Time_End_Work(current_process);
}
process_node& Obtain_Obtain()// Get priority
{
int temp = 9999;
process_node *p_temp = nullptr;
while (q_list.size() == 0);
for (auto ib = q_list.begin(); ib != q_list.end(); ib++)
{
if ((*ib)->_function - (*ib)->function < temp)
{
temp = (*ib)->_function - (*ib)->function;
p_temp = (*ib);
}
}
cout << " The priority is the program " << p_temp->prcess_id << endl;
p_temp->begin = g_time;
return *p_temp;
}
void Run_begin()
{
while (1)
{
process_node &p_temp = Obtain_Obtain();
showlist();
One_End_Process(p_temp);
}
}
// Time instances arrive
void pthread_model()
{
time_t ts;
srand((unsigned int)time(&ts));
while (1)
{
int x_temp = 0;
lock_guard<mutex>ldg(g_mutex_time);
cout <<" Time :["<<g_time<<"]" << endl;
if (g_time%2==0)
{
while (1)
{
x_temp = rand() % 5;
if (x_temp > 0)
{
break;
}
}
Come_Init_Prcess(main_doing, x_temp);
cout << " Instance arrives " << endl;
}
Sleep(1000);
g_time++;
}
}
int main()
{
thread th_model(pthread_model);
thread th_main(Run_begin);
th_model.join();
th_main.join();
cin.get();
}
边栏推荐
- MySQL查询父节点下面的所有子孙节点,查询用户列表时多级(公司)部门处理,根据反射,递归树形结构工具类
- N天前的日期
- easypoi导出隔行样式设置
- Redis主从复制原理及配置
- List of papers on gestures
- Easypoi export table with echars chart
- Understanding of maximum likelihood estimation, gradient descent, linear regression and logistic regression
- kali下安装nessus
- Pytorch installation - CPU version
- heroku 操作总结
猜你喜欢

最短寻道时间优先(SSTF)

metasploit渗透ms7_010练习

Neo4j运行报错Error occurred during initialization of VM Incompatible minimum and maximum heap sizes spec

guava之限流RateLimiter

Image segmentation method

Sysevr environment configuration: joern-0.3.1, neo4j-2.1.5, py2neo2.0

object detection

Shell--第一天作业

Neo4j running error occurred during initialization of VM incompatible minimum and maximum heap sizes spec

Nrf51822 review summary
随机推荐
Neo4j running error occurred during initialization of VM incompatible minimum and maximum heap sizes spec
用户态vs内核态、进程vs线程
Image segmentation method
一个定时任务提醒工具
Pytorch installation - CPU version
远程访问云服务器上Neo4j等服务的本地网址
Implementation method of converting ast into word vector before converting word vector
Two horizontal and vertical screen switching schemes for uniapp mobile terminal
N天前的日期
Insert sort of sort
低端电脑如何深度学习秘籍-使用mistGPU计算平台
caffe fine tune
easypoi导出表格带echars图表
Freemaker merges cells, uses if and else tags, and processes null and empty strings
The.Joernindex database has no content after Joern runs
Review of C language (variable parameters)
分解路径为目录名和文件名的方法
Shell--- function
MySQL排除节假日,计算日期差
easypoi一对多,合并单元格,并且根据内容自适应行高