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

相关推荐
Dovis(誓平步青云)几秒前
《剖析 Linux 文件系统:架构、原理与实战操作指南》
linux·运维·服务器
千百元几秒前
centos查线程数
linux·运维·centos
---学无止境---2 分钟前
Linux中基数树标签相关操作函数的实现
linux
San3026 分钟前
使用 n8n 构建自动化科技新闻速览工作流:从 RSS 到 AI 摘要生成与文件存储
运维·人工智能·机器学习
or77iu_N35 分钟前
Linux 解压安装(安装tomcat)
linux·运维·tomcat
赋创小助手1 小时前
实测对比 32GB RTX 5090 与 48GB RTX 4090,多场景高并发测试,全面解析 AI 服务器整机性能与显存差异。
运维·服务器·人工智能·科技·深度学习·神经网络·自然语言处理
晨曦之旅1 小时前
白嫖服务器
运维·服务器
TG_yunshuguoji1 小时前
阿里云渠道商:如何建立阿里云的权限模型?
运维·服务器·阿里云·云计算
海棠蚀omo1 小时前
Linux操作系统-父进程的等待:一个关于回收与终结的故事
linux·操作系统
乌萨奇也要立志学C++1 小时前
【Linux】Ext系列文件系统 从磁盘结构到文件存储的原理剖析
android·linux·缓存·1024程序员节