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

相关推荐
SKYDROID云卓小助手2 分钟前
无人设备遥控器之数字图传技术
运维·服务器·单片机·嵌入式硬件·fpga开发
努力努力再努力wz19 分钟前
【Linux进阶系列】:线程(上)
java·linux·运维·服务器·数据结构·c++·redis
java 乐山27 分钟前
蓝牙网关(备份)
linux·网络·算法
2301_8035545236 分钟前
面试后查缺补漏--cmake,makefiles,g++,gcc(自写精华版)
linux·运维·服务器
煤球王子41 分钟前
浅学任务调度
linux
102400241 小时前
ubuntu系统中 jupyter Kernel 频繁崩溃原因
linux·运维·服务器
深圳市恒讯科技1 小时前
使用站群服务器做SEO,如何避免被搜索引擎判定为“站群作弊”?
服务器·搜索引擎·php
LilySesy2 小时前
ABAP+如果在join的时候需要表1的字段某几位等于表2的字段的某几位,需要怎么做?
服务器·前端·数据库·sap·abap·alv
大唐荣华2 小时前
工业制造领域的ODM、OEM、EMS、JDM、CM、OBM都是啥
运维·产品运营·制造
z10_142 小时前
海外住宅ip怎么区分干净程度以及怎么选择海外住宅ip
服务器·网络·网络协议·tcp/ip