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

相关推荐
lwx9148522 小时前
Linux-特殊权限SUID,SGID,SBIT
linux·运维·服务器
皮卡狮3 小时前
Linux权限的概念
linux
炘爚3 小时前
深入解析printf缓冲区与fork进程复制机制
linux·运维·算法
workflower3 小时前
注塑机行业目前自动化现状分析
运维·人工智能·语言模型·自动化·集成测试·软件工程·软件需求
小义_4 小时前
随笔 3(Linux)
linux·运维·服务器·云原生·红帽
#六脉神剑4 小时前
MySQL参数调优:十个关键参数助力数据库性能数倍提升
运维·mysql
cccccc语言我来了4 小时前
Linux(10)进程概念
linux·运维·服务器
伐尘5 小时前
【linux】查看空间(内存、磁盘、文件目录、分区)的几个命令
linux·运维·网络
Deitymoon5 小时前
linux——PV操作
linux
倔强的胖蚂蚁5 小时前
x2openEuler 辅助机完整部署教程
运维·云原生