【操作系统xv6】学习记录--实验1 Lab: Xv6 and Unix utilities--未完

发布时间:2024年01月03日

ref:https://pdos.csail.mit.edu/6.828/2020/xv6.html

在这里插入图片描述

实验:Lab: Xv6 and Unix utilities

环境搭建

实验环境搭建:https://blog.csdn.net/qq_45512097/article/details/126741793
搭建了1天,大家自求多福吧,哎。~搞环境真是折磨人
anyway,我搞好了:
在这里插入图片描述

开整实验

内容1:sleep

创建user/sleep.c
在Makefile中UPROGS下添加$U/_sleep
编写sleep.c
运行测试程序grade-lab-util并且指明要测试的函数。如 grade-lab-util sleep

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

void main(int argc, char *argv[])
{
  if(argc != 2){
    // 2 输出到哪里,输出内容,
    fprintf(2,"usage:sleep <time> \n");
    exit(1);
  }
  int sec = atoi(argv[1]);
  sleep(sec);  
  //printf("usage:sleep %d \n",sec);
  exit(0);
}

修改makefile,只需要改这一个地方

在这里插入图片描述

验证命令,要退出qume才能执行,否则会报错,
这种时候单项验证sleep

./grade-lab-util sleep
justin@DESKTOP-NIK28BI:~/vc6/xv6-labs-2020$ ./grade-lab-util sleep
fatal: detected dubious ownership in repository at '/mnt/d/code/vc6/xv6-labs-2020'
To add an exception for this directory, call:

        git config --global --add safe.directory /mnt/d/code/vc6/xv6-labs-2020
make: 'kernel/kernel' is up to date.
== Test sleep, no arguments == fatal: detected dubious ownership in repository at '/mnt/d/code/vc6/xv6-labs-2020'
To add an exception for this directory, call:

        git config --global --add safe.directory /mnt/d/code/vc6/xv6-labs-2020
sleep, no arguments: OK (1.3s)
== Test sleep, returns == sleep, returns: OK (0.8s)
== Test sleep, makes syscall == sleep, makes syscall: OK (1.0s)

内容2:pingpong

Write a program that uses UNIX system calls to ‘‘ping-pong’’ a byte between two processes over a pair of pipes, one for each direction.
The parent should send a byte to the child;
the child should print “: received ping”, where is its process ID, write the byte on the pipe to the parent(这里没有指定具体写什么内容,什么都可以,只是作为标志,且这个标志不需要也不要打印,否则会影响测评), and exit;
the parent should read the byte from the child, print “: received pong”, and exit.
Your solution should be in the file user/pingpong.c.

ref:https://xv6.dgs.zone/labs/requirements/lab1.html

文章来源:https://blog.csdn.net/weixin_40293999/article/details/135357420
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。