Lab 04: Process Creation
In this lab, you will learn to use UNIX system calls to create new processes.
Exercises
In this exercise, you are required to write a program named lab04.c in your working directory to complete the following tasks:
(1) To create the processes as the diagram shown in Fig. 1, where Process 1 is the parent of process 2 and process 2 is the parent of process 3.
(2) Processes will print out the messages including their PID and their child PID.
Sample output is shown as follows (just for your reference, not the hard codes)
Process 1: My PID is 2542 and I have a child process with PID=2543
Process 2: My PID is 2543 and I have a child process with PID=2544
Process 3: My PID is 2544 and I have no child process.
Note that the actual order of the processes can be different from this output while the process relationship shall be maintained.
实验04:流程创建
在本实验中,您将学习使用UNIX系统调用来创建新进程。
练习题
在本练习中,您需要在工作目录中编写一个名为lab04.c的程序以完成以下任务:
(1)创建如图1所示的流程,其中流程1是流程2的父级,流程2是流程3的父级。
(2)进程将打印出包括其PID和其子PID的消息。
输出示例如下(仅供参考,不包括硬编码)
流程1:我的PID是2542,我有一个子进程,其PID = 2543
流程2:我的PID是2543,我有一个子进程,PID = 2544
流程3:我的PID是2544,我没有子流程。
注意,在保持过程关系的同时,过程的实际顺序可能与此输出不同。