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

相关推荐
千百元几秒前
zookeeper启不来了
linux·zookeeper·debian
志栋智能41 分钟前
超自动化安全:构建智能安全运营的核心引擎
大数据·运维·服务器·数据库·安全·自动化·产品运营
AnalogElectronic2 小时前
linux 测试网络和端口是否连通的命令详解
linux·网络·php
Edward111111112 小时前
4月28日防火墙问题
linux·运维·服务器
想学后端的前端工程师3 小时前
【补充内外网突然不通的情况】
运维·服务器
面汤放盐3 小时前
何时使用以及何时不应使用微服务:没有银弹
java·运维·云计算
子琦啊3 小时前
【算法复习】字符串 | 两个底层直觉,吃透高频题
linux·运维·算法
跨境数据猎手4 小时前
跨境独立站系统技术拆解(附带源码)
服务器·前端·php
AOwhisky4 小时前
Kubernetes 学习笔记:集群管理、命名空间与 Pod 基础
linux·运维·笔记·学习·云原生·kubernetes