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

相关推荐
嵌入小生0071 分钟前
进程(2)---相关函数接口、消亡、exec函数族 | 嵌入式(Linux)
linux·c语言·嵌入式·进程·函数接口·exec函数族·进程的消亡
程序员一点2 分钟前
第9章:软件包管理(DNF 与 RPM)
linux·运维·openeuler
@syh.6 分钟前
【linux】进程间通信
linux
wdfk_prog8 分钟前
EWMA、加权平均与一次低通滤波的对比与选型
linux·笔记·学习·游戏·ssh
FoldWinCard11 分钟前
Python 第三次作业
java·服务器·python
Mr.小海12 分钟前
Docker Compose 实战:多容器应用编排从入门到生产落地
运维·docker·容器
Ronin30525 分钟前
交换机路由管理模块
服务器·rabbitmq·动态规划·交换路由
longxibo26 分钟前
【Ubuntu datasophon1.2.1 二开之六:解决CLICKHOUSE安装问题】
大数据·linux·clickhouse·ubuntu
何中应27 分钟前
Jenkins如何注册为CentOS7的一个服务
linux·运维·jenkins·开发工具
三点水-here31 分钟前
03 - KV Cache与批处理:大模型推理的内存管理核心技术
服务器·人工智能·ai编程