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

相关推荐
科研前沿1 小时前
镜像视界 CameraGraph™+多智能体:构建自感知自决策的全域空间认知网络技术方案
大数据·运维·人工智能·数码相机·计算机视觉
暴力求解1 小时前
Linux---线程基础
linux·运维·服务器
JAVA面经实录9171 小时前
计算机基础(完整版·超详细可背诵)
java·linux·数据结构·算法
晚风_END1 小时前
Linux|操作系统|最新版openzfs编译记录
linux·运维·服务器·数据库·spring·中间件·个人开发
GanGanGanGan_1 小时前
Rocky Linux 9 + XFCE 编译安装 fcitx5 + Rime 教程
linux·centos
代码中介商1 小时前
Linux TCP 网络编程完全指南:从三次握手到高并发服务器
服务器·网络·tcp/ip
咖喱o2 小时前
QinQ/VLAN Stacking
linux·运维·服务器·网络
xiaoye-duck2 小时前
《Linux系统编程》Linux指令 (二):从零开始理解Linux基础指令
linux
月白风清江有声2 小时前
安装mingw 版 cmake
linux
sduwcgg3 小时前
IQ-Learn 在 RTX 3090 服务器上的环境配置与踩坑记录
运维·服务器