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

相关推荐
gaize12131 分钟前
服务器核心功能与应用场景全解析
服务器
qinyia2 分钟前
使用AI助手完成服务器系统备份迁移任务
linux·运维·服务器
知行合一。。。5 分钟前
Linux--10---crontab -e定时任务
java·linux·运维
德迅云安全—珍珍7 分钟前
如何去判断高防服务器的防御能力是否真实可靠?
运维·服务器
qq_273900238 分钟前
Apptainer 将 Ubuntu 本地 Conda 环境打包为 Singularity(SIF)镜像
linux·ubuntu·conda
mljy.11 分钟前
Linux《Socket编程UDP》
linux
云飞云共享云桌面12 分钟前
非标自动化设备工厂如何2台服务器带动20个SolidWorks设计
运维·服务器·人工智能·3d·自动化·制造
好好学习天天向上~~14 分钟前
2_Linux学习总结_基础指令
linux·学习
万博智云OneProCloud16 分钟前
从 CloudEndure 到 HyperBDR:制造业企业如何重构 AWS 云容灾体系
运维·重构·aws
历程里程碑17 分钟前
Linux 18 进程控制
linux·运维·服务器·开发语言·数据结构·c++·笔记