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

相关推荐
A_humble_scholar8 分钟前
Linux(十六)从页表到线程封装:深入理解 Linux 线程的共享、控制与封装
linux
海盗123414 分钟前
.NET编码规范03-C#命名规范大全
linux·服务器·.net
WZF-Sang16 分钟前
TCP和UDP协议
linux·服务器·网络·c++·学习·tcp/ip·udp
做个文艺程序员22 分钟前
Linux第11篇:存储管理——磁盘分区、LVM 与文件系统
linux·运维·服务器
懂AI的老郑22 分钟前
工业检测场景下智能体的应用:从自动化到智能化
运维·自动化
AI视觉网奇29 分钟前
BambuStudio 自定义加载页面
服务器·前端·javascript
天空'之城32 分钟前
Linux 系统编程 14:Reactor 反应堆模式
linux·开发语言·网络编程·reactor 反应堆模式
法号:行颠42 分钟前
《Linux内核源码全景解读:从上电到用户态》之 目录
linux
运维大师44 分钟前
【云原生与DevOps】08-多云容灾架构设计:跨Region自动切换实践
运维·云原生·devops
一氧化二氢.h1 小时前
AI大模型批量自动化评测脚本
运维·人工智能·自动化