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

相关推荐
handsomestWei5 分钟前
Docker引擎API接入配置
运维·http·docker·容器·api
si莉亚9 分钟前
ROS2安装EVO工具包
linux·开发语言·c++·开源
Tingjct10 分钟前
Linux常用指令
linux·运维·服务器
广州灵眸科技有限公司30 分钟前
为RK3588注入澎湃算力:RK1820 AI加速卡完整适配与评测指南
linux·网络·人工智能·物联网·算法
daad77734 分钟前
wifi_note
运维·服务器·数据库
IT界的老黄牛36 分钟前
Linux 压缩命令实战:tar、gzip、bzip2、xz、zstd 怎么选?一篇讲清楚
linux·运维·服务器
IT WorryFree1 小时前
飞塔防火墙与第三方设备进行IPSEC故障诊断期间,用户可能会观察到以下错误:
linux·服务器·网络
12345,catch a tiger1 小时前
虚拟机ubuntu安装Vmware Tools
linux·运维·ubuntu
✎ ﹏梦醒͜ღ҉繁华落℘1 小时前
Makefile -GNU和MakeFile关系(二)
服务器·gnu
凉、介1 小时前
别再把 PCIe 的 inbound/outbound、iATU 和 eDMA 混为一谈
linux·笔记·学习·嵌入式·pcie