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

相关推荐
左手厨刀右手茼蒿1 小时前
数据仓库的架构演进:从MySQL到ClickHouse到数据湖的工程化实践
linux·嵌入式·系统内核
左手厨刀右手茼蒿1 小时前
创业团队技术选型:别用大厂架构解决小团队问题
linux·嵌入式·系统内核
明志数科2 小时前
宇树科技IPO背后的产业逻辑:人形机器人从“讲故事“到“交数据“
运维·服务器·数据库
外滩运维专家2 小时前
验证码接口上线三天就被刷了,我后来加的几道防线
运维
Data_Journal2 小时前
什么是 CAPTCHA,它是如何工作的?
java·大数据·服务器·前端·数据库
跨境小彭2 小时前
店群运营实操复盘:批量活动申报自动化优化方案
大数据·运维·人工智能·自动化·跨境电商·temu·temu电商运营
Jlzn88882 小时前
2026年锂电CCS组装线:车规储能双场景兼容自动化方案的技术架构与实践
运维·架构·自动化
bosins2 小时前
将 Hyper-V 上的 Ubuntu 虚拟机内容迁移到 WSL (Windows Subsystem for Linux) 中
linux·windows·ubuntu
AC赳赳老秦3 小时前
语义采集进阶实战:利用 OpenClaw AI 语义识别自动提取网页核心信息,无需手动编写选择器
java·运维·服务器·python·信息可视化·deepseek·openclaw
我星期八休息3 小时前
扩展—DNS与ICMP
linux·服务器·网络