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

相关推荐
黄筱筱筱筱筱筱筱14 小时前
RHCE---web服务器①
linux·运维·服务器
上海云盾安全满满14 小时前
服务器被攻击了,更换IP是否有用吗
服务器·网络·tcp/ip
AC赳赳老秦14 小时前
全链路自动化巡检:用 OpenClaw 实现服务器 - 应用 - 数据库全链路巡检,自动生成报告与整改建议
服务器·数据库·人工智能·深度学习·自动化·deepseek·openclaw
流浪00114 小时前
Linux基础篇(三)轻松拿捏入门级指令
linux·运维·服务器
weixin_5142531814 小时前
511-opencua-best_patch
服务器
Waay14 小时前
Linux Shell 知识点考评(三):awk文本分析(附答案)
linux·服务器·编辑器
爱喝水的鱼丶14 小时前
SAP-ABAP:ABAP Development Tools(ADT)安装配置学习分享教程(四篇连载) 第二篇:ADT客户端完整安装与初始配置教程
运维·开发语言·学习·sap·abap
其实防守也摸鱼14 小时前
Upload-labs:部署靶场及Pass-01实战解析
服务器·网络·安全·web安全·教程·文件上传·工具
xlq2232214 小时前
53.tcp socket
linux·服务器·开发语言·网络·网络协议·tcp/ip
wanhengidc15 小时前
云手机的兼容性与稳定性
大数据·运维·服务器·网络·人工智能·智能手机