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

相关推荐
云飞云共享云桌面6 小时前
传统工作站 vs 云飞云共享云桌面:制造业设计云桌面选型深度对比
运维·服务器·前端·网络·3d·架构·制造
JAVA面经实录9178 小时前
操作系统面试题
java·服务器·数据库·计算机网络·面试
小刘|8 小时前
Spring AI Alibaba 集成和风天气 API 实战
java·服务器·前端
暮云星影9 小时前
全志linux开发屏幕适配(一)屏幕参数设置说明
linux·arm开发
Maynor9969 小时前
我用 Codex 给自己的网站上线了一个智能体客服:从 Dify 到服务器部署,全程实战复盘
运维·服务器
聚名网10 小时前
域名net,com,cn有区别吗?有哪些不同呢?
服务器·开发语言·php
java_cj10 小时前
深入kubectl create源码:从YAML到Pod的完整链路拆解
运维·云原生·容器·kubernetes
小小小花儿10 小时前
SSH密钥配置(免密连接远程服务器)
服务器·ssh
swordbob11 小时前
NIO 的 Channel 里有多个 BIO 吗?
linux·网络·nio
深圳恒讯11 小时前
越南服务器BGP多线和单线有什么区别?
运维·服务器