운영체제/xv6
xv6 Lab: Utilities (1) sleep
JaeminRyu
2022. 8. 31. 16:15
728x90
이 문제는 MIT의 xv6 수업에 출처가 있습니다.
출처 : Lab: Xv6 and Unix utilities (mit.edu)
Implement the UNIX program sleep for xv6; your sleep should pause for a user-specified number of ticks.
A tick is a notion of time defined by the xv6 kernel, namely the time between two interrupts from the timer chip.
이미 구현되어 있는 sleep()함수를 이용하여 sleep 명령어를 구현하는 문제
Solution
#include "kernel/types.h"
#include "kernel/stat.h"
#include "user/user.h"
int main(int argc,char *argv[]){
int time;
if(argc <=1) //함수의 인자가 2개 이하라면
printf("Usage: sleep <time>");
exit(1);
}
time = atoi(argv[1]); //입력한 time이 str타입이므로 정수형으로 변환
sleep(time);
exit(0);
}
728x90