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

cpp 复制代码
#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

重新编译:

make qemu

输入sleep可以看到命令

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

相关推荐
hy____1237 分钟前
Linux_进程间通信
linux·运维·服务器
银发控、15 分钟前
nginx静态资源
运维·nginx
郭涤生27 分钟前
C++的函数是否可以做到完全覆盖Linux和windows的跨平台
linux·c++·windows
老百姓懂点AI28 分钟前
[测试工程] 告别“玄学”评测:智能体来了(西南总部)基于AI agent指挥官的自动化Eval框架与AI调度官的回归测试
运维·人工智能·自动化
德育处主任Pro1 小时前
『NAS』用SSH的方式连上NAS
运维·ssh
Meaauf1 小时前
VMware安装中科方德服务器操作系统
运维·服务器·中科方德
南宫码农1 小时前
神马影视8.5版本如意伪静态+视频教程
linux·运维·centos
mftang1 小时前
现代互联网安全的基石: SSL/TLS技术介绍
服务器·网络·ssl
坐怀不乱杯魂1 小时前
Linux网络 - 网络层
linux·服务器·网络
j_xxx404_1 小时前
Linux:命令行参数与环境变量
linux·运维·服务器