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

相关推荐
辻弋2019 分钟前
自动检测硬件生成驱动清单、实时监控FPS、120秒性能记录——30+项优化模块化开关,所有改动可精确复原
服务器·windows·游戏引擎·电脑·开源软件
CC城子23 分钟前
EtherNet/IP I/O 丢包排查(linux系统)
linux·单片机·tcp/ip·ethernetip
新时代牛马25 分钟前
Linux 信号处理完整篇:从sigaction、掩码到内核发送与可重入排障
linux·运维·信号处理
lpfasd12333 分钟前
Docker存储清理与防膨胀实践
运维·docker·容器
每天被AI救一次33 分钟前
WorkBuddy 会议自动化实战:从腾讯会议转写到待办系统的完整链路(附全套提示词)
运维·自动化·腾讯会议
程序员梅雨37 分钟前
Linux & Shell 实用干货
linux·运维·服务器·后端·面试·php
吴声子夜歌43 分钟前
编写Shell脚本——自顶向下设计
linux·运维·shell
M78佐菲1 小时前
HTML学习笔记
linux·笔记·学习·tcp/ip·html
XR1234567881 小时前
医院无线整网高密覆盖选型深度解析
运维·网络
新时代牛马1 小时前
嵌入式 Linux 蓝牙框架完整篇:从 HCI、L2CAP 到BlueZ 用户态
linux·运维·服务器