Skip to content

Commit 4686de2

Browse files
Cdk# CDK – CloudKernel OS Simulation
Adds CloudKernel, a small Java simulation for our Operating Systems Lab. Demonstrates basic OS concepts: system boot, VM synchronization, and limited resource sharing. Includes: + Project source code + README with run instructions + Project report (PDF) + .gitattributes for line endings Uses CountDownLatch, CyclicBarrier, and Semaphore to coordinate VMs and resources.
2 parents a64c4c3 + 7d15dbd commit 4686de2

16 files changed

Lines changed: 518 additions & 0 deletions

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

CloudKernel/README.md

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# CloudKernel ☁️⚙️
2+
3+
## Overview
4+
5+
**CloudKernel** is a small Java-based simulation created for our **Operating Systems Lab**.
6+
The purpose of this project is to show how a hypervisor-like system can manage multiple **Virtual Machines (VMs)** while coordinating shared resources.
7+
8+
Instead of building a real operating system, this project focuses on demonstrating **important OS concepts** like synchronization, resource sharing, and concurrent execution using Java threads.
9+
10+
The program simulates a system where several virtual machines start after the system boots, run tasks together, and share limited network resources.
11+
12+
---
13+
14+
## 🎓 Academic Information
15+
16+
**Course:** Operating Systems Lab
17+
**Semester:** 4th Semester
18+
19+
**Submitted to:**
20+
Mam Amara Nadeem
21+
22+
**Submitted by:**
23+
24+
- **Moavia Amir** (2k24_BSAI_72)
25+
- **Ali Raza** (2k24_BSAI_44)
26+
- **Muhammad Arslan Nasir** (2k24_BSAI_26)
27+
28+
**Submission Date:**
29+
March 03, 2026
30+
31+
---
32+
33+
## 🎯 Project Goals
34+
35+
This project was designed to help understand how operating systems manage:
36+
37+
- System boot coordination
38+
- Thread synchronization
39+
- Limited resource sharing
40+
- Parallel execution of processes
41+
42+
All these ideas are implemented using **Java concurrency utilities**.
43+
44+
---
45+
46+
## ⚙️ Key Concepts Used
47+
48+
### 1. System Boot Coordination
49+
50+
Before any virtual machine starts running, the system must finish its boot process.
51+
52+
We simulate this using **CountDownLatch**.
53+
It ensures that resources like **Disk and RAM** are ready before the virtual machines begin execution.
54+
55+
---
56+
57+
### 2. VM Cycle Synchronization
58+
59+
Each virtual machine performs its work in cycles.
60+
To keep them synchronized, we use **CyclicBarrier**.
61+
62+
This means all VMs must finish a cycle before the next one begins.
63+
64+
---
65+
66+
### 3. Limited Network Access
67+
68+
In real systems, hardware resources are limited.
69+
In this simulation, only **two VMs can use the network at the same time**.
70+
71+
This is managed using a **Semaphore**, which controls access to the shared network ports.
72+
73+
---
74+
75+
## 🧩 Project Structure
76+
```
77+
CloudKernel
78+
79+
├── src
80+
│ │
81+
│ ├── Main.java
82+
│ │
83+
│ ├── core
84+
│ │ ├── BootManager.java
85+
│ │ ├── ClockSynchronizer.java
86+
│ │ └── NetworkPortManager.java
87+
│ │
88+
│ ├── entities
89+
│ │ └── VirtualMachine.java
90+
│ │
91+
│ └── utils
92+
│ └── Logger.java
93+
94+
├── doc
95+
│ └── proposal
96+
97+
└── README.md
98+
```
99+
---
100+
101+
## 🏗 System Workflow
102+
103+
The program runs in the following order:
104+
105+
```
106+
System Boot
107+
108+
109+
BootManager initializes resources
110+
111+
112+
Virtual Machines start (Threads)
113+
114+
115+
VMs execute cycles together
116+
117+
118+
Network access controlled by Semaphore
119+
120+
121+
Logs printed to terminal
122+
```
123+
124+
---
125+
126+
## ▶️ How to Run the Project
127+
128+
### 1. Compile the project
129+
130+
```bash
131+
javac -d out -sourcepath src src/Main.java
132+
```
133+
### 2. Run the program
134+
```bash
135+
java -cp out Main
136+
```
137+
## 🖥 Example Output
138+
139+
When the program runs, you may see output like:
140+
```
141+
[BOOT] Disk initialized
142+
[BOOT] RAM initialized
143+
[BOOT] System ready
144+
145+
[VM-1] Starting execution
146+
[VM-2] Starting execution
147+
[VM-3] Starting execution
148+
149+
[VM-1] Requesting network access
150+
[VM-2] Requesting network access
151+
152+
[VM-1] Using network port
153+
[VM-2] Using network port
154+
155+
[VM-3] Waiting for network port
156+
```
157+
The Logger class keeps the output organized so it is easier to read.
158+
159+
## 🧠 What We Learned
160+
161+
While building this project, we understood how operating systems handle:
162+
163+
+ **Thread** synchronization
164+
165+
+ **Shared** resource management
166+
167+
+ **Parallel** execution
168+
169+
+ **Process** coordination
170+
171+
These concepts are important for understanding how real operating systems and cloud platforms work.
172+
173+
---
174+
175+
## 📌 Conclusion
176+
177+
CloudKernel is a simple educational simulation that demonstrates how a hypervisor-like system can coordinate virtual machines and manage shared resources.
178+
179+
Although it is a simplified model, it provides a clear understanding of synchronization and concurrency in operating systems.
180+
181+
---
19.4 KB
Binary file not shown.

