0% found this document useful (0 votes)
14 views3 pages

Lab Task6 17042025 023659pm

The document outlines Lab Task 06 for the CSC320 Operating Systems course, due on April 16, 2025. It includes individual programming tasks in C++ that involve launching GUI programs, executing child processes, logging system commands, and validating script arguments. The lab aims to enhance understanding of system calls and integration of system-level programs with C++ applications.

Uploaded by

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

Lab Task6 17042025 023659pm

The document outlines Lab Task 06 for the CSC320 Operating Systems course, due on April 16, 2025. It includes individual programming tasks in C++ that involve launching GUI programs, executing child processes, logging system commands, and validating script arguments. The lab aims to enhance understanding of system calls and integration of system-level programs with C++ applications.

Uploaded by

armarking654
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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: 06
Due Date: Wednesday, 16 Aprial, 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:
Question 1: Launching a GUI Program with Validation
Objective: Validate the existence of the gedit editor before launching.
Write a C++ program that checks whether the gedit text editor exists in /usr/bin/gedit. If it
exists, use execl() to open it. If it doesn’t exist, print an error message and exit gracefully.
Hint: Use access() with X_OK.

Question 2: Execute Calculator in a Child Process


Objective: Understand how execl() behaves in a forked process.
Write a C++ program that creates a child process using fork(). The child should launch
gnome-calculator using execl(), while the parent prints its PID and waits for the child to
complete.
Hint: Use waitpid() in the parent.

Question 3: System Command Execution with Logging


Objective: Run system utilities and log the command.
Create a program that logs the current date/time using the date command via execl(). After
that, append "--- Logged by user ---" using the output of the whoami command.
Hint: Use file I/O or temporary files.

Question 4: Python Script Execution with Argument Validation


Objective: Execute external scripts with parameters and validate results.
Assume a Python script analyze.py expects two numbers and prints their sum. Write a C++
program that accepts two numbers from the command line, validates them, and passes them
to analyze.py using execl().
Bonus: Print an error if inputs are non-numeric.

Question 5: Launch Interactive Bash Shell After Program Validation


Objective: Build hybrid control flow using execl().
Write a C++ program that asks the user a password. If correct (hardcoded), launch an
interactive bash shell using execl(). Otherwise, print "Access Denied" and exit.

Question 6: Fallback Mechanism on Command Failure


Objective: Handle failure gracefully and provide alternatives.
Attempt to launch gedit using execl(). If it fails, fallback to launching nano using terminal
commands. Log the result.

Question 7: Chained Executions Using execl() and Shell Scripts


Objective: Understand command chaining and script launching.
Write a shell script status.sh that prints disk usage, memory usage, and current user. Create a
C++ program to execute this script using execl(). Ensure the script is executable. Report error
if script is missing.

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. Mins 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:
 You will understand how to work with low-level system calls like execl().
 You will learn how to integrate system-level programs with your C++
application.
 You will develop hybrid application interaction using scripting and
compiled languages.

You might also like