实验一
6s081这个课搁置一段时间了,最近才把实验2做完,特意开个博客记录,当着一个监督吧。
实验一没什么前置知识,配置好环境,会c语言直接就可以做。
Lab util: Unix utilities
test_pipe.c
#include "kernel/stat.h"
#include "user/user.h"
int main(int avgc, char* argv[]) {
char buf[1];
char abyte[] = "abc";
int p[2];
pipe(p);
int pid = fork();
if (pid == 0) {
// child
printf("child's pid is %d \n", getpid());
printf("waiting parent to write\n");
// read block until data have been written
// or all write end have been closed
close(p[1]); // 必须同时close掉parent和child的p[1],read才不会阻塞
read(p[0], buf,1