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

相关推荐
想要入门的程序猿4 分钟前
VTK与PCL源码编译(Ubuntu 20.04.6)
linux·运维·服务器
EmbeddedCore18 分钟前
轻量级消息防重模块全解析:从原理到高性能优化
linux·运维·服务器·嵌入式硬件
回到原点的码农23 分钟前
Linux(CentOS)安装 MySQL
linux·mysql·centos
发光小北36 分钟前
SG-UHF110 系列远距离超高频 RFID 读写器如何应用?
服务器·网络
smileNicky1 小时前
Linux 系列从多节点的catalina 日志中统计设备调用频次
java·linux·服务器
北方的流星1 小时前
华三交换机DHCP服务配置
运维·网络
PyHaVolask2 小时前
图片处理基础
运维·服务器
qing222222222 小时前
Linux中修改mac地址(重启后依然生效)
linux·服务器·macos
桦02 小时前
【Linux复习】:进程概念
linux·运维·服务器
Par@ish2 小时前
【局域网协议】通过ISE实现radius认证,AD 的TCP 3268端口在其中发挥什么作用
服务器·网络·tcp/ip