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

相关推荐
Lsir10110_4 分钟前
【Linux】线程初步——线程概念以及接口认识
linux·运维·服务器
cuber膜拜23 分钟前
Tenacity 原理与基本使用
服务器·网络·python·装饰器模式·tenacity
cuber膜拜24 分钟前
PyBreaker 原理与基本使用
服务器·网络·python·pybreaker
Albert Edison32 分钟前
【Python】文件
android·服务器·python
未来之窗软件服务34 分钟前
服务器运维(三十三)日志分析ssh日志工具—东方仙盟
运维·服务器·ssh·仙盟创梦ide·东方仙盟
梦雨羊40 分钟前
搭建服务器进行测试
linux·运维·服务器
青主创享阁1 小时前
玄晶引擎2.7.6技术拆解+实战略落地:春节前自动化运营能力升级全解析
运维·自动化
FLS1681 小时前
华为S5700交换机SSH/Telnet/Web登录完整配置流程(V200R005C00SPC500)
运维·网络·华为·ssh
哼?~1 小时前
磁盘与文件系统
linux
Bigbig.1 小时前
Linux 挖矿病毒深度排查与修复实录
linux·安全