成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

linux進(jìn)程調(diào)度模擬

運(yùn)維 系統(tǒng)運(yùn)維
/*模擬實(shí)現(xiàn)LINUX進(jìn)程調(diào)度的靜態(tài)優(yōu)先級(jí)算法和時(shí)間片輪轉(zhuǎn)算法引入LINUX調(diào)度
/*模擬實(shí)現(xiàn)LINUX進(jìn)程調(diào)度的靜態(tài)優(yōu)先級(jí)算法和時(shí)間片輪轉(zhuǎn)算法引入LINUX調(diào)度
*/
#include
#include
#include
#include
#include
#define RUN  1
#define SLEEP  0
#define READY  2
#define DEG_SCHEDULE
#define NUM 6
struct OSPCB
{
int PcbName ; /*進(jìn)程名字*/
int ReqCount;   /*進(jìn)程執(zhí)行計(jì)數(shù)*/
int RunTime;/*進(jìn)程執(zhí)行時(shí)間數(shù)*/
int Prority;/*進(jìn)程優(yōu)先級(jí)*/
int PcbStatus;  /*進(jìn)程狀態(tài)*/
int PcbTime;/*進(jìn)程時(shí)間片*/
struct OSPCB* prev;
struct OSPCB *next;
};
struct ProcessQueue  /*模擬CPU調(diào)度隊(duì)列*/
{
struct OSPCB *PointerHead; /*指向進(jìn)程鏈表頭*/
int PcbNumber;/*CPU每次調(diào)度計(jì)數(shù)器*/
};
//static struct CriticalResource
//{
// int flag;
// char BufferVoice[2000];
//}
static int flag;
void *Function(int *arg);
void InitPcb(struct OSPCB *pcb);
int Schedule(struct ProcessQueue *queue);
void  InheritSchedule(struct OSPCB *pcb);
int main(void)
{
int i,ret;
struct OSPCB *pNewPcb,*pNew;
struct ProcessQueue *pNewQueue;
int a[4][4] = {{1,1,0,1},{2,2,0,2},{3,3,0,3},{4,4,0,4}};
pNewQueue = (struct ProcessQueue *)malloc(sizeof(struct ProcessQueue));
pNewQueue->PointerHead = NULL;
pNewQueue->PcbNumber = 0;
for(i = 0; i < 4;i++) /*進(jìn)程初始化*/
{
pNewPcb = (struct  OSPCB *)malloc(sizeof(struct OSPCB));
pNewPcb->PcbName   = a[i][0];
pNewPcb->ReqCount  = a[i][1];
pNewPcb->RunTime   = a[i][2];
pNewPcb->Prority   = a[i][3];
pNewPcb->PcbStatus = READY;
pNewPcb->PcbTime   = 3;
InitPcb(pNewPcb);
if(pNewQueue->PointerHead == NULL)
{
pNewQueue->PointerHead = pNewPcb;
}else{
pNew->next = pNewPcb;
pNewPcb->prev = pNew;
}
pNew =  pNewPcb;
pNewQueue->PcbNumber++;
}
#if 0
for(p = pNewQueue->PointerHead; p != NULL; p = p->next)
{
printf("process name = %d\n",p->PcbName);
}
#endif
Schedule(pNewQueue);/*進(jìn)入進(jìn)程調(diào)度*/
return 0;
}
void InitPcb(struct OSPCB *pcb)
{
pcb->prev = NULL;
pcb->next = NULL;
}
int Schedule(struct ProcessQueue *queue) /*進(jìn)程調(diào)度*/
{
struct OSPCB *pcb,*CurrRun;
int value,SechNumber = 8;
pthread_t pthread_id[NUM];
int i = 0;
// printf("%s\n",__FUNCTION__);
for(pcb = queue->PointerHead;pcb !=NULL;pcb = pcb->next)
{
if(pcb->PcbTime  == 0)
{
pcb->Prority +=4;
}
pcb->PcbTime = 3;
}
while(queue->PointerHead != NULL)
{
for(pcb = queue->PointerHead;pcb !=NULL;pcb = pcb->next)
{
if(pcb == queue->PointerHead)
{
CurrRun = pcb;
}else{
if(CurrRun->Prority < pcb->Prority)
CurrRun = pcb;
}
CurrRun->PcbStatus = RUN;
}
SechNumber--;
CurrRun->ReqCount--;
CurrRun->PcbTime--;
if(i != (CurrRun->PcbName))
{
i = CurrRun->PcbName;
pthread_create(&pthread_id[i],NULL,(void*)Function,&(CurrRun->PcbName));
}
#ifdef DEG_SCHEDULE
printf("present process  = %d CurrRun->ReqCount = %d\n",CurrRun->PcbName,CurrRun->ReqCount);
#endif
if(CurrRun->PcbTime == 0)
{
CurrRun->Prority -=4; /*進(jìn)程懲罰性降優(yōu)先級(jí)處理*/
}
if(CurrRun->ReqCount == 0)
{
if(CurrRun == queue->PointerHead)
{
queue->PointerHead = CurrRun->next;
}else if (CurrRun->next != NULL){
CurrRun->prev->next = CurrRun->next;
CurrRun->next->prev = CurrRun->prev;
}else{
CurrRun->prev->next = NULL;
}
//   printf("Run process name = %d  Reqcount = %d Sechedule count = %d\n",CurrRun->PcbName,CurrRun->ReqCount,SechNumber);
}
if(SechNumber == 0)/*時(shí)間片用完重新調(diào)度*/
{
Schedule(queue);
}
}
return 0;
}
void SleepProcess(void)
{
}
void DeleteProcess(void)
{
// return 0;
}
void *Function(int *arg) /*進(jìn)程執(zhí)行函數(shù)*/
{
int i,count = 0;
int PthreadName;
struct OSPCB *pNew;
pNew = (struct OSPCB *)arg;
PthreadName = *(int *)arg;
#ifdef DEG_SCHEDULE
printf("Enter the function process %d\n", PthreadName);
#endif
while(1)
{
if(flag == 0) /*訪問臨界區(qū)資源*/
{
flag = 1;
#ifdef DEG_SCHEDULE
printf("get lcok in  process %d\n", PthreadName);
#endif
for(i = 0; i < 10000; i++)
{
pNew->PcbStatus = SLEEP;
sleep(1);
}
flag = 0;/*釋放臨界區(qū)資源*/
break;
}else{ /*自旋直到得到可訪問的臨界區(qū)資源*/
count++;
if(count == 5000)
{
#ifdef DEG_SCHEDULE
printf("flag = %d can not get lock in process name %d\n",flag,PthreadName);
#endif
}
}
}
#ifdef DEG_SCHEDULE
printf("flag = %d out process %d\n", flag,PthreadName);
#endif
}

