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

相关推荐
林开落L31 分钟前
解决云服务器内存不足:2 分钟搞定 Ubuntu swap 交换区配置(新手友好版)
运维·服务器·ubuntu·swap交换区
初恋叫萱萱34 分钟前
深入解析 Rust + LLM 开发:手把手教你写一个 AI 运维助手
运维·人工智能·rust
加农炮手Jinx41 分钟前
Flutter for OpenHarmony: Flutter 三方库 icon_font_generator 自动化将 SVG 图标集转化为字体文件(鸿蒙矢量资源全自动管理)
运维·flutter·华为·自动化·harmonyos·devops
我真的想 啸41 分钟前
在 Ubuntu 24.04 系统上安装并使用 Codex CLI
linux·ubuntu·arcgis
雨大王5124 小时前
汽车生产智能计划助手如何提升排产效率并降低库存积压?
大数据·运维
嵌入小生0074 小时前
线程(2)/ 线程属性 /相关函数接口--- 嵌入式(Linux)
linux·嵌入式·线程·软件编程·僵尸线程·马年开工第一学·线程属性
以太浮标4 小时前
华为eNSP综合实验之- 3a认证配置案例及解析(AAA认证)
运维·tcp/ip·网络安全·华为·信息与通信
No8g攻城狮5 小时前
【Linux】Linux nano 编辑器全攻略:从入门到精通
linux·运维·编辑器·nano
zl_dfq5 小时前
Linux 之 【网络套接字编程】(固定宽度整数类型、socket常见API、netstat)
linux·网络
2301_805962936 小时前
arduino IDE如何设置代理
运维·服务器