스케줄링 알고리즘 질문입니다.
슬아라
질문 제목 : 스케줄링 알고리즘 질문입니다.밑에 소스 코드입니다. 거의 다했는데 계속 오류가 뜨네요 문법적으로는 오류가 없는거 같은데 머가 잘못된 거죠?
고수 님들의 조언 부탁드립니다.질문 내용 :
#includestdio.h
#includestdlib.h
struct process{
char name[10]; // process name
int arrival_time; // process arrival time
int burst_time; // burst time
int run;
int processno; // 입력받은 프로세스에 따른 번호 할당
int turnaround; // turnaround time
int waiting; // 대기시간
};
int total=0;
struct process temp; //프로세스를 고체하기 위하여 필요한 임시공간
struct process* proc=(struct process*)malloc(sizeof(struct process)*5);
struct process* queue=(struct process*)malloc(sizeof(struct process)*5);
void func_print(){
int* gantt=(int*)malloc(sizeof(int)*total);
int i=0, turnaround=0;
for (i=0,turnaround=0; i5; i++){
turnaround+=queue[i].turnaround;
}// 반환시간
printf(\n1. print gantt chart\n);
for (i=0; itotal; i++){
printf (%d,gantt[i]);
}//draw gantt chart!
printf(\n 2. average turnaround time \n); //turnaround time
printf(\n);
}//function print
void fcfs(){//fcfs
int* gantt=(int*)malloc(sizeof(int)*total);
int a, i=0;
for (a=0; a5; a++){
while ( queue[a].burst_time 0 ){
gantt[i]=queue[a].processno;
queue[a].burst_time--;
i++;
queue[a].turnaround = i-queue[a].arrival_time;
queue[a].waiting = queue[a].turnaround - queue[a].run;
}
}
func_print(queue,gantt);
printf(--------------turn_around time---------------\n);
printf(|%s %s %s %s %s \tave |\n, queue[0].name, queue[1].name,
queue[2].name, queue[3].name, queue[4].name);
printf(|%d %d %d %d %d %f|\n, queue[0].turnaround, queue[1].turnaround,
queue[2].turnaround, queue[3].turnaround, queue[4].turnaround, (float)queue[a].turnaround/5);
printf(-----------------------------------------------\n);
}
void np_sjf(){//sjf
int* gantt=(int*)malloc(sizeof(int)*total);
int b, i=0, a=0;
while (a5){
while ( queue[a].burst_time 0 ){
gantt[i]=queue[a].processno;
queue[a].burst_time--;
i++;
queue[a].turnaround = i-queue[a].arrival_time;
queue[a].waiting = queue[a].turnaround - queue[a].run;
}
a++;
for (b=a+1; b5; b++)
if (queue[b].arrival_time = i && queue[a].burst_time queue[b].burst_time){
temp=queue[b];
queue[b]=queue[a];
queue[a]=temp;
}
}
func_print(queue,gantt);
printf(--------------turn_around time---------------\n);
printf(|%s %s %s %s %s \tave |\n, queue[0].name, queue[1].name,
queue[2].name, queue[3].name, queue[4].name);
printf(|%d %d %d %d %d %f|\n, queue[0].turnaround, queue[1].turnaround,
queue[2].turnaround, queue[3].turnaround, queue[4].turnaround, (float)queue[a].turnaround/5);
printf(-----------------------------------------------\n);
}
void p_sjf(){//srt
int* gantt=(int*)malloc(sizeof(int)*total);
int b, i=0, a=0;
while (a5){
while ( queue[a].burst_time 0 ){
for (b=a+1; b5; b++)
if (queue[b].arrival_time = i && queue[a].burst_time queue[b].burst_time){
temp=queue[b];
queue[b]=queue[a];
queue[a]=temp;
} // 현재 도착한 프로세스중 실행시간이 짧을경우 실행되고 있는 프로세스와 교체
gantt[i]=queue[a].processno;
queue[a].burst_time--;
i++;
queue[a].turnaround = i-queue[a].arrival_time;
queue[a].waiting = queue[a].turnaround - queue[a].run;
}
a++;
}
func_print(queue,gantt);
printf(--------------turn_around time---------------\n);
printf(|%s %s %s %s %s \tave |\n, queue[0].name, queue[1].name,
queue[2].name, queue[3].name, queue[4].name);
printf(|%d %d %d %d %d %f|\n, queue[0].turnaround, queue[1].turnaround,
queue[2].turnaround, queue[3].turnaround, queue[4].turnaround, (float)queue[a].turnaround/5);
printf(-----------------------------------------------\n);
}
void rr_1(id rr_1(){//rr
int* gantt=(int*)malloc(sizeof(int)*total);
int b, a, i=0;
int next=0;
while (itotal){
a = next%5;
if ( queue[a].arrival_time = i){
for (b=0; b1 && queue[a].burst_time0; b++){
gantt[i]=queue[a].processno;
queue[a].burst_time--;
i++;
queue[a].turnaround = i-queue[a].arrival_time;
queue[a].waiting = queue[a].turnaround - queue[a].run;
}
}
next++;
}
func_print(queue,gantt);
printf(--------------turn_around time---------------\n);
printf(|%s %s %s %s %s \tave |\n, queue[0].name, queue[1].name,
queue[2].name, queue[3].name, queue[4].name);
printf(|%d %d %d %d %d %f|\n, queue[0].turnaround, queue[1].turnaround,
queue[2].turnaround, queue[3].turnaround, queue[4].turnaround, (float)queue[a].turnaround/5);
printf(-----------------------------------------------\n);
}
void rr_4(){//rr
int* gantt=(int*)malloc(sizeof(int)*total);
int b, a, i=0;
int next=0;
while (itotal){
a = next%5;
if ( queue[a].arrival_time = i){
for (b=0; b4 && queue[a].burst_time0; b++){
gantt[i]=queue[a].processno;
queue[a].burst_time--;
i++;
queue[a].turnaround = i-queue[a].arrival_time;
queue[a].waiting = queue[a].turnaround - queue[a].run;
}
}
next++;
}
func_print(queue,gantt);
printf(--------------turn_around time---------------\n);
printf(|%s %s %s %s %s \tave |\n, queue[0].name, queue[1].name,
queue[2].name, queue[3].name, queue[4].name);
printf(|%d %d %d %d %d %f|\n, queue[0].turnaround, queue[1].turnaround,
queue[2].turnaround, queue[3].turnaround, queue[4].turnaround, (float)queue[a].turnaround/5);
printf(-----------------------------------------------\n);
}
void func_swap(){//도착 시간 순서대로 정렬함 bubble sorting
int i, j;
for (i=0; i4; i++)
for (j=i+1; j5; j++)
if (queue[i].arrival_time queue[j].arrival_time){
temp = queue[i];
queue[i] = queue[j];
queue[j] = temp;
}
}
void main(){
int i;
printf(please input process status\n);
for (i=0; i5; i++){
proc[i].processno=i+1;
printf( %d 번째 프로세스 정보 입력 \n,proc[i].processno);
printf(process name : );scanf(%s, &proc[i].name);
printf(process arrival time : );scanf(%d, &proc[i].arrival_time);
printf(process burst time : );scanf(%d, &proc[i].burst_time);
proc[i].run = proc[i].burst_time;
}
printf(----------------process stats-----------------\n);
printf(|\tname\tarrival time\tburst time\t|\n);
for(i =0 ; i5 ; i++){
printf(|\t %s\t %d\t\t %d \t|\n, proc[i].name, proc[i].arrival_time, proc[i].burst_time);
}
printf(------------------------------------------------\n);
printf(\n 다음이 프로세스 넘버와 프로세스 이름입니다.\n);
printf( 간트차트는 프로세스 넘버가 출력됩니다.\n);
for (i=0; i5; i++)
printf( %d : %s ,proc[i].processno, proc[i].name);
for (i=0; i5; i++)
total+=proc[i].burst_time;
printf(\n************** fcfs scheduling **************\n);//fcfs 스케쥴링
for (i=0; i5; i++)
queue[i]=proc[i];
func_swap(queue);
fcfs(queue);
printf(\n********* non preemtive sjf scheduling********\n); //비선점 sjf 스케쥴링
for (i=0; i5; i++)
queue[i]=proc[i];
func_swap(queue);
np_sjf(queue);
printf(\n********** preemtive sjf scheduling **********\n); //선점 sjf 스케쥴링
for (i=0; i5; i++)
queue[i]=proc[i];
func_swap(queue);
p_sjf(queue);
printf(\n***** round-robin scheduling(q time = 1) *****\n); //rr 스케쥴링(q=1)
for (i=0; i5; i++)
queue[i]=proc[i];
func_swap(queue);
rr_1(queue);
printf(\n***** round-robin scheduling(q time = 4) *****\n); //rr 스케쥴링(q=4)
for (i=0; i5; i++)
queue[i]=proc[i];
func_swap(queue);
rr_4(queue);
system(pause);
}
-
라일락
scanf에서 %s를 사용할때 주소를 넘겨줘야 되는데,
배열의 이름은 그 자체로 주소가 됩니다.
따라서 &를 넣지 않아야 됩니다.
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2692210 | 정보 올림피아드 문제인데.. 풀이 과정이 궁금합니다.(재귀함수) (5) | 물티슈 | 2025-04-20 |
2692144 | C언어와 리눅스에 대한 질문입니다. | 싴흐한세여니 | 2025-04-20 |
2692114 | 컨텍스트 스위칭하는데 걸리는 시간 측정.. | YourWay | 2025-04-19 |
2692086 | 간접참조 연산자, 증감연산자 질문이용! (2) | 블랙캣 | 2025-04-19 |
2692056 | 주석좀 달아주세요. 몇개적엇는데 몇개만달아주세요. (2) | DevilsTears | 2025-04-19 |
2691978 | 진수 쉽게 이해하는법... (3) | 지지않는 | 2025-04-18 |
2691949 | getchar() 한 문자를 입력받는 함수 질문 | 채꽃 | 2025-04-18 |
2691919 | 배열 정렬 및 합치기 질문입니다. | 사과 | 2025-04-18 |
2691845 | c언어왕초보 질문이 있습니다........ | 루나 | 2025-04-17 |
2691815 | void add(int num); 함수... (4) | 살랑살랑 | 2025-04-17 |
2691756 | 명령 프롬프트 스크롤바가 없어요 | 두메꽃 | 2025-04-16 |
2691725 | 자료구조에 관련해서 질문이 있어 글을 올립니다. | 누리알찬 | 2025-04-16 |
2691697 | if 문에서 구조체 배열에 저장되있던 문자열 검사하는 법 ? (2) | 민트맛사탕 | 2025-04-16 |
2691678 | C언어 함수 질문이요~!!! | 연보라 | 2025-04-15 |
2691650 | 반복문 | 돋가이 | 2025-04-15 |
2691618 | 링크드리스트 개념 질문이예요 (3) | 맨마루 | 2025-04-15 |
2691592 | 동적할당 이용 배열선언 질문입니다.ㅠㅠ (3) | 허리달 | 2025-04-15 |
2691542 | /=의 용도를 알려주세요 ㅠㅠ! (2) | 아라 | 2025-04-14 |
2691510 | sizeof 연산자 질문입니다 (2) | 종달 | 2025-04-14 |
2691483 | 파일 오픈시 에러 질문드립니다. (2) | 호습다 | 2025-04-14 |