【編輯推薦】

  1. Linux應(yīng)用:在Fedora 下安裝opera瀏覽器
  2. linux死機(jī)了怎么辦 處理辦法詳細(xì)解析
  3. linux塊設(shè)備,字符設(shè)備
責(zé)任編輯:趙寧寧 來源: chinaitlab
相關(guān)推薦

2023-03-03 00:03:07

Linux進(jìn)程管理

2010-03-08 14:40:27

Linux進(jìn)程調(diào)度

2021-05-12 07:50:02

CFS調(diào)度器Linux

2023-03-05 15:28:39

CFSLinux進(jìn)程

2012-05-14 14:09:53

Linux內(nèi)核調(diào)度系統(tǒng)

2018-05-30 13:42:39

2009-12-11 09:42:54

Linux內(nèi)核源碼進(jìn)程調(diào)度

2009-12-11 09:47:23

Linux內(nèi)核源碼進(jìn)程調(diào)度

2022-12-30 07:50:05

無棧協(xié)程Linux

2021-12-15 15:03:51

Linux內(nèi)核調(diào)度

2022-04-27 10:14:43

進(jìn)程調(diào)度LinuxCPU

2023-05-08 12:03:14

Linux內(nèi)核進(jìn)程

2025-06-16 05:10:00

2021-02-22 07:58:45

算法進(jìn)程調(diào)度

2023-11-26 18:54:29

Linux調(diào)度器

2022-02-15 18:45:35

Linux進(jìn)程調(diào)度器

2025-01-21 10:54:28

2011-01-21 07:36:00

LinuxBFSCFS

2011-01-13 13:59:14

2010-02-25 10:28:43

Linux進(jìn)程管理
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: 美女黄18岁以下禁止观看 | www97影院| 免费在线观看一区二区 | 国产精品久久 | 午夜精品久久久久久久久久久久久 | 亚洲欧美国产精品一区二区 | 国产精品久久久久久久久免费相片 | 久久99久久99久久 | 日韩一区二区三区av | 中文字幕高清免费日韩视频在线 | 天天干天天插 | 久久亚洲欧美日韩精品专区 | 久草网站| 国产91视频免费 | 精品国产91乱码一区二区三区 | 欧美一级毛片久久99精品蜜桃 | 91色视频在线观看 | 国产日韩欧美二区 | 成人av在线大片 | 亚洲精品一| av网站免费看 | 亚洲视频二区 | 国产一区二区三区四区五区3d | 国精品一区二区 | 免费观看一级毛片 | 97色在线观看免费视频 | 久久久精品视 | 久久精品久久久 | 亚洲一区二区三区高清 | 国产亚洲一区二区三区在线观看 | 国产精品久久久久久亚洲调教 | 黄色毛片在线看 | 野狼在线社区2017入口 | 99精品久久99久久久久 | 成人h视频在线 | 中文字幕免费 | 久久精品毛片 | 日韩高清一区二区 | 成人精品在线视频 | av天天干 | 免费精品久久久久久中文字幕 |