수다닷컴

  • 해외여행
    • 괌
    • 태국
    • 유럽
    • 일본
    • 필리핀
    • 미국
    • 중국
    • 기타여행
    • 싱가폴
  • 건강
    • 다이어트
    • 당뇨
    • 헬스
    • 건강음식
    • 건강기타
  • 컴퓨터
    • 프로그램 개발일반
    • C언어
    • 비주얼베이직
  • 결혼생활
    • 출산/육아
    • 결혼준비
    • 엄마이야기방
  • 일상생활
    • 면접
    • 취업
    • 진로선택
  • 교육
    • 교육일반
    • 아이교육
    • 토익
    • 해외연수
    • 영어
  • 취미생활
    • 음악
    • 자전거
    • 수영
    • 바이크
    • 축구
  • 기타
    • 강아지
    • 제주도여행
    • 국내여행
    • 기타일상
    • 애플
    • 휴대폰관련
  • 프로그램 개발일반
  • C언어
  • 비주얼베이직

라운드로빈 스케쥴러..

시아

2023.04.01


질문 제목 : 라운드로빈 스케쥴러 제작 라운드 로빈질문 내용 :
#include stdio.h
#include stdlib.h#define max_queue_length 10000#define quantum 5
struct process_control_block { int state; // 0: not running, 1: running int time_serviced;};
struct process_log { int entry_time; int turnaround_time; int waiting_time;};
struct process { int pid; int arrival_time; int required_service_time; int first_serviced; struct process_control_block pcb; struct process_log log;};
struct process create_process(int pid, int arrival_time, int required_service_time){ struct process p;
p.pid = pid; p.arrival_time = arrival_time; p.required_service_time = required_service_time; p.first_serviced = 1; p.pcb.state = 0; // not running p.pcb.time_serviced = 0; p.log.turnaround_time = 0; p.log.waiting_time = 0;
return(p);}
struct process *process_list;int num_processes;int process_queue[max_queue_length];int f=0, r=0;int queue_size=0;

void push(int p){ if (queue_size max_queue_length) { process_queue[r] = p; r = (r+1)%max_queue_length; queue_size ++; } else { printf(error: queue is full\n); }}
int pop(){ int fprev = f; f = (f+1)%max_queue_length; queue_size --; return(process_queue[fprev]);}
void report_log(int option, int cpu_used, int total_time){ int turnaround_sum = 0; int waiting_sum = 0; int i;
printf(\nlog of process scheduling\n); for(i=0;inum_processes;i++) { printf(pid(%d), process_list[i].pid); printf( turnaround time: %d, process_list[i].log.turnaround_time); printf( waiting time : %d\n, process_list[i].log.waiting_time); turnaround_sum += process_list[i].log.turnaround_time; waiting_sum += process_list[i].log.waiting_time; }
printf(\n-----------------------------------------------------\n); switch (option) { case 1: printf(short-term scheduling method: first-come-first-served\n); break; case 2: printf(short-term scheduling method: round robin\n); break; case 3: printf(short-term scheduling method: shorted process next\n); break; case 4: printf(short-term scheduling method: shorted remaining time\n); break; default: break; } printf(-----------------------------------------------------\n);
printf(\naverage turnaround time: %.2f\n, (float)turnaround_sum / num_processes); printf(average waiting time : %.2f\n, (float)waiting_sum / num_processes); printf(cpu utilization : %.2f%%\n, ((float)cpu_used / total_time)*100);}
struct process *make_process_list(char *filename){ struct process *plist, p; file *process_file; int pid, arrival_time, required_service_time; int i;
process_file=fopen(filename, r);
if (process_file==null) { printf(file open error: %s\n, filename); exit(-1); }
fscanf(process_file, %d, &num_processes); plist = (struct process *) malloc(sizeof(struct process) * num_processes);
// construct process list for(i=0;inum_processes;i++) { fscanf(process_file, %d %d %d, &pid, &arrival_time, &required_service_time); p = create_process(pid, arrival_time, required_service_time);
// add p to the end of process list plist[i] = p; } fclose(process_file); return(plist);}
void admit_to_queue(int t){ static int i = 0;
while (t == process_list[i].arrival_time) { // to handle processes that have same arrival time push(i); process_list[i].log.entry_time = t; printf([%d] pid(%d): entered into queue\n, t, process_list[i].pid); i++; }}
int short_term_schedule(option, pindex, q){ int next_pindex;
next_pindex = pindex;
switch (option) { case 1: // fcfs // if cpu is idle and queue is not empty, pop a process from ready queue if (pindex 0 && queue_size 0) next_pindex = pop(); break;//여기를 수정해야합니다.. case 2: // round robin
// hw4: you should fill here...
break;
case 3: // spn break;
case 4: // sjt break;
default: break; } return next_pindex;}
void preempt_process(int t, int process_index){ printf([%d] pid(%d): preempted\n, t, process_list[process_index].pid);
// hw4: you should fill here...}
int main(int argc, char *argv[]){ int option, total_time; int cpu_used = 0; int num_processed = 0; int t = 0; int q = 0;
int process_index = -1; // cpu is idle with no processes int prev_process_index = -1; int time_serviced, required_service_time;

if (argc != 3) { printf(usage: hw4 option process_file\n); printf( option: 1 (fcfs: first-come-first-served)\n); printf( option: 2 (rr : round robin)\n); printf( option: 3 (spn : shorted process next)\n); printf( option: 4 (srt : shorted remaining time)\n); exit(-1); } else { option = atoi(argv[1]); }
process_list = make_process_list(argv[2]);
while(num_processed num_processes) { // until all processes are processed
// admit process to ready queue admit_to_queue(t);
// short-term scheduling process_index = short_term_schedule(option, prev_process_index, q);
// preempt prev_process_index if (prev_process_index =0 && process_index != prev_process_index) { preempt_process(t, prev_process_index); }
// if cpu is not idle if (process_index =0) { // service one cpu tick to the process if (process_list[process_index].first_serviced) { process_list[process_index].log.waiting_time = t - process_list[process_index].log.entry_time; process_list[process_index].first_serviced = 0; } process_list[process_index].pcb.state = 1; // running if (process_index != prev_process_index) printf([%d] pid(%d): running\n, t, process_list[process_index].pid);
// cpu services one time tick for the process of process_index process_list[process_index].pcb.time_serviced ++; cpu_used ++;
// hw4: modify variable q here... }
t++; // increase a time tick
if (process_index =0) { // check if the current process can be flushed out from cpu time_serviced = process_list[process_index].pcb.time_serviced; required_service_time = process_list[process_index].required_service_time;
if (required_service_time == time_serviced) { printf([%d] pid(%d): finished\n, t, process_list[process_index].pid); num_processed++; process_list[process_index].log.turnaround_time = t - process_list[process_index].log.entry_time; process_index = -1; // indicates cpu is idle now
// hw4: modify variable q here... } } prev_process_index = process_index; }
total_time = t;
report_log(option, cpu_used, total_time);
return(0);}

코드는 이렇게 되있는데 round robin 스케쥴러 짜는건데 빨간색부분을 수정해야하는데 어떻게해야할지모르겟네요 ㅠㅠ1. process list를 구성 할 것2. 새로운 process가 발생하면 process를 creation하여 list에추가3. creation된 process는 process 정보 (process id, cpuexecution time)와 process control block으로 구성됨• process control block에는 process 상태 (running, not-running등) 등의 정보를 담고 있음실제 과제 평가에 사용될 process list는 약 수 만개 정도의process 들을 가지는 list를 사용할 예정임이것이 요구조건인데..힌트들을 보자면,

• 내부적으로 가상의 현재 시간 t를 두고 loop을 한바뀌 돌때마다 1씩 증가시킨다.1. process list, queue 등 자료구조를 만든다.2. process file list를 읽어 들여 process list를 만든다.• array, vector, linked-list 형태이든 상관없음3. queue를 초기화 한다.4. 현재 시간 t를 0으로 초기화 한다.5. while loop (모든 process가 처리되기 전까지)a. process admissionprocess 중 arrival time이 현재시간인 process를 ready queue에 집어 넣는다.b. short-term scheduler를 이용해서 다음번에 수행할 process를 고른다c. 이전에 수행중인 process와 다음 번 수행할 process가 다르면,해당 process를 시간 1 만큼 서비스 한다.d. 시간 t를 1만큼 증가 시킨다.e. 현재 cpu가 처리중인 process의 required_service_time이 전부 처리 되었는지확인하여 처리 완료 시킨다.6. turnaround time, waiting time, cpu utilization 등 로그 결과를 리포트 한다

신청하기





COMMENT

댓글을 입력해주세요. 비속어와 욕설은 삼가해주세요.

번호 제 목 글쓴이 날짜
2699476 끌어올림;;달력 짜봤는데요 이 소스 줄일 수 있나요? - 스샷첨부 (2) 클라우드 2025-06-26
2699444 [좀 급함] system("explorer [주소] ") 문에 변수를 사용할 수 있나요? 알 2025-06-26
2699415 파일//read//와 배열 아란 2025-06-25
2699386 구조체 안에 일부분만 char 배열에 복사하려면 어떻게 해야하나요? (1) 미즈 2025-06-25
2699361 연결리스트 정렬하는 부분에 대해서 질문 드립니다 아이처럼 2025-06-25
2699304 [기초]아직 안주무시는분 계신가요..?포인터배열? 좀 도와주세요. 놀리기 2025-06-24
2699272 printf() 함수이용해서 프로그램 만들기 질문요! (5) 다가 2025-06-24
2699221 PUSH와 POP코드를 더 간단하게 어떻게 해야할까요? 파라미 2025-06-24
2699192 설치오류가 자꾸 나요 한번봐주세여~ (1) 소녀틳향기 2025-06-23
2699161 for loop안에 있는 if문 (9) Orange 2025-06-23
2699105 링크더리스트 이전 링크값 출력함수. 꼬꼬마 2025-06-23
2699078 정수를 한자리씩 배열에 담는 법은 어떻게 하나요.. (4) 귀염포텐 2025-06-22
2699024 C언어 공부하려는데 도와주세요!!! (2) 달님 2025-06-22
2698994 날짜 계산하는 C 코드 짜고 있는데 꽉 막혀서 질문드립니다.. (6) 별 2025-06-22
2698967 파일삭제 윈도우 폴더까지 접근하게하는 함수가 뭔가요 (2) 샤인 2025-06-21
2698938 c언어 메모리질문 (3) 나래 2025-06-21
2698909 서비스 요청 고객 관리 프로그램 짜는것좀 도와주세요ㅜㅜ (4) 궁수자리 2025-06-21
2698882 프로그래밍좀 짜주세요 (3) 황예 2025-06-21
2698855 카프-라빈 알고리즘 코딩 분석좀 도와주세요.. 꽃봄 2025-06-20
2698829 학점계산기 (7) MyWay 2025-06-20
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

수다닷컴 | 여러분과 함께하는 수다토크 커뮤니티 수다닷컴에 오신것을 환영합니다.
사업자등록번호 : 117-07-92748 상호 : 진달래여행사 대표자 : 명현재 서울시 강서구 방화동 890번지 푸르지오 107동 306호
copyright 2011 게시글 삭제 및 기타 문의 : clairacademy@naver.com