MIT6s081 lab1 sleep的实现

这篇博客介绍了如何实现MIT6.828实验中的sleep命令。作者建议参考其他用户程序,如echo.c、grep.c和rm.c,了解如何获取命令行参数。当用户忘记传递参数时,程序应打印错误信息并使用exit(1)异常退出。通过atoi函数将命令行参数字符串转换为整数,并调用sleep系统调用。博主提醒读者查看sysproc.c中的内核实现、user.h中的C定义以及usys.S中的汇编代码。最后,确保main函数在程序结束时调用exit(0)正常退出。
摘要由CSDN通过智能技术生成
  • 参考材料
    https://pdos.csail.mit.edu/6.828/2020/labs/util.html

  • Look at some of the other programs in user/ (e.g., user/echo.c, user/grep.c, and user/rm.c) to see how you can obtain the command-line arguments passed to a program.
    grep.c echo.c rm.c int main(){} 括号里的参数是int argc, char* argv[]。argc表示参数个数,argv表示内容。

  • If the user forgets to pass an argument, sleep should print an error message.
    要写一个提示错误的语句。printf(“exec error\n”);
    exit(1)括号里是1表示出现异常。

  • The command-line argument is passed as a string; you can convert it to an integer using atoi (see user/ulib.c).
    如果传入的数字是10,存储到argv[1]里,调用atoi()把字符类型转换成整型。

  • Use the system call sleep.
    See kernel/sysproc.c for the xv6 kernel code that implements the sleep system call (look for sys_sleep), user/user.h for the C definition of sleep callable from a u

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值