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

相关推荐
Deitymoon10 分钟前
linux——TCPIP协议原理
linux·网络
独小乐19 分钟前
018.使用I2C总线EEPROM|千篇笔记实现嵌入式全栈/裸机篇
linux·笔记·单片机·嵌入式硬件·arm·信息与通信
SPC的存折29 分钟前
2、Docker命令与镜像、容器管理
linux·运维·服务器·docker·容器·eureka
D4c-lovetrain33 分钟前
Linux个人心得26 (redis主从复制全流程,详细版)
linux·运维·服务器
晴天¥42 分钟前
达梦数据库共享存储集群搭建(DSC双节点+Openfiler-IP SAN存储)
linux·数据库·达梦数据库
吃着火锅x唱着歌1 小时前
LeetCode 150.逆波兰表达式求值
linux·算法·leetcode
Bert.Cai1 小时前
Linux whoami命令详解
linux·运维
x***r1511 小时前
驱动精灵离线版使用指南:免联网快速安装驱动(万能网卡版)
linux·运维·服务器
嵌入式×边缘AI:打怪升级日志1 小时前
Linux GPIO子系统与中断驱动开发:从入门到实战(完整版)
linux·运维·驱动开发
147API1 小时前
多模型路由规则设计实战:第一版系统别做成黑盒
服务器·前端·javascript