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

相关推荐
minji...6 小时前
Linux 线程同步与互斥(四) POSIX信号量,基于环形队列的生产者消费者模型
linux·运维·服务器·c语言·开发语言·c++
SPC的存折6 小时前
8、Docker镜像瘦身
运维·docker·容器
抠脚学代码6 小时前
Linux开发-->驱动开发-->字符设备驱动框架(2)
linux·运维·驱动开发
何中应6 小时前
Promehteus如何指定数据路径
运维·prometheus·监控
热爱Liunx的丘丘人6 小时前
Ansible的Playbook案例一
linux·运维·服务器·ansible
浪客川7 小时前
【百例RUST - 014】Trait
服务器·网络·rust
Minla7 小时前
kubectl常用命令别名设置(linux|windows)
linux·运维·服务器·k8s
程序猿编码7 小时前
给Linux程序穿“隐身衣”——ELF运行时加密器全解析(C/C++代码实现)
linux·c语言·c++·网络安全·elf·内存安全
学习论之费曼学习法7 小时前
用 Agent 自动化数据处理:从 2 小时到 15 分钟的效率革命
运维·自动化
cyber_两只龙宝7 小时前
【Oracle】Oracle之SQL的聚合函数和分组
linux·运维·数据库·sql·云原生·oracle