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

相关推荐
Leinwin1 小时前
OpenClaw 多 Agent 协作框架的并发限制与企业化规避方案痛点直击
java·运维·数据库
2401_865382501 小时前
信息化项目运维与运营的区别
运维·运营·信息化项目·政务信息化
漠北的哈士奇1 小时前
VMware Workstation导入ova文件时出现闪退但是没有报错信息
运维·vmware·虚拟机·闪退·ova
如意.7591 小时前
【Linux开发工具实战】Git、GDB与CGDB从入门到精通
linux·运维·git
Thera7772 小时前
C++ 高性能时间轮定时器:从单例设计到 Linux timerfd 深度优化
linux·开发语言·c++
运维小欣2 小时前
智能体选型实战指南
运维·人工智能
yy55272 小时前
Nginx 性能优化与监控
运维·nginx·性能优化
爱吃土豆的马铃薯ㅤㅤㅤㅤㅤㅤㅤㅤㅤ3 小时前
Linux 查询某进程文件所在路径 命令
linux·运维·服务器
05大叔5 小时前
网络基础知识 域名,JSON格式,AI基础
运维·服务器·网络
安当加密5 小时前
无需改 PAM!轻量级 RADIUS + ASP身份认证系统 实现 Linux 登录双因子认证
linux·运维·服务器