• 전문가 요청 쿠폰 이벤트
*종*
Bronze개인
팔로워0 팔로우
소개
등록된 소개글이 없습니다.
전문분야 등록된 전문분야가 없습니다.
판매자 정보
학교정보
입력된 정보가 없습니다.
직장정보
입력된 정보가 없습니다.
자격증
  • 입력된 정보가 없습니다.
판매지수
전체자료 1
검색어 입력폼
  • [운영체재론] 스케줄러 평가A좋아요
    #include #include #include #define TIME_SLICE 4 // 시간 할당량의 크기#define N 3 // I/O 장치의 수#define READY 0 // 프로세스 상태#define RUNNING 1#define WAIT 2#define TERMINATED 3#define DISK 0 // Device 종류#define TERMINAL 1#define TAPE 2#define IO_TIME_MIN 1 // I/O요구 시간#define IO_TIME_MAX 5#define PCB_MIN 5 // 프로세스의 길이#define PCB_MAX 10#define P_NUM_MIN 5 // 프로세스의 갯수#define P_NUM_MAX 9#define ON 1#define OFF 0typedef struct _proc // PCB를 선언{int pid; // Process IDint priority; // 우선순위int state; // 실행상태 [READY | RUNNING | WAIT | TERMINATED]int pc; // 문맥교환을 위한 프로그램 카운터int length; // 프로세스의 크기int io_need_time; // I/O에 필요한 시간int which_dev; // 장치종류 [DISK | TERMINAL | TAPE]struct _proc *next; // 다음프로세스의 포인터struct _proc *prev; // 이전프로세스의 포인터} proc;int HW_PC = 0; // Hardware PCint runrun ; // 문맥교환이 필요한가를 나타냄 [0:상태유지 | 1:필요]int time_progress; // TIME_SLICE를 측정하기 위한 변수int global_time = 0; // 전역시간을 나타내는 변수int io_request; // 프로세스가 I/O작업을 요청했음을 표시함proc *cur_proc; // 현재 프로세스proc *Ready_Q; // Ready Queproc *Wait_Q[N];큐에서 제거void insert_queue( proc *current, proc *Queue ); // Queue 맨 뒤쪽에 cur_proc를 추가void interrupt( proc *current, proc *target_Q ); // cur_proc을 From_Q[i]에서 To_Q로 이동void destroy_queue( proc *Queue ); // Queue를 메모리에서 제거void print_queue( proc *Queue ); // Queue의 내용을 출력void main(){int num_of_proc;srand(time( NULL ) );runrun = ON;io_request = OFF;do {num_of_proc = (rand() % 20) + 1;}while (num_of_proc next || Wait_Q[0]->next || Wait_Q[1]->next || Wait_Q[2]->next ){ // 실행할 프로세스가 남아있으면 수행한다printf( "%d: ", global_time );if( runrun ) // 문맥교환할때가 되었으면{cur_proc = dequeue( Ready_Q ); // Ready_Q 맨 앞의 포인터를 가져온다if( cur_proc ) // cur_proc이 NULL이 아니면 HW_PC에 문맥 복구{printf( "tGet process [%d]n", cur_proc->pid );HW_PC = cur_proc->pc;}runrun = OFF; // 문맥교환 변수 OFFtime_progress = 0; // TIME_SLICE만큼 돌았는지 확인하기 위한 변수를 초기화}//////////////////////////////////////////// start if ////////////////////////////////////////////if( !cur_proc ) // Ready_Q 에서 꺼내온게 NULL 이라면, (Ready_Q가 비었으면)runrun = ON;else // 레디큐에서 정상적으로 꺼내run = ON;}else if( io_request ) // I/O 요청을 받았으면{io_request = OFF;cur_proc->state = WAIT; // 현재 프로세스 상태를 'WAIT'cur_proc->pc = HW_PC; // 현재까지 실행한 내용을 pc에 저장cur_proc->which_dev = rand() % 3;// 디바이스 종류를 임의로 설정cur_proc->io_need_time = rand() % (IO_TIME_MAX-IO_TIME_MIN+1) + IO_TIME_MIN;// I/O 소요시간을 1~9 사이로 설정delete_queue( cur_proc ); // Ready_Q에서 빼서insert_queue( cur_proc, Wait_Q[cur_proc->which_dev] );// 적당한 WAIT_Q[x]에 집어넣는다printf( "tMove process [%d] to Wait_Q[%d] from Ready_Q (I/O Time: %d)n",cur_proc->pid, cur_proc->which_dev, cur_proc->io_need_time );runrun = ON;}else // 실행이 끝난것도 아니고 I/O 요청도 없으면 프로세스를 처리한다{HW_PC++; // 실행된 시간을 1 증가time_progress++; // TIME_SLICE 체크용printf( "tProcess [%d] executed %d/%dn", cur_proc->pid, HW_PC, cur_proc->length );if( time_progress == TIME_SLICE ) // TIME_SLICE만큼 실행했으면{cur_proc->pc = HW_PC; // HW_PC값 저장runrun = ON; // 문맥교환 준비하고cur_proc->priority++; // 우선순위를 낮추고update_queue( Ready_Q ); // 프로세스를 우선순위에 따라 Ready_Q를 재조정}}}/////////////////////////////////////un = ON; // 문맥교환 요청if( cur_proc ) cur_proc->pc = HW_PC;// cur_proc이 NULL이 아니면 pc에 실행된 시간 저장printf( "tMove process [%d] to Ready_Q form Wait_Q[%d]n", tmp->pid, i );}else{tmp->io_need_time--; // I/O 처리printf( "tProcess [%d] I/O need time decreased to %d (On Device : %d)n",tmp->pid, tmp->io_need_time, i );}}}global_time++; // 전체시간 증가if( global_time % 5 == 0 ) // 전체시간이 5의 배수일때마다 I/O 요청io_request = ON;}printf( "nZombie Queue Status :n" );print_queue( Zombie_Q ); // Zombie_Q에 들어있는 내용을 출력destroy_queue( Ready_Q );destroy_queue( Wait_Q[0] );destroy_queue( Wait_Q[1] );destroy_queue( Wait_Q[2] );destroy_queue( Zombie_Q ); // 큐들을 메모리에서 해제하고 종료}void creat_proc( int num_of_proc ){init_proc(); // 각각 Queue들의 Linked List를 초기화한다int i, pid = 0;for( i=0 ; iio_need_time = 0; // IO에 필요한 시간p->pc = 0; // 프로그램 카운터는 맨 앞p->pid = pid; // 0부터 하나씩 증가p->priority = rand() % 21; // 우선순위는 0~20p->state = READY; // Ready!!p->which_dev = 0; // 디바이스 종류p->length = rand() % (PCB_MAX-PCB_MIN+1) + PCB_MIN;// 프로세스의 길이는 PC = NULL;Ready_Q->prev = Ready_Q;Zombie_Q = ( proc* )malloc( sizeof( proc ) );Zombie_Q->next = NULL;Zombie_Q->prev = Zombie_Q;for( i=0 ; inext = NULL;Wait_Q[i]->prev = Wait_Q[i];}}proc *dequeue( proc *Queue ){return Queue->next; // Head 뒤의 포인터를 리턴}void delete_queue( proc *current ){current->prev->next = current->next; // current 노드를 제거if( current->next )current->next->prev = current->prev;}void insert_queue( proc *current, proc *Queue ){proc *tmp;tmp = Queue;while( tmp->next )tmp = tmp->next; // 최종적으로 tmp는 Queue의 꼬리를 가리킴current->prev = tmp;current->next = NULL;tmp->next = current; // 꼬리 뒤에다 current를 삽입}void update_queue( proc *Queue ){int i, j, length = 0; // Ready_Q를 priority 기준으로 버블소트proc *t1, *t2, *tmp, *count;count = Queue->next;while( count ){length++;count = count->next;}if( length > 1 ){for( i=0 ; inext;t2 = Queue->next->next;for( j=0; jpriority > t2->priority ){t1->prev->next = t2;if( t2->next )t2->next->prev = t1;t1->next = t2->next;t2->prev = t1->prev;t1->prev = t2;t2->next =
    공학/기술| 2002.04.30| 9페이지| 1,000원| 조회(845)
    미리보기