CloudKernel/out/Main.class

2.38 KB
Binary file not shown.
2.25 KB
Binary file not shown.
1.7 KB
Binary file not shown.
1.48 KB
Binary file not shown.
1.96 KB
Binary file not shown.

CloudKernel/out/utils/Logger.class

1.96 KB
Binary file not shown.

CloudKernel/src/Main.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import core.BootManager;
2+
import core.ClockSynchronizer;
3+
import core.NetworkPortManager;
4+
import entities.VirtualMachine;
5+
import utils.Logger;
6+
7+
// Entry point for the CloudKernel simulation.
8+
public class Main {
9+
10+
private static final int NUM_VMS = 3;
11+
private static final int NUM_CYCLES = 2;
12+
13+
public static void main(String[] args) throws InterruptedException {
14+
// Phase 1: boot
15+
Logger.section("PHASE 1: SYSTEM BOOT [CountDownLatch]");
16+
Logger.log("HYPERVISOR", "CloudKernel v1.0 starting...", Logger.BOLD + Logger.GREEN);
17+
18+
BootManager bootManager = new BootManager();
19+
bootManager.initDisk();
20+
bootManager.initRAM();
21+
bootManager.awaitBootCompletion();
22+
23+
Thread.sleep(500);
24+
25+
// Phase 2: VM execution
26+
Logger.section("PHASE 2: VM EXECUTION [CyclicBarrier + Semaphore]");
27+
int[] cycleNum = { 0 };
28+
ClockSynchronizer clock = new ClockSynchronizer(NUM_VMS, cycleNum);
29+
NetworkPortManager networkManager = new NetworkPortManager();
30+
31+
Logger.log("HYPERVISOR",
32+
"Launching " + NUM_VMS + " VMs for " + NUM_CYCLES + " cycles each...",
33+
Logger.CYAN);
34+
35+
Thread[] vmThreads = new Thread[NUM_VMS];
36+
for (int i = 1; i <= NUM_VMS; i++) {
37+
int workDuration = 600 + (i * 200);
38+
39+
VirtualMachine vm = new VirtualMachine(
40+
"VM-" + i, NUM_CYCLES, clock, networkManager, workDuration);
41+
vmThreads[i - 1] = new Thread(vm, "VM-" + i);
42+
vmThreads[i - 1].start();
43+
}
44+
45+
for (Thread t : vmThreads) {
46+
t.join();
47+
}
48+
49+
// Phase 3: shutdown
50+
Logger.section("PHASE 3: SYSTEM SHUTDOWN");
51+
Logger.log("HYPERVISOR", "All VMs have completed execution.", Logger.GREEN);
52+
Logger.log("HYPERVISOR", "Releasing all system resources...", Logger.YELLOW);
53+
Thread.sleep(300);
54+
Logger.log("HYPERVISOR", "CloudKernel has shut down cleanly. Goodbye. [OK]", Logger.BOLD + Logger.GREEN);
55+
Logger.separator();
56+
System.out.println();
57+
}
58+
}

0 commit comments

Comments
 (0)