0% found this document useful (0 votes)
11 views7 pages

Operating Systems Lab Tasks Guide

The document outlines the lab task for CSC320: Operating Systems, focusing on understanding operating system structures and functions. Students are required to complete four programming tasks in C++ related to process management, including synchronization, orphan processes, zombie processes, and using waitpid(). The submission must adhere to specific formatting guidelines and be submitted as a PDF by March 19, 2025.

Uploaded by

za241967
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views7 pages

Operating Systems Lab Tasks Guide

The document outlines the lab task for CSC320: Operating Systems, focusing on understanding operating system structures and functions. Students are required to complete four programming tasks in C++ related to process management, including synchronization, orphan processes, zombie processes, and using waitpid(). The submission must adhere to specific formatting guidelines and be submitted as a PDF by March 19, 2025.

Uploaded by

za241967
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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.

Common questions

Powered by AI

Creating an orphan process demonstrates the role of the init process as the ultimate parental authority over all orphaned processes in Unix-like operating systems. When a parent process terminates, leaving behind a child, the child process becomes orphaned. In such cases, the init process (PID = 1) automatically adopts the orphan, ensuring that resources are eventually released and maintaining system stability.

Creating and managing files in a Linux environment aids in building a foundational understanding of the operating system’s file structure, permissions, and command-line utilities. Mastery of these skills demonstrates competence in navigating directory hierarchies, using text editors, and executing essential system commands, which are critical competencies for system administration, programming, and troubleshooting within a Linux OS as emphasized in the learning outcomes.

The command 'ps -elf | grep Z' is used to identify zombie processes, which are processes that have completed execution but still occupy an entry in the process table. This state occurs because the parent process has not yet read the child’s exit status through wait() or waitpid(). Identifying zombies is critical for system administrators to ensure efficient resource management and prevent cluttering of the process table, which could lead to system slowdowns or resource exhaustion.

Learning to use built-in text editors and viewing system information is important as it cultivates essential skills for efficient system administration and programming within a Linux environment. These skills enable users to edit configuration files, write scripts, manage software installations, and analyze system performance, thereby enhancing problem-solving and system optimization capabilities crucial for effective Linux systems management.

Submitting documentation with screenshots and proper formatting is crucial because it demonstrates thorough understanding and execution of the lab tasks. It ensures clarity, aids in evaluating the correctness and effectiveness of the solutions, and helps instructors verify that the work is original and correctly carried out according to guidelines. Proper documentation also serves as a valuable resource for future reference and debugging.

Proper submission with the correct file naming convention facilitates efficient academic management and clear communication by ensuring that submissions are easily identifiable and organized, thereby reducing administrative load on instructors. It helps in accurately track and evaluate student work, enabling timely feedback and grading, and ensures compliance with institutional procedures.

The waitpid() system call differs from wait() by allowing a parent process to wait for a specific child process to terminate, identified by the child's process ID. Unlike wait(), which can only wait for any arbitrary child process, waitpid() provides more precise control in environments with multiple child processes. Its use advantages include improved management of complex process hierarchies and avoidance of unpredictable execution order when multiple children are involved.

The emphasis on avoiding plagiarism is rooted in the importance of academic integrity and the need for students to demonstrate their understanding and problem-solving abilities independently. Plagiarism undermines the learning process and can lead to serious academic consequences, including loss of marks, disciplinary action, and damage to one's academic reputation.

The immediate exit of a parent process poses the challenge of potentially leaving child processes unmanaged, leading to resource leaks if not handled properly. However, in Unix-like operating systems, the init process automatically adopts any orphaned processes, ensuring that they have a valid parent process and that their eventual termination is properly managed, thus maintaining system resource integrity.

The wait() system call enables the parent process to pause its execution until one of its child processes terminates, ensuring that the child process completes its task before the parent continues. This synchronization is crucial to manage the order of execution in concurrent processes, preventing the parent from prematurely executing its subsequent operations without considering the termination of its children.

You might also like