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

相关推荐
YumiProxy6 小时前
动态IP冲突排查实战:从ARP检测到DHCP地址池的完整链路
服务器·网络·网络协议·tcp/ip·ip
ai小陈6 小时前
GPU服务器租用容器实战:Docker数据卷持久化与安全重建
服务器·人工智能·安全·docker·ai·gpu算力
智能运维指南6 小时前
从分散运维到统一运维:2026 统一运维管理体系建设路径与选型要点
运维·一体化运维·智能运维·嘉为蓝鲸
ITyunwei09876 小时前
ITIL 5 落地前,先补齐工单数据底座的 4 步
运维·企业微信
M78佐菲7 小时前
ARM学习笔记(12)
linux·arm开发·笔记·嵌入式硬件·学习
ai小陈7 小时前
深度学习CUDA OOM排查:显存占用与碎片问题实战
服务器·人工智能·python·深度学习·ai·gpu算力
GPU实战笔记7 小时前
项目实例端口异常:修复端口与重置端口的决策边界
服务器·端口·网络连接·故障排查·云服务器
可涵不会debug7 小时前
C++ std::bind 实战教程:线程池、回调场景全覆盖
linux·开发语言·c++
实点科技7 小时前
远程IO模块的柜外安装:装在什么位置、防尘罩怎么选配
运维·服务器·网络