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

相关推荐
木卫二号Coding8 分钟前
CentOS 系统 Shell 脚本开机自启动方法详解
linux
l1t18 分钟前
DeepSeek总结的RegreSQL 2.0测试通过了。计划却没通过。
linux·数据库·postgresql
蝶恋舞者33 分钟前
怎样设置软件开机自启动(用的最多,最简单)
linux·运维·服务器
Dawn-bit39 分钟前
Linux打包压缩与用户权限管理详解
linux·服务器·数据库
ls_elect40 分钟前
PostgreSQL 18.4 SCRAM-SHA-256 认证故障诊断及修复办法
linux·数据库·postgresql
段一凡-华北理工大学1 小时前
AI Agent 从入门到封神:24 讲打造你的超级智能体~系列文章23:从Demo到上线:Agent应用的架构设计、性能优化与成本控制实战
运维·网络·人工智能·性能优化·高炉炼铁·工业智能体
L1624761 小时前
Zabbix 7.0 LTS 完整部署与运维手册(AlmaLinux 9 + MySQL 8.0 + Nginx)
运维·mysql·zabbix
happymade1 小时前
MSRM3 区域层级嵌套功能深度解析与实操教程
运维·网络拓扑·网络管理·网络运维·msrm3
陈同学xxx2 小时前
Hermes Agent 接入飞书,在手机上随时聊天
linux·python·飞书
网络小白不怕黑2 小时前
14.VSFTP服务相关配置
linux·运维·服务器