// 프로세스의 해당 라인에 void printService(int current_process, int service_time) { int i = 0; // 커서 옴겨서 setCursorMove(xcur, ycur+current_process); // 서비스 타임 만큼 찍는다. for(i = 0; i < service_time ; i++) { printf("%s",str); xcur += str_size; } }
int main(void) { Scheduling_Policy simulater[3] = {{"FCFS",FCFS},{"RR",RR},{"HRRN",HRRN}}; Queue *ready_queue = new_Queue(); //준비상태 큐 생성 Queue *wait_queue = new_Queue(); //대기상태 큐 생성 int i = 0, j = 0; int policy_count = sizeof(simulater)/sizeof(Scheduling_Policy); int process_count = 5; Process *head = NULL; //프로세스 구조체 형의 head 생성, 초기화 if(ready_queue == NULL || wait_queue == NULL) return; default_wait_queue(wait_queue); //초기 대기상태 큐에 프로세스 정책 삽입 time_axis = wait_queue->head->arrival_time; //프로세스의 최초 수행시간을 고려하기 위해 첫 프로세스의 수행시작시간을 별도 관리 // 모든 프로세스 수행 시간 //초기값 = 큐의 head, null이 아닐동안, 다음 프로세스로 진행 for(head = wait_queue->head ; head!=NULL; head = head->next) total_service_time += head->service_time; //큐에 들어온 프로세스의 서비스타임의 총합 system("clear"); printf("<Scheduling Simulater>\n"); printf("policy / time\n"); for(i = 0; i < policy_count ; i++) { // 스케줄링 정책 이름 printf("%s\t",simulater[i].name); // 시간 축 출력 for(j = time_axis; j <total_service_time+time_axis; j++) printf("%-8d",j); printf("\n"); for(head = wait_queue->head; head!=NULL; head = head->next) printf("%c\n",head->name); printf("\n"); } // 스케줄링 정책 모두 실행 for(i=0; i < policy_count ;i++) { simulater[i].scheduling(wait_queue, ready_queue); default_wait_queue(wait_queue); } // 커서 제자리에 setCursorMove(0,25); }
void RR(Queue* wait_queue, Queue* ready_queue) { int time = 0, time_flow = 0; const int RR_quantum = quantum; xcur = start; ycur += 7; Process* current = NULL; setCursorMove(xcur,ycur); // RR 찍기 // 총 수행시간 동안 while(time < total_service_time) { // 큐에 수행시간 동안 들어온 새 프로세스를 담는다. while(wait_queue->head != NULL) { if(wait_queue->head->arrival_time <= time) push(ready_queue, pop(wait_queue)); else break; } // 프로세스가 실행이 남아 아래서 해제가 안됬을 경우 // 다시 준비 큐에 삽입 if(current != NULL) push(ready_queue, current); // 레디 큐에 프로세스가 있을 경우 if(ready_queue->head != NULL) { // 꺼내서 수행시키고, 시간 업데이트 current = pop(ready_queue); // 수행시간은 할당된 시간과 서비스 시간 중 작은 것으로 한다. time_flow = current->service_time < RR_quantum ? current->service_time : RR_quantum; printService(current->order,time_flow); current->service_time -= RR_quantum; // 만일 프로세스가 다 수행되었다면 메모리 해제 if(current->service_time <= 0) free(current); } // 시간 업데이트 time += time_flow; } }
void FCFS(Queue* wait_queue, Queue* ready_queue) { int time = 0; xcur = start; //커서의 x 위치 초기화 ycur = 3; //커서의y 위치 초기화 Process* current = NULL; //현재 진행중인 process 초기화 setCursorMove(xcur,ycur); //커서 초기위치로 이동 // FCFS 찍기 while(time < total_service_time && wait_queue->head!=NULL) { current = pop(wait_queue); printService(current->order, current->service_time); time += current->service_time; free(current); } }
void HRRN(Queue* wait_queue, Queue* ready_queue) { int time=0; xcur = start; ycur += 7; Process*list=NULL; Process*temp=NULL; setCursorMove(xcur,ycur); /* HRRN 찍기 */ while(time<total_service_time) { while(wait_queue->head!=NULL)//input and sort list { temp=pop(wait_queue); float p=priorty(temp,time); Process * search; if(list==NULL) list=temp; else if(p>1 && p>priorty(list,time)) { temp->next=list; list=temp; } else { search=list; while(search->next!=NULL) search=search->next; search->next=temp; } } printService(list->order,list->service_time); time+=list->service_time; list=list->next; while(list!=NULL)//push queue { push(wait_queue,copy_Process(list)); list=list->next; } } }
// private QVariant kpAbstractSelectionTool::operationMove (Operation op, const QVariant &data1, const QVariant &data2) { (void) data1; (void) data2; switch (op) { case HaventBegunDrawUserMessage: return /*virtual*/haventBegunDrawUserMessageMove (); case SetCursor: setCursorMove (); break; case BeginDraw: beginDrawMove (); break; case Draw: drawMove (currentPoint (), normalizedRect ()); break; case Cancel: cancelMove (); break; case EndDraw: endDrawMove (); break; default: Q_ASSERT (!"Unhandled operation"); break; } return QVariant (); }