본문 바로가기
운영체제/xv6

xv6 Lab: Utilities (1) sleep

by JaeminRyu 2022. 8. 31.
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);
}

 

'운영체제 > xv6' 카테고리의 다른 글

xv6 Lab: Utilities (5) xargs  (0) 2022.09.03
xv6 Lab: Utilities (4) find  (0) 2022.09.02
xv6 Lab: Utilities (3) primes  (0) 2022.09.01
xv6 Lab: Utilities (2) pingpong  (0) 2022.08.31