当前位置: 首页 > wzjs >正文

免费做自我介绍网站长春网站建设策划方案

免费做自我介绍网站,长春网站建设策划方案,阿里 wordpress插件,网站做访问追踪接上文 MIT XV6 - 1.1 Lab: Xv6 and Unix utilities - user/_sleep 是什么?做什么? pingpong 不务正业了那么久(然而并没有,虽然还在探索sleep,但是教材我已经看完了前三章了),让我们赶紧继续下去 在进行本实验之前请务…

接上文 MIT XV6 - 1.1 Lab: Xv6 and Unix utilities - user/_sleep 是什么?做什么?

pingpong

不务正业了那么久(然而并没有,虽然还在探索sleep,但是教材我已经看完了前三章了),让我们赶紧继续下去

在进行本实验之前请务必阅读完教材 Chapter 1,尤其是1.3对于PIPE的介绍,实验具体要求如下:

Write a user-level program that uses xv6 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 “pid: received ping”, where pid 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 “pid: received pong”, and exit. Your solution should be in the file user/pingpong.c.

Some hints:

  • Add the program to UPROGS in Makefile.
  • Use pipe to create a pipe.
  • Use fork to create a child.
  • Use read to read from a pipe, and write to write to a pipe.
  • Use getpid to find the process ID of the calling process.
  • User programs on xv6 have a limited set of library functions available to them. You can see the list in user/user.h; the source (other than for system calls) is in user/ulib.c, user/printf.c, and user/umalloc.c.

Run the program from the xv6 shell and it should produce the following output:

make qemu
...
init: start sh
$ pingpong
4: received ping
3: received pong
$

整体还是比较简单的,主要你得理解forkpipe的用法,以及一些要点,比如fork的返回值如果是子进程,那么会返回0;read会一直等到有足够的输入或者文件描述符被关闭啊。这些都在课本中有描述。

以下是实验源码(这注释,不用想,一定是AI写的…) GitHub已经同步

/** pingpong.c - A simple program demonstrating inter-process communication using pipes* * This program creates a parent-child process pair that communicate through a pipe.* The parent sends a "ping" message to the child, and the child responds with a "pong".* * Communication Flow:* 1. Parent creates a pipe* 2. Parent forks a child process* 3. Both processes have access to the pipe's read and write ends* 4. Parent writes "p" to pipe and waits for response* 5. Child reads "p" from pipe, prints "received ping", and writes "p" back* 6. Parent reads "p" from pipe and prints "received pong"* * Timing Diagram:* * Parent Process          Child Process*     |                       |*     |--pipe creation------>|*     |                       |*     |--fork()------------->|*     |                       |*     |--write("p")--------->|*     |                       |*     |<--read("p")----------|*     |                       |*     |<--write("p")---------|*     |                       |*     |--read("p")---------->|*     |                       |*     |--wait()------------->|*     |                       |*     |<--exit()-------------|*     |                       |*/#include "kernel/types.h"  // Include kernel type definitions
#include "user/user.h"     // Include user-level system call definitionsint main(int argc, char *argv[]) {int p[2];                // Array to store pipe file descriptorspipe(p);                 // Create a pipe, p[0] for reading, p[1] for writingchar buf[1];            // Buffer to store single character messagesif (fork() == 0) {      // Child processread(p[0], buf, 1);   // Read "p" from parentprintf("%d: received ping\n", getpid());  // Print child's PID and messagewrite(p[1], "p", 1);  // Send "p" back to parentclose(p[0]);          // Close read endclose(p[1]);          // Close write endexit(0);              // Exit child process} else {                // Parent processwrite(p[1], "p", 1);  // Send "p" to childread(p[0], buf, 1);   // Wait for child's responseprintf("%d: received pong\n", getpid());  // Print parent's PID and messagewait(0);              // Wait for child to exitclose(p[0]);          // Close read endclose(p[1]);          // Close write endexit(0);              // Exit parent process}return 0;
}

实验结果

make qemu
qemu-system-riscv64 -machine virt -bios none -kernel kernel/kernel -m 128M -smp 3 -nographic -global virtio-mmio.force-legacy=false -drive file=fs.img,if=none,format=raw,id=x0 -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0xv6 kernel is bootinghart 1 starting
hart 2 starting
init: starting sh
$ pingpong
4: received ping
3: received pong
$ QEMU: Terminated

ut结果

./grade-lab-util pingpong
make: `kernel/kernel' is up to date.
== Test pingpong == pingpong: OK (1.1s) 

我觉得得找时间看看他ut都做了什么。

http://www.dtcms.com/wzjs/453430.html

相关文章:

  • 厦门本地企业网站建设站长统计app下载免费
  • 那个装修公司的网站做的好怎么做好网络营销推广
  • 德阳网站建设 选哪家好百度网页版登录入口
  • 百度搜索公司网站展现图片手机如何制作一个网页链接
  • 邵阳做网站站长工具seo综合查询问题
  • 金牛区建设审批网站网络营销策划方案800字
  • 做网站好不好优化建议
  • html网页制作平台福州seo按天收费
  • 内蒙古旅游攻略周口搜索引擎优化
  • 买公司 网站建设百度代做seo排名
  • 做海鲜哪个b2b网站好点semantic
  • 加盟网站建设的内容网络商城应该如何推广
  • 济南网站建设的公司苏州网站建设书生
  • 国内用python做的网站浅谈一下网络营销的几个误区
  • 做电池的外贸网站自助快速建站
  • 网站简单布局图夫唯老师seo
  • 成都网站搜索排名优化公司网络营销内容
  • 网站建设案例展示软文经典案例
  • 做菠菜网站好赚吗杭州网站搜索排名
  • 单页网站模板修改吗深圳百度推广客服电话多少
  • 哈尔滨网站制作推广新媒体培训
  • 打开一个网站在建设中重庆放心seo整站优化
  • 建设项目信息类网站seo教程网站
  • 建程网是干嘛的推广优化工具
  • 建设宣传网站上的请示直接登录的网站
  • 电子商务网站建设定位设想宁德市人力资源和社会保障局
  • 网站开发中职教材网站内部seo
  • 品牌网站怎么做seo网站设计公司多少钱
  • 做网站 php java泉州百度搜索推广
  • 2019年做网站还有前景吗百度搜索资源平台token