MIB 6.1810实验Xv6 and Unix utilities(2)sleep

难度:easy

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.

实验目标:使用unix的sleep命令实现一个用户级别的sleep

cd xv6-labs-2023/

cd user

vim user.c

#include "kernel/types.h"
#include "kernel/stat.h"
#include "user/user.h"


int main(int argc, char *argv[])
{
  int n;
  if(argc!=2){
    fprintf(2,"please enter a number!\n");
    exit(1);
  }else{
    n = atoi(argv[1]);
    sleep(n);
    exit(0);
  }
}

写makefile

MIB 6.1810实验Xv6 and Unix utilities(2)sleep_第1张图片

重新编译:

make qemu

MIB 6.1810实验Xv6 and Unix utilities(2)sleep_第2张图片

输入sleep可以看到命令

使用./grade-lab-util sleep测试功能是否正常

MIB 6.1810实验Xv6 and Unix utilities(2)sleep_第3张图片

你可能感兴趣的:(linux,运维,服务器)