MIT 6.S081lab记录

lab utilities

##配置XV6环境

ubuntu24.04换源

从 Ubuntu 24.04 开始,Ubuntu 的软件源配置文件变更为 DEB822 格式,路径为 /etc/apt/sources.list.d/ubuntu.sources

备份原文件后添加国内源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 阿里云
Types: deb
URIs: http://mirrors.aliyun.com/ubuntu/
Suites: noble noble-updates noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

# 清华源 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
Types: deb
URIs: http://mirrors.tuna.tsinghua.edu.cn/ubuntu/
Suites: noble noble-updates noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

#中科大源
Types: deb
URIs: http://mirrors.ustc.edu.cn/ubuntu/
Suites: noble noble-updates noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg







更新源列表

1
2
3
sudo apt-get update
sudo apt-get upgrade

安装QEMU和RISC-V交叉编译工具

1
sudo apt-get install git build-essential gdb-multiarch qemu-system-misc gcc-riscv64-linux-gnu binutils-riscv64-linux-gnu 

拉取xv6,编译及运行

1
2
3
4
git clone https://github.com/mit-pdos/xv6-riscv.git
cd xv6-riscv
sudo make
make qemu//使用qemu运行

系统调用的使用

管道与dup联合编程:wc命令的管道通信与输入重定向-CSDN博客

素数筛

利用多进程和管道,对素数进行筛选;
埃拉托色尼筛:该算法首先假设范围内的所有数字 2 至 n 是素数。它遍历列表从 2 至 √n,并且对于每个遇到的数字,它都会删除列表中的所有倍数。对于所有未删除的数字,此过程将继续。因此,我们得到了范围内所有素数的最终列表 2 至 n.