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

相关推荐
小虾爬滑丫爬11 分钟前
.net8发布Linux 版本程序,部署到Linux服务器上
linux·.net8·打包部署
l1l2x1x220 分钟前
DNS配置作业
运维·服务器
阿巴~阿巴~37 分钟前
UDP网络编程:从客户端封装到服务端绑定的深度实践
linux·网络·socket网络编程·sendto函数·ip绑定·udp网络编程
wanhengidc40 分钟前
云手机的核心价值
运维·游戏·智能手机·云计算
m0_6398171544 分钟前
基于springboot纺织品企业财务管理系统【带源码和文档】
java·服务器·前端
硬核子牙1 小时前
ext4文件系统与jbd2
linux
Lynnxiaowen1 小时前
今天我们开始学习ansible之playbook的简单运用
linux·运维·学习·云计算·ansible
誰能久伴不乏1 小时前
Linux 进程通信与同步机制:共享内存、内存映射、文件锁与信号量的深度解析
linux·服务器·c++
xulihang1 小时前
如何在Windows上使用SANE扫描文档
linux·前端·javascript
wanhengidc2 小时前
云手机的网络架构
服务器·网络·游戏·智能手机·架构·云计算