Department of Computer Science
CSC320: Operating Systems Lab
Class: BSCS-5B
CLO1: Understand the characteristics of different
structures of the Operating Systems and identify the core
functions of the Operating Systems.
Lab Task: 04
Due Date: Wednesday, March 19, 2025
Submit Lab Task on LMS (02:30 PM)
Instructions:
1. It is an individual task.
2. Create a document containing script and each command’s execution result.
3. Attach required screenshots where specified.
4. Submit the document in pdf format before the due date. Submission file
name must include Lab number, your ID and name like
(W4_M-Abc_00-000000-000).
5. Any kind of plagiarism found will rsult a serious loss in marks.
6. Ensure proper formatting and labeling of screenshots.
Lab Task:
Task 1: Using wait() to Synchronize Parent and Child Processes
Question:
Write a C++ program where:
1. The parent process creates a child process using fork().
2. The child prints its PID and exits using exit(0).
3. The parent uses wait() to ensure the child terminates before it prints its own message.
Expected Output (Order should be controlled using wait()):
Child Process: PID =
Parent Process: PID =
Child terminated, parent exiting.
Task 2: Creating an Orphan Process
Question:
Write a C++ program that:
1. The parent creates a child process.
2. The parent exits immediately, making the child an orphan.
3. The child prints its PID and its new parent PID (getppid()).
4. Use ps -elf | grep [child_pid] to verify that the orphan process is adopted by init (PID
= 1).
Expected Output (Run ps -elf while the child is running):
Parent exiting...
Child Process: PID = , New Parent PID = 1
Task 3: Creating a Zombie Process
Question:
Write a C++ program that:
1. The parent creates a child process.
2. The child prints a message and exits immediately.
3. The parent does not call wait(), leaving the child as a zombie process.
4. Use ps -elf | grep Z to observe the zombie state before the parent terminates.
Expected Output (Check process list before parent exits):
Child Process (PID ) exiting...
Parent Process (PID ) running...
(Check zombie process using ps -elf | grep Z)
Task 4: Using waitpid() to Control Execution Order
Question:
Modify Task 1 to use waitpid() instead of wait(), ensuring that the parent only waits for a
specific child process.
• Use pid_t waitpid(child_pid, &status, 0);
• Observe how waitpid() works when multiple child processes exist.
Deliverables
Upload the document containing codes as well as screenshots on LMS.
Do strictly follow the submission guidelines please. Do not submit separate code for each task
in the form of zip folders etc.
Grade Criteria
This lab is graded. Min marks: 0. Max marks: 10.
Activity Minimum Maximum
Documentation with clearly defined Fail Pass
understanding of the lab task and
approach
Lab Tasks 0 10
Learning Outcomes:
✓ By the end of this lab, students should be able to:
✓ Navigate and manage files in a Linux environment.
✓ Perform basic file and directory operations.
✓ Use built-in text editors and view system information.
✓ Understand and execute essential Linux commands efficiently.