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测试功能是否正常

相关推荐
CIO_Alliance8 分钟前
AI+iPaaS解决方案:跨系统业务流程自动化助力企业AI化转型
运维·人工智能·自动化
学无止境_永不停歇33 分钟前
9. 缓冲区
linux·服务器·c++
dok1237 分钟前
Johannes 《Linux内核模块与设备驱动开发:编写Linux驱动程序》(4) devicefile 设备号相关
linux·运维·服务器
毛驴赶鹿1 小时前
低配置服务器怎么搭建监控?Komari Docker部署与公网访问完整教程
运维·服务器·docker
Fu2067211 小时前
结课项目考试
linux·运维·服务器
MXsoft6181 小时前
## 信创运维2.0的“最后一公里”——国产设备“能用但不好用”,问题出在哪?
运维
Albert·Lin1 小时前
LVS相关知识点总结-一
linux·服务器·lvs
公众号:fuwuqiBMC3 小时前
(转自“服务器BMC”)服务器BMC芯片——AST1840
运维·服务器·fpga开发
测试专家3 小时前
PCI-1553B板卡在 Windows Server 2016 服务器安装流程详解
服务器·windows·单片机
忘路之远近i3 小时前
受够阿里云自带终端后,我用 Cursor + grill-me 做了个运维面板
服务器·开发语言·人工智能·python·阿里云·云计算