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

相关推荐
手握风云-10 分钟前
基于 Java 的网页聊天室(三)
服务器·前端·数据库
xlp666hub18 分钟前
深度剖析 Linux Input 子系统(3):从零写一个 Input 驱动,最详细手把手(附完整代码)
linux·面试
贺小涛21 分钟前
jenkins
运维·jenkins
开开心心_Every35 分钟前
限时免费加密、隐藏、锁定文件文件夹好工具
运维·服务器·人工智能·edge·pdf·逻辑回归·深度优先
RisunJan1 小时前
Linux命令-modprobe(自动处理可载入模块)
linux·运维
野犬寒鸦1 小时前
Redis复习记录day1
服务器·开发语言·数据库·redis·缓存
龙俊俊1 小时前
服务器模型部署与加载
服务器·人工智能·深度学习
何朴尧1 小时前
OpenClaw Linux 完整安装指南
linux
木木em哈哈2 小时前
记一次在线编辑器的探索
linux·服务器·网络