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

相关推荐
hy____1238 分钟前
Linux_网络编程套接字
linux·运维·网络
若风的雨31 分钟前
【deepseek】 Linux 调度延时分析
linux
小夏卷编程35 分钟前
Ubuntu 20.04.4 宝塔 docker showdoc v3.2 更新到v3.7.3
运维·docker·容器
康康的AI博客39 分钟前
农业工业变革:如何通过DMXAPI中转提升自动化效率
运维·人工智能·自动化
2301_803554521 小时前
linux 以及 c++编程里对于进程,线程的操作
linux·运维·c++
LuDvei1 小时前
windows 中 vs code远程连接linux
linux·运维·服务器·windows
石小千2 小时前
Ubuntu24.04安装Mysql8
运维·mysql
生活爱好者!2 小时前
NAS帮我找回童年的快乐!部署 小游戏
运维·服务器·docker·容器·娱乐
GDAL2 小时前
MANIFEST.in简介
linux·服务器·前端·python
点点滴滴的记录2 小时前
Redis部署在Linux上性能高于Windows
linux·数据库·redis