操作系统实验
Lab0
目录
1.思考题解答
2.难点分析
3.思考体会
思考题解答
Thinking 0.1
以下为Thinking 0.1要求得到的所有文件内容:
Untracked.txt
未跟踪的文件:
(使用 "git add <文件>..." 以包含要提交的内容)
README.txt
Untracked.txt
提交为空,但是存在尚未跟踪的文件(使用 "git add" 建立跟踪)
Stage.txt
要提交的变更:
(使用 "git restore --staged <文件>..." 以取消暂存)
新文件: README.txt
未跟踪的文件:
(使用 "git add <文件>..." 以包含要提交的内容)
Stage.txt
Untracked.txt
Modified.txt
尚未暂存以备提交的变更:
(使用 "git add <文件>..." 更新要提交的内容)
(使用 "git restore <文件>..." 丢弃工作区的改动)
修改: README.txt
未跟踪的文件:
(使用 "git add <文件>..." 以包含要提交的内容)
Modified.txt
Stage.txt
Untracked.txt
修改尚未加入提交(使用 "git add" 和/或 "git commit -a")
开始时创建了 README.txt,Git 状态为未跟踪,对应 Untracked.txt 显示的状态。
输入命令git add README.txt
;
README.txt 的 Git 状态为已跟踪,未暂存,对应 Stage.txt 显示的状态。
输入命令git commit README.txt
;
README.txt 的 Git 状态为已暂存。
修改 README.txt 的内容;
README.txt状态为已变更,变更未暂存,对应 Modified.txt 显示的状态。
git add
使 README.txt 被 git 仓库跟踪,其修改状态可被 git 仓库感知,若未使用此指令,则状态一直未 未跟踪。
Thinking 0.2
add the file : git add filename
stage the file : git add filename
commit : git commit filename
Thinking 0.3
git checkout -- print.c
git reset HEAD print.c
git checkout -- print.c
git clean hello.txt -f
Thinking 0.4
三次提交后:
提交序号 | 哈希值 |
---|---|
1 | 0fb5628c1a0c6da35386b494fa821201be1001bd |
2 | f6c6c7b6a22c5b31eda77caa497ba8296371c35b |
3 | 393b36b7ffcf9a798682817d5e662d24b7fc6e3b |
执行git reset --hard HEAD^
后,gitlog 中仅存在前两次提交记录,第3次(最近一次)被撤销了。
执行git reset --hard 0fb5628c1a0c6da35386b494fa821201be1001bd
后,gitlog 中仅存在第1次提交记录,回到提交说明为1的版本。
执行 git reset --hard 393b36b7ffcf9a798682817d5e662d24b7fc6e3b
后,回到版本3,gilog中存在3次记录。
Thinking 0.5
执行echo first
输出 first 到屏幕(标准输出)上。
执行echo second > output.txt
重定向输入到 output.txt, output.txt内容:
second
执行echo third > output.txt
重定向输入到 output.txt, output.txt被覆写:
third
执行echo forth >> output.txt
重定向输入到 output.txt的文末, output.txt内容:
third
forth
Thinking 0.6
command.sh 文件内容:
1 #!/bin/bash
2 touch test
3 echo 'echo Shell Start...' > test
4 echo 'echo set a = 1' >> test
5 echo 'a=1' >> test
6 echo 'echo set b = 2' >> test
7 echo 'b=2' >> test
8 echo 'echo set c = a+b' >> test
9 echo 'c=$[$a+$b]' >> test
10 echo 'echo c = $c' >> test
11 echo 'echo save c to ./filel' >> test
12 echo 'echo $c>file1' >> test
13 echo 'echo save b to ./file2' >> test
14 echo 'echo $b>file2' >> test
15 echo 'echo save a to ./file3' >> test
16 echo 'echo $a>file3' >> test
17 echo 'echo save filel file2 file3 to file4' >> test
18 echo 'cat filel>file4' >> test
19 echo 'cat file2>>file4' >> test
20 echo 'cat file3>>file4' >> test
21 echo 'echo save file4 to ./result' >> test
22 echo 'cat file4>>result' >> test
result文件内容:
3
2
1
(随着执行次数增加result内的 3 2 1 序列数目也增加)
test 文件实现了
- 为变量 a b c 赋值
- 将变量分别写入三个文件
- 将三个文件的内容合并
- 将合并后的文件内容输出到result文件的文末
故可以解释上述输出。
指令 | 执行结果 |
---|---|
echo echo Shell Start | 屏幕上显示 echo Shell Start |
echo `echo Shell Start` | 屏幕上显示 Shell Start |
echo echo $c>file1 | file1 被写入 echo |
echo `echo $c>file1` | file1 被写入 空字符串,屏幕上输出空行 |
难点分析
在 lab0 中,我认为难度较大的实验操作如下:
- Makefile文件的编写,由于从未接触过此类程序编译执行方式,编写过程中特殊的语法和跨文件夹链接的操作具有较大难度。
- 脚本文件的语法,在 .sh 文件中,变量和基本程序结构的使用方法与之前使用的编程语言有所不同,需要尽快掌握。
- awk 和 sed 高效处理字符串,这两类指令集批量处理字符串十分便携,但指令格式也相对复杂,可能需要查询文档才能准确使用。
思考体会
在 lab0 中,我熟悉了课上实验的评测流程;在所有题目中最让我感到困难的是 Exercise 0.4 的 Makefile 的编写,由于以往编写过的 Makefile 编译链接的都是同一个文件夹下的库和文件,导致不熟悉如何制定链接文件的位置来实现跨文件夹的编译;在课下的练习中,应该加强对 Makefile 的语法和功能的理解实践。