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

相关推荐
SunnyRivers9 分钟前
深入理解Linux后台命令
linux·后台运行·重定向·nohub
刘叨叨趣味运维12 分钟前
快速掌握Linux启动过程:像看接力赛一样简单
linux
Q168496451522 分钟前
红帽Linux-进程、ssh、网络、软件包、文件系统
linux·运维·网络
ℳ₯㎕ddzོꦿ࿐30 分钟前
Docker 环境下 Paperless-ngx 中文增强版部署实战
运维·docker·容器
wdfk_prog43 分钟前
[Linux]学习笔记系列 -- [drivers][base]cpu
linux·笔记·学习
zhaoyun92744 分钟前
ubuntu linux 安装net8 net9 net 10方法
linux·ubuntu
大母猴啃编程1 小时前
线程同步与互斥
linux
zwtahql2 小时前
ubuntu远程ssh连接
linux·ubuntu·ssh
南烟斋..2 小时前
嵌入式系统(51单片机)核心外设详解:UART通信与DS18B20温度采集
linux·运维·网络