仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 727|回复: 13
打印 上一主题 下一主题

[其他Linux] 来讲讲:linux历程调剂摹拟

[复制链接]
第二个灵魂 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 12:08:41 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
当你经过一段时间的学习后就应该扩充自己的知识,多学习linux命令,但是不要在初学阶段就系统的学习linux命令。
/*摹拟完成LINUX历程调剂的静态优先级算法和工夫片轮转算法引进LINUX调剂
*/
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
#include<sys/stat.h>
#include<sys/types.h>
#defineRUN1
#defineSLEEP0
#defineREADY2
#defineDEG_SCHEDULE
#defineNUM6
structOSPCB
{
intPcbName;/*历程名字*/
intReqCount;/*历程实行计数*/
intRunTime;/*历程实行工夫数*/
intPrority;/*历程优先级*/
intPcbStatus;/*历程形态*/
intPcbTime;/*历程工夫片*/
structOSPCB*prev;
structOSPCB*next;
};
structProcessQueue/*摹拟CPU调剂行列*/
{
structOSPCB*PointerHead;/*指向历程链表头*/
intPcbNumber;/*CPU每次调剂计数器*/
};
//staticstructCriticalResource
//{
//intflag;
//charBufferVoice[2000];
//}
staticintflag;
void*Function(int*arg);
voidInitPcb(structOSPCB*pcb);
intSchedule(structProcessQueue*queue);
voidInheritSchedule(structOSPCB*pcb);
intmain(void)
{
inti,ret;
structOSPCB*pNewPcb,*pNew;
structProcessQueue*pNewQueue;
inta[4][4]={{1,1,0,1},{2,2,0,2},{3,3,0,3},{4,4,0,4}};
pNewQueue=(structProcessQueue*)malloc(sizeof(structProcessQueue));
pNewQueue->PointerHead=NULL;
pNewQueue->PcbNumber=0;
for(i=0;i<4;i++)/*历程初始化*/
{
pNewPcb=(structOSPCB*)malloc(sizeof(structOSPCB));
pNewPcb->PcbName=a[0];
pNewPcb->ReqCount=a[1];
pNewPcb->RunTime=a[2];
pNewPcb->Prority=a[3];
pNewPcb->PcbStatus=READY;
pNewPcb->PcbTime=3;
InitPcb(pNewPcb);
if(pNewQueue->PointerHead==NULL)
{
pNewQueue->PointerHead=pNewPcb;
}else{
&nbsp</p>
123下一页


每一个开发团队都对他的发行版做过测试后放出的.那些国际知名的大品牌更是如此。
第二个灵魂 该用户已被删除
沙发
 楼主| 发表于 2015-1-16 13:13:59 | 显示全部楼层

来讲讲:linux历程调剂摹拟

如果你让他去用linux搭建一个web服务器,做一个linux网关,他就什么都不会了.他们把时间都浪费在了版本的转换上了.
;pNew->next=pNewPcb;
pNewPcb->prev=pNew;
}
pNew=pNewPcb;
pNewQueue->PcbNumber++;
}
#if0
for(p=pNewQueue->PointerHead;p!=NULL;p=p->next)
{
printf("processname=%d\n",p->PcbName);
}
#endif
Schedule(pNewQueue);/*进进历程调剂*/
return0;
}
voidInitPcb(structOSPCB*pcb)
{
pcb->prev=NULL;
pcb->next=NULL;
}
intSchedule(structProcessQueue*queue)/*历程调剂*/
{
structOSPCB*pcb,*CurrRun;
intvalue,SechNumber=8;
pthread_tpthread_id[NUM];
inti=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,NULL,(void*)Function,&(CurrRun->PcbName));
}
#ifdefDEG_SCHEDULE
printf("presentprocess=%dCurrRun->ReqCount=%d\n",CurrRun->PcbName,CurrRun->ReqCount);
#endif
if(CurrRun->PcbTime==0)
{
CurrRun->Prority-=4;/*历程处分性降优先级处置*/
}
if(CurrRun->ReqCount==0)
{
if(CurrRun==queue->PointerHead)
{
queue->PointerHead=CurrRun->next;
}elseif(CurrRun->next!=NULL){
&n</p>
上一页123下一页


如果你学不好的话,你在linux中开发的机会就很少,或者说几乎没有,它的优势就消失了,然后随着时间的流逝,你就会全部忘记她;
第二个灵魂 该用户已被删除
板凳
 楼主| 发表于 2015-1-16 13:31:42 | 显示全部楼层

来讲讲:linux历程调剂摹拟

linux系统的文件布置,etc/,opt/目录的内容等;
bsp;CurrRun->prev->next=CurrRun->next;
CurrRun->next->prev=CurrRun->prev;
}else{
CurrRun->prev->next=NULL;
}
//printf("Runprocessname=%dReqcount=%dSechedulecount=%d\n",CurrRun->PcbName,CurrRun->ReqCount,SechNumber);
}
if(SechNumber==0)/*工夫片用完从头调剂*/
{
Schedule(queue);
}
}
return0;
}
voidSleepProcess(void)
{
}
voidDeleteProcess(void)
{
//return0;
}
void*Function(int*arg)/*历程实行函数*/
{
inti,count=0;
intPthreadName;
structOSPCB*pNew;
pNew=(structOSPCB*)arg;
PthreadName=*(int*)arg;
#ifdefDEG_SCHEDULE
printf("Enterthefunctionprocess%d\n",PthreadName);
#endif
while(1)
{
if(flag==0)/*会见临界区资本*/
{
flag=1;
#ifdefDEG_SCHEDULE
printf("getlcokinprocess%d\n",PthreadName);
#endif
for(i=0;i<10000;i++)
{
pNew->PcbStatus=SLEEP;
sleep(1);
}
flag=0;/*开释临界区资本*/
break;
}else{/*自旋直到失掉可会见的临界区资本*/
count++;
if(count==5000)
{
#ifdefDEG_SCHEDULE
printf("flag=%dcannotgetlockinprocessname%d\n",flag,PthreadName);
#endif
}
}
}
#ifdefDEG_SCHEDULE
printf("flag=%doutprocess%d\n",flag,PthreadName);
#endif
}</p>
上一页123


开发linux发行版的人都是通读过linux内核代码,对linux原理极其精通的人。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-31 16:19

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表