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

相关推荐
小-黯3 分钟前
Linux桌面入口文件.desktop文件内容格式
linux·运维·服务器
Serverless社区24 分钟前
探秘 AgentRun|基于 Serverless 的 AI Agent 沙箱工程化之路
运维·阿里云·云原生·serverless·函数计算
CheungChunChiu38 分钟前
Flutter 在嵌入式开发的策略与生态
linux·flutter·opengl
十五年专注C++开发1 小时前
CMake基础: 在release模式下生成调试信息的方法
linux·c++·windows·cmake·跨平台构建
不会代码的小猴1 小时前
Linux环境编程第三天笔记
linux·笔记
~光~~1 小时前
【嵌入式linux学习】04_Pinctrl 和 GPIO子系统
linux·rk3588·嵌入式linux
数智工坊1 小时前
【操作系统-IO调度】
java·服务器·数据库
475.351 小时前
linux-journal日志清理
linux·运维·服务器
weixin_438732101 小时前
ChromeDriver谷歌驱动下载
linux·chrome·selenium·自动化·mac·chrome devtools·chromedriver
小付爱coding2 小时前
跟着官网学LangChain【第01章:模型(Models)】
服务器·网络·langchain