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

相关推荐
北方的流星4 分钟前
华三路由器NAT配置
运维·网络·华三
wj30558537827 分钟前
Codex + Git 开发环境配置指南(WSL版)
linux·运维·git
星马梦缘1 小时前
如何切换window-ubuntu双系统【方案二】
linux·运维·ubuntu
2501_927283581 小时前
荣联汇智助力天津艺虹打造“软硬一体”智慧工厂,全流程自动化引领印刷包装行业数智变革
大数据·运维·数据仓库·人工智能·低代码·自动化
HXDGCL2 小时前
矩形环形导轨:自动化循环线的核心运动单元解析
运维·算法·自动化
丑八怪大丑2 小时前
Java网络编程
linux·服务器·网络
橙子也要努力变强3 小时前
信号捕捉底层机制-机理篇2
linux·服务器·c++
Jinkxs3 小时前
LoadBalancer- 主流负载均衡工具盘点:Nginx / Haproxy / Keepalived 基础介绍
运维·nginx·负载均衡
秋93 小时前
MySQL 8.0.46 全平台安装与配置详解(Windows/Linux/macOS)
linux·windows·mysql
小康小小涵4 小时前
基于ESP32S3实现无人机RID模块底层源码编译
linux·开发语言·python