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 分钟前
Linux基本命令篇 —— alias命令
linux·服务器·bash
好名字更能让你们记住我1 小时前
Linux多线程(十二)之【生产者消费者模型】
linux·运维·服务器·jvm·windows·centos
门思科技1 小时前
设计可靠 LoRaWAN 设备时需要考虑的关键能力
运维·服务器·网络·嵌入式硬件·物联网
小锋学长生活大爆炸1 小时前
【知识】RPC和gRPC
服务器·网络协议·rpc
学习编程的gas1 小时前
Linux开发工具——gcc/g++
linux·运维·服务器
大大。1 小时前
van-tabbar-item选中active数据变了,图标没变
java·服务器·前端
嵌入式成长家1 小时前
ubuntu rules 使用规则
linux·ubuntu·rules 使用规则
_可乐无糖1 小时前
AWS WebRTC: 判断viewer端拉流是否稳定的算法
linux·服务器·webrtc·aws
数据智能老司机2 小时前
Linux内核编程——Linux设备模型
linux·架构·操作系统
老友@2 小时前
服务器异常宕机或重启导致 RabbitMQ 启动失败问题分析与解决方案
服务器·rabbitmq·启动失败·宕机