Implement a user-level sleep program for xv6, along the lines of the UNIX sleep command.
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. Your solution should be in the file user/sleep.c.
// user/sleep.c
#include "kernel/types.h"
#include "kernel/stat.h"
#include "user/user.h"
int main(int argc, char* argv[]){
if(argv[1] == 0){
fprintf(2, "Usage: sleep [Seconds]\n");
exit(1);
}
for(uint i = 0; argv[1][i] != 0; i++){
if(!(argv[1][i] >= '0' && argv[1][i] <= '9')){
fprintf(2, "Usage: sleep [Seconds_in_Integer]\n");
exit(1);
}
}
uint Seconds = atoi(argv[1]);
sleep(Seconds);
exit(0);
}
'xv6:2024 > Chapter 1' 카테고리의 다른 글
Exercise 1-5. xargs (1) | 2024.11.19 |
---|---|
Exercise 1-4. find (0) | 2024.11.18 |
Exercise 1-3. primes (0) | 2024.11.16 |
Exercise 1-2. pingpong (0) | 2024.11.16 |
xv6's every system call && read() from the pipe (1) | 2024.11.16 |