#南昌大学实验报告
姓名:王梦佳
学号:6103115097
邮箱地址:[email protected]
专业班级:计科153班
实验日期:2018.4.30
课程名称:LINUX程序设计
##实验项目名称
Lab 4: Multi-processing in Linux
##实验目的
• Understanding the mechanism of multi-processing
• Understanding the idea of process scheduling
• Understanding multi-thread programming
##实验步骤
The Fork Question
Fork and fork more
The Collatz conjecture
进程是资源管理的最小单位,而线程是程序执行的最小单位。
##实验数据或结果
Determine what will be output at the commented lines LINE X and LINE Y
for fork_problem.c
makefile文件内容:
![makefile.png](https://upload-images.jianshu.io/upload_images/11549370-9fe21cc4c27d36f1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
frork-problem的结果:
![fork.png](https://upload-images.jianshu.io/upload_images/11549370-d5081e87774a2599.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
• How many unique processes are created using the multi-fork?
Complete the code for function fork1 in fork1.c
Complete the code for function fork2 in fork2.c
完善文件内容:
![fork-complete.png](https://upload-images.jianshu.io/upload_images/11549370-f304c86bebbda92f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
Compile both and run them
fork1的结果:
![fork1-result.png](https://upload-images.jianshu.io/upload_images/11549370-46777054b8ae4933.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
fork2的结果:
![fork2-result.png](https://upload-images.jianshu.io/upload_images/11549370-a55a664a573214cf.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
• Explain why they perform, differently.
Collatz问题:
Collatz.c直接运行的结果:
![collatz.png](https://upload-images.jianshu.io/upload_images/11549370-c714c63072a00295.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
运用链表和多线程后的thrd-Collatz.c的运行结果:
![thrd-Collatz.png](https://upload-images.jianshu.io/upload_images/11549370-f10920b56d6e52e8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
##参考资料
https://www.jianshu.com/