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

相关推荐
Mortalbreeze2 小时前
深入理解 Linux IO 模型(一):阻塞 IO、非阻塞 IO 与信号驱动 IO
linux·运维·服务器
带鱼吃猫3 小时前
LangChain:提示词模板与少样本提示功能
服务器·数据库·langchain
一直C3 小时前
Linux应用软件编程|TCP协议与Socket全套编程(三次握手、四次挥手、报文头部、核心机制)
linux·网络协议·tcp/ip·wireshark·vim·visual studio
D_codingXuChu3 小时前
2026年物联网应用开发服务商选型指南|从设备接入、数据处理、业务联动到长期运维,拆解项目落地中的工程实践与可验证方法,帮助企业判断供应商真实交付能力
运维·物联网·开发经验·企业服务
2301_780789663 小时前
CDN提供商常用的DDoS缓解技术与策略
linux·运维·服务器·人工智能·架构
进击的雷神3 小时前
网站 SEO 功能怎么测:从手工检查到自动化脚本的实战思路
运维·爬虫·自动化·官网seo·收录
Kismet_nvi3 小时前
Python运维自动化核心模块
运维·python·自动化
夏炳辉.3 小时前
Rocky Linux 8 从零安装 psql(PostgreSQL 客户端)
linux·运维·postgresql
姚不倒3 小时前
Nginx 核心架构:Master-Worker、epoll、热重载深度解析
运维·nginx·架构
β添砖java3 小时前
学习笔记:实战章节:在Linux上部署各类软件
linux·笔记·学习