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

相关推荐
0vvv08 分钟前
删除wsl环境下的Ubuntu系统
linux·运维·ubuntu
@土豆12 分钟前
Ubuntu 22.04 运行 Filebeat 7.11.2 崩溃问题分析及解决文档
linux·数据库·ubuntu
C++ 老炮儿的技术栈27 分钟前
GCC编译时无法向/tmp 目录写入临时汇编文件,因为设备空间不足,解决
linux·运维·开发语言·汇编·c++·git·qt
Agent产品评测局38 分钟前
企业数据处理自动化落地,抓取分析全流程实现方案 —— 2026企业级智能体选型与技术路径深度解析
运维·人工智能·ai·自动化
autumn200540 分钟前
Flutter 框架跨平台鸿蒙开发 - 历史人物对话
服务器·flutter·华为·harmonyos
爱莉希雅&&&1 小时前
linux中MySQL数据库备份恢复的四种方法(更新中)
linux·数据库·mysql·数据库备份·mysqldumper
我科绝伦(Huanhuan Zhou)1 小时前
分享一个网络智能运维系统
运维·网络
鬼先生_sir1 小时前
Spring Cloud 微服务监控实战:SkyWalking + Prometheus+Grafana 全栈解决方案
运维·spring cloud·grafana·prometheus·skywalking
信创DevOps先锋1 小时前
DevOps工具链选型新趋势:本土化适配与安全可控成企业核心诉求
运维·安全·devops
coppher1 小时前
Ubuntu 22.04 amd64 离线安装 Docker 完整教程
linux·docker