进程调度Word文档格式.docx

上传人:b****2 文档编号:4591618 上传时间:2023-05-03 格式:DOCX 页数:21 大小:291.24KB
下载 相关 举报
进程调度Word文档格式.docx_第1页
第1页 / 共21页
进程调度Word文档格式.docx_第2页
第2页 / 共21页
进程调度Word文档格式.docx_第3页
第3页 / 共21页
进程调度Word文档格式.docx_第4页
第4页 / 共21页
进程调度Word文档格式.docx_第5页
第5页 / 共21页
进程调度Word文档格式.docx_第6页
第6页 / 共21页
进程调度Word文档格式.docx_第7页
第7页 / 共21页
进程调度Word文档格式.docx_第8页
第8页 / 共21页
进程调度Word文档格式.docx_第9页
第9页 / 共21页
进程调度Word文档格式.docx_第10页
第10页 / 共21页
进程调度Word文档格式.docx_第11页
第11页 / 共21页
进程调度Word文档格式.docx_第12页
第12页 / 共21页
进程调度Word文档格式.docx_第13页
第13页 / 共21页
进程调度Word文档格式.docx_第14页
第14页 / 共21页
进程调度Word文档格式.docx_第15页
第15页 / 共21页
进程调度Word文档格式.docx_第16页
第16页 / 共21页
进程调度Word文档格式.docx_第17页
第17页 / 共21页
进程调度Word文档格式.docx_第18页
第18页 / 共21页
进程调度Word文档格式.docx_第19页
第19页 / 共21页
进程调度Word文档格式.docx_第20页
第20页 / 共21页
亲,该文档总共21页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

进程调度Word文档格式.docx

《进程调度Word文档格式.docx》由会员分享,可在线阅读,更多相关《进程调度Word文档格式.docx(21页珍藏版)》请在冰点文库上搜索。

进程调度Word文档格式.docx

}

deqcmd.type=DEQ;

deqcmd.defpri=0;

deqcmd.owner=getuid();

deqcmd.argnum=1;

strcpy(deqcmd.data,*++argv);

printf("

jid%s\n"

deqcmd.data);

if((fd=open("

/tmp/server"

O_WRONLY))<

0)

deqopenfifofailed"

//?

?

if(write(fd,&

deqcmd,DATALEN)<

0)//?

deqwritefailed"

close(fd);

return0;

}

Enq.c代码:

intp=0;

charc,*offset;

structjobcmdenqcmd;

