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

相关推荐
va学弟3 小时前
Java 网络通信编程(6):视频通话
java·服务器·网络·音视频
幸福指北4 小时前
我用 Tauri + Vue 3 + Rust 开发了这款跨平台网络连接查看工具PortView,性能炸裂!
运维·网络·监控
V__KING__5 小时前
systemd-remount-fs,fstab之间的渊源
linux·服务器·网络
酿情师5 小时前
Windows Subsystem for Linux (WSL, Ubuntu)安装教程(详细)
linux·windows·ubuntu
Titan20246 小时前
Linux环境变量个人笔记
linux·服务器·c++
zx_zx_1236 小时前
传输层协议tcp (2)
服务器·网络·tcp/ip
青柠代码录6 小时前
【Linux】路径区分:testdir、testdir/、testdir/*
linux·运维·服务器
7yewh6 小时前
jetson_yolo_deployment 02_linux_dev_skills
linux·python·嵌入式硬件·yolo·嵌入式
supersolon6 小时前
Windows下WSL(Ubuntu24.04)安装Nodejs
linux·ubuntu·node.js
进击切图仔7 小时前
跨系统时间戳同步问题解决总结
linux