전체보기
받은후기 2
2개 리뷰 평점
  • A+최고예요
    0
  • A좋아요
    1
  • B괜찮아요
    1
  • C아쉬워요
    0
  • D별로예요
    0
전체보기
해캠 AI 챗봇과 대화하기
챗봇으로 간편하게 상담해보세요.
2026년 03월 31일 화요일
AI 챗봇
안녕하세요. 해피캠퍼스 AI 챗봇입니다. 무엇이 궁금하신가요?
2:33 오후
문서 초안을 생성해주는 EasyAI
안녕하세요 해피캠퍼스의 20년의 운영 노하우를 이용하여 당신만의 초안을 만들어주는 EasyAI 입니다.
저는 아래와 같이 작업을 도와드립니다.
- 주제만 입력하면 AI가 방대한 정보를 재가공하여, 최적의 목차와 내용을 자동으로 만들어 드립니다.
- 장문의 콘텐츠를 쉽고 빠르게 작성해 드립니다.
- 스토어에서 무료 이용권를 계정별로 1회 발급 받을 수 있습니다. 지금 바로 체험해 보세요!
이런 주제들을 입력해 보세요.
- 유아에게 적합한 문학작품의 기준과 특성
- 한국인의 가치관 중에서 정신적 가치관을 이루는 것들을 문화적 문법으로 정리하고, 현대한국사회에서 일어나는 사건과 사고를 비교하여 자신의 의견으로 기술하세요
- 작별인사 독후감