FAST-NUCES · Spring 2025 · CS-2006

Operating Systems – Shell Scripting

My Operating Systems lab work from Spring 2025. Two assignments: Bash scripts and a C string toolkit, then five C/C++ programs on processes, pipes, threads and CPU scheduling.

2Assignments
4Bash scripts
11C/C++ source files
6Makefiles

Overview

This is my CS-2006 Operating Systems lab work from Spring 2025 at FAST-NUCES. The assignment briefs sit next to the code in each folder.

Assignment 1

Bash scripts and a C toolkit

A disk cleanup helper, a file-utility menu, an application-usage tracker, a personal expense ledger, and a C string toolkit that runs each task in a grandchild process with fork and execlp.

Assignment 2

Processes, threads and scheduling

A zombie survival game with pipes, office-hour thread sync, a cricket lineup tool (SJF, SRTF, Round Robin), four processes talking in a circle, and a three-level multilevel feedback queue.

Course

CS-2006 · Spring 2025

FAST-NUCES, section A, roll 22I-2327. The programs are written for Linux (Bash, gcc/g++ and POSIX).

Assignment 1

Four Bash scripts and a small C string toolkit. The original brief is in assignment-01.pdf.

Q01 Disk cleanup

Walks $HOME: the ten largest files (asks before deleting), a duplicate-file helper using MD5 (defined in the script, left commented in the default run), cache cleanup, and files not accessed in the last 10 days. The cache clean does not ask first. Do not run this on a machine you care about until you have read the script.

Q02 File utilities

A menu: invert a file’s permissions, search a file (a dot in the pattern means any character), stitch the first N lines of even-positioned files and the last N lines of odd-positioned files into dummy_file.txt, and touch a file if its modification time is more than 24 hours old. Messages are also written to text_file.txt.

Q03 Application usage

Every 10 seconds it reads the focused X11 window with xdotool, appends a line to ~/app_usage.log, and prints a minutes-and-seconds report. After one minute on a listed app it sends a notification and runs pkill. Needs xdotool (and notify-send for the warning).

Q04 String toolkit

You type one word. The parent writes it to input.txt, then for each task it double-forks and the grandchild runs a worker with execlp. Workers append to output.txt (task, PID, result). Option 6 prints that file. Run make so all six binaries sit in the same folder.

Q05 Expense tracker

A ledger in expenses.csv (date,category,amount). You can add a row, print per-category totals and savings (income minus expenses), print the file, plot spending with gnuplot, and set a budget. A warning appears if expenses go over the budget.

Assignment 2

Five C/C++ programs. The original brief is in assignment-02.pdf.

Q01 Zombie survival

A terminal game. The parent is the game manager. Each player and each zombie is a child process and talks through a pipe. After five turns the higher score wins. The zombie count comes from my roll number: (2327 * 3) % 20 + 1, which is 2.

Q02 Office hours

A professor thread and one student thread per person. Students take turns asking a question; the professor waits, answers, and only then is the next student let through. Shared flags are std::atomic — no mutexes or semaphores, as the brief asked.

Q03 Cricket scheduling

You enter batsmen and bowlers. For batting, SJF orders by strike rate and SRTF by average, then a predicted team score is printed. For bowling, SJF uses economy, SRTF uses wickets, and Round Robin rotates bowlers over a number of overs.

Q04 Circular pipes

Four processes, A → B → C → D → A, connected by unnamed pipes. Process A starts a message. Each of B, C and D appends a note, writes its own log file (log_A.txt … log_D.txt), and passes the result on. A prints the fully modified message when it comes back.

Q05 Multilevel feedback queue

Three queues: Round Robin with quantum 4, Round Robin with quantum 8, then FCFS to completion. You enter each process’s PID, arrival time and burst time. The program prints turnaround time and waiting time.

Folder Structure

Folder structure
OS_Shell_Script/
├── assignment-01/
│   ├── assignment-01.pdf
│   ├── q01-disk-cleanup/
│   │   └── q01-disk-cleanup.sh
│   ├── q02-file-utilities/
│   │   └── q02-file-utilities.sh
│   ├── q03-app-usage/
│   │   └── q03-app-usage.sh
│   ├── q04-string-toolkit/
│   │   ├── Makefile
│   │   ├── main_file.c
│   │   ├── reverse_str.c
│   │   ├── length_str.c
│   │   ├── ascii_add_2_str.c
│   │   ├── sort_str.c
│   │   └── capitalize_str.c
│   └── q05-expense-tracker/
│       └── q05-expense-tracker.sh
├── assignment-02/
│   ├── assignment-02.pdf
│   ├── q01-zombie-survival/
│   │   ├── Makefile
│   │   └── zombie-survival.cpp
│   ├── q02-office-hours/
│   │   ├── Makefile
│   │   └── office-hours.cpp
│   ├── q03-cricket-scheduling/
│   │   ├── Makefile
│   │   └── cricket-scheduling.cpp
│   ├── q04-circular-pipes/
│   │   ├── Makefile
│   │   └── circular-pipes.c
│   └── q05-mfq-scheduler/
│       ├── Makefile
│       └── mfq-scheduler.cpp
├── screenshots/
├── assets/
│   ├── css/style.css
│   ├── js/main.js
│   ├── favicon.svg
│   └── og-image.png
├── index.html
├── LICENSE
└── README.md

How to Run

Linux or WSL, with Bash, gcc and g++. The C programs use POSIX calls, so they are meant for Linux, not plain Windows.

Clone the repository

bash
git clone https://github.com/rohaan2802/OS_Shell_Script.git
cd OS_Shell_Script

Assignment 1 – a Bash script

bash
cd assignment-01/q02-file-utilities
chmod +x q02-file-utilities.sh
./q02-file-utilities.sh

Assignment 1 – the C string toolkit

bash
cd assignment-01/q04-string-toolkit
make
./main_file

Assignment 2 – any of the five programs

bash
cd assignment-02/q01-zombie-survival
make
./zombie-survival

The office-hours program is already linked with -pthread in its Makefile. The disk-cleanup script can delete files — read it before you run it. Q03 needs xdotool. Q05’s graph needs gnuplot.

License

The code I wrote is under the MIT License. The assignment PDFs belong to their instructors at FAST-NUCES and are here only for reference with this lab work.