if(argc==1){

enq[-pnum]e_fileargs\n"

\t-pnum\t\tspecifythejobpriority\n"

\te_file\t\ttheabsolutepathoftheexefile\n"

\targs\t\ttheargspassedtothee_file\n"

while(--argc>

0&

&

(*++argv)[0]=='

-'

){

c=*++argv[0];

switch(c){

case'

p'

:

p=atoi(*(++argv));

argc--;

break;

default:

printf("

Illegaloption%c\n"

c);

return1;

}

if(p<

0||p>

3)

p=0;

enqcmd.type=ENQ;

enqcmd.defpri=p;

enqcmd.owner=getuid();

enqcmd.argnum=argc;

offset=enqcmd.data;

while(argc-->

0){

strcpy(offset,*argv);

strcat(offset,"

"

offset=offset+strlen(*argv)+1;

argv++;

#ifdefDEBUG

enqcmdcmdtype\t%d\n"

enqcmdowner\t%d\n"

enqcmddefpri\t%d\n"

enqcmddata\t%s\n"

enqcmd.type,enqcmd.owner,enqcmd.defpri,enqcmd.data);

#endif

enqopenfifofailed"

enqcmd,DATALEN)<

enqwritefailed"

Job.c代码:

stdio.h>

sys/time.h>

sys/wait.h>

signal.h>

time.h>

voidsig_handler(intsig,siginfo_t*info,void*notused);

voidschedule();

intallocjid();

voiddo_enq(structjobinfo*newjob,structjobcmdenqcmd);

voiddo_deq(structjobcmddeqcmd);

voiddo_stat(structjobcmdstatcmd);

voidupdateall();

structwaitqueue*jobselect();

voidjobswitch();

intjobid=0;

intsiginfo=1;

intfifo;

intglobalfd;

structwaitqueue*head=NULL;

structwaitqueue*next=NULL,*current=NULL;

intmain()

structtimevalinterval;

structitimervalnew,old;

structstatstatbuf;

structsigactionnewact,oldact1,oldact2;

if(stat("

&

statbuf)==0){//?

if(remove("

)<

printf("

removefailed"

if(mkfifo("

0666)<

mkfifofailed"

if((fifo=open("

O_RDONLY|O_NONBLOCK))<

openfifofailed"

if((globalfd=open("

/dev/null"

openglobalfilefailed"

newact.sa_sigaction=sig_handler;

sigemptyset(&

newact.sa_mask);

newact.sa_flags=SA_SIGINFO;

sigaction(SIGCHLD,&

newact,&

oldact1);

sigaction(SIGVTALRM,&

oldact2);

interval.tv_sec=0;

interval.tv_usec=100;

new.it_interval=interval;

new.it_value=interval;

setitimer(ITIMER_VIRTUAL,&

new,&

old);

while(siginfo==1)

;

close(fifo);

close(globalfd);

voidsig_handler(intsig,siginfo_t*info,void*notused)

intstatus;

intret;

switch(sig){

caseSIGVTALRM:

schedule();

return;

caseSIGCHLD:

ret=waitpid(-1,&

status,WNOHANG);

if(ret==0)

return;

if(WIFEXITED(status)){//?

current->

job->

state=DONE;

normaltermation,exitstatus=%d\n"

WEXITSTATUS(status));

}else

if(WIFSIGNALED(status)){

printf("

abnormaltermation,signalnumber=%d\n"

}else

if(WIFSTOPPED(status)){

printf("

childstopped,signalnumber=%d\n"

WSTOPSIG(status));

}

default:

voidschedule()

structjobinfo*newjob=NULL;

structjobcmdcmd;

intcount=0;

bzero(&

cmd,DATALEN);

if((count=read(fifo,&

cmd,DATALEN))<

readfifofailed"

#ifdefDEBUG//?

/

if(count){

cmdcmdtype\t%d\n"

"

cmddefpri\t%d\n"

cmddata\t%s\n"

cmd.type,cmd.defpri,cmd.data);

}else

nodataread\n"

switch(cmd.type){

caseENQ:

do_enq(newjob,cmd);

break;

caseDEQ:

do_deq(cmd);

caseSTAT:

do_stat(cmd);

updateall();

next=jobselect();

jobswitch();

voiddo_enq(structjobinfo*newjob,structjobcmdenqcmd)

structwaitqueue*newnode,*p;

inti=0,pid;

char*offset,*argvec,*q;

char**arglist;

sigset_tzeromask;

zeromask);

newjob=(structjobinfo*)malloc(sizeof(structjobinfo));

newjob->

jid=allocjid();

defpri=enqcmd.defpri;

curpri=enqcmd.defpri;

ownerid=enqcmd.owner;

state=READY;

create_time=time(NULL);

wait_time=0;

run_time=0;

arglist=(char**)malloc(sizeof(char*)*(enqcmd.argnum+1));

cmdarg=arglist;

argvec=enqcmd.data;

while(i<

enqcmd.argnum){

if(*offset=='

'

*offset++='

\0'

;

q=(char*)malloc(offset-argvec);

strcpy(q,argvec);

arglist[i++]=q;

argvec=offset;

offset++;

arglist[i]=NULL;

enqcmdargnum%d\n"

enqcmd.argnum);

for(i=0;

i<

enqcmd.argnum;

i++)

parseenqcmd:

%s\n"

arglist[i]);

newnode=(structwaitqueue*)malloc(sizeof(structwaitqueue));

newnode->

next=NULL;

job=newjob;

if(head){

for(p=head;

p->

next!

=NULL;

p=p->

next);

p->

next=newnode;

}else

head=newnode;

if((pid=fork())<

enqforkfailed"

if(pid==0){

newjob->

pid=getpid();

raise(SIGSTOP);

beginrunning\n"

for(i=0;

arglist[i]!

arglist%s\n"

dup2(globalfd,1);

if(execv(arglist[0],arglist)<

execfailed\n"

exit

(1);

}else{

pid=pid;

intallocjid()

return++jobid;

voiddo_deq(structjobcmddeqcmd)

intdeqid,i;

structwaitqueue*p,*prev,*select,*selectprev;

deqid=atoi(deqcmd.data);

deqjid%d\n"

deqid);

if(current&

current->

jid==deqid){

terminatecurrentjob\n"

kill(SIGKILL,current->

pid);

(current->

cmdarg)[i]!

free((current->

cmdarg)[i]);

free(current->

cmdarg);

job);

free(current);

current=NULL;

select=NULL;

selectprev=NULL;

for(prev=NULL,p=head;

p!

prev=p,p=p->

next)

if(p->

jid==deqid)

if(p!

=NULL){

if(prev==NULL)

head=NULL;

else

prev->

next=p->

next;

(p->

free((p->

free(p->

free(p);

p=NULL;

voiddo_stat(structjobcmdstatcmd)

structwaitqueue*p;

chartimebuf[BUFLEN];

JOBID\tPID\tOWNER\tRUNTIME\tWAITTIME\tCREATTIME\tSTATE\n"

if(current){

strcpy(timebuf,ctime(&

(current->

create_time)));

timebuf[strlen(timebuf)-1]='

%d\t%d\t%d\t%d\t%d\t%s\t%s\n"

current->

jid,

pid,

ownerid,

run_time,

wait_time,

timebuf,

RUNNING"

for(p=head;

next){

(p->

READY"

voidupdateall()

if(current)

current->

run_time+=1;

wait_time+=100;

if(p->

wait_time>

=1000&

p->

curpri<

p->

curpri++;

structwaitqueue*jobselect()

inthighest=-1;

select=NULL;

selectprev=NULL;

for(prev=NULL,p=head;

curpri>

highest){

select=p;

selectprev=prev;

highest=p->

curpri;

if(select!

if(selectprev!

=NULL)

selectprev->

next=select->

else

head=NULL;

returnselect;

voidjobswitch()

inti;

if(current!

=NULL&

state==DONE){

free((current->

free(current->

if(next==NULL&

current==NULL)

return;

else

if(next!

current==NULL){

beginstartnewjob\n"

current=next;

next=NULL;

state=RUNNING;

kill(current->

pid,SIGCONT);

return;

if(next!

current!

beginswitch\n"

kill(current->

pid,SIGSTOP);

curpri=current->

defpri;

if(head!

for(p=head;

next)

;

p->

next=current;

head=current;

current=next;

next=NULL;

job-

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2