栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

MIT6s081 lab1 sleep的实现

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

MIT6s081 lab1 sleep的实现

参考材料
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 errorn”);
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 user program, and user/usys.S for the assembler code that jumps from user code into the kernel for sleep.
调用sleep()传入时间参数就好了。他让看sleep的具体实现和汇编代码。

Make sure main calls exit() in order to exit your program.
调用exit(0)正常退出就可以了。

完整代码:

#include "kernel/types.h"
#include "user/user.h"


int main(int argc, char* argv[]){ 
   if(argc != 2){
    printf("exec errorn");
    exit(1);
  }
    int num=atoi(argv[1]);
    sleep(num);
    exit(0);
}`


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/733543.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号