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

相关推荐
Codefengfeng3 小时前
CTF工具篇
linux·运维·服务器
封奚泽优3 小时前
Docker常用命令(Windows 11)
运维·docker·容器
上海合宙LuatOS3 小时前
LuatOS核心库API——【i2c】I2C 操作
linux·运维·单片机·嵌入式硬件·物联网·计算机外设·硬件工程
Zach_yuan4 小时前
数据链路层核心技术解析:以太网与ARP协议
服务器·网络·网络协议
一文解千机5 小时前
wine 优化配置及显卡加速,完美运行Electron 编译的程序(新榜小豆芽、作家助手、小V猫等)
linux·ubuntu·electron·wine·wine优化配置·wine显卡加速·wine大型游戏
2401_858286116 小时前
OS53.【Linux】System V 共享内存(2)
linux·运维·服务器·共享内存
REDcker7 小时前
DNS技术详解
服务器·后端·计算机网络·互联网·dns·服务端
上海合宙LuatOS7 小时前
LuatOS核心库API——【io】 io操作(扩展)
java·服务器·前端·网络·单片机·嵌入式硬件·物联网
能源革命10 小时前
Ubuntu_24.04 安装OpenClaw教程
linux·ubuntu
志栋智能11 小时前
AI驱动的安全自动化机器人:从“告警疲劳”到“智能免疫”的防御革命
运维·人工智能·安全·机器人·自动化