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

相关推荐
idolao37 分钟前
CentOS 7 安装 nginx-1.3.15.tar.gz 详细步骤(从源码编译到启动配置)
linux·运维·数据库
@encryption38 分钟前
TCP,IP
服务器·网络·tcp/ip
yaoxin5211231 小时前
358. Java IO API - 使用 relativize() 创建路径之间的相对关系
java·linux·python
CDN3601 小时前
低成本游戏防护:360 SDK 游戏盾使用总结
运维·游戏·网络安全
万象.1 小时前
docker镜像仓库
运维·docker·容器
rosmis1 小时前
自动化文献检索与下载工作流:基于 Playwright 的 RPA 实践方案
运维·自动化·rpa
亚林瓜子1 小时前
linux账号强制密码过期导致私钥文件登录异常问题——(current) UNIX password:
linux·运维·服务器·ssh·aws·ec2·chage
姚不倒1 小时前
Docker 核心原理与运维实战:从入门到生产级理解
运维·docker·架构
Code_LT1 小时前
【AIGC】Claude Code Rules配置
linux·ubuntu·aigc
LXY_BUAA1 小时前
《嵌入式操作系统》_驱动框架_20260318
linux·运维·服务器