Small C exercises exploring processes, fork(), IPC, CPU scheduling, page
replacement, and file I/O.
All 13 experiments in the supplied list are covered. Existing programs are kept in their original folders; the missing experiments are added below.
| No. | Question (simple wording) | Source |
|---|---|---|
| 1 | Create a child process using fork(). | Fork demo |
| 2 | Parent adds odd numbers; child adds even numbers from 1 to n. | Odd/even sums |
| 3 | Make the parent wait until the child finishes. | Wait demo |
| 4 | Show orphan and zombie processes. | Orphan, Zombie |
| 5 | Send data between processes using a pipe. | Pipe demo |
| 6 | Send a message using a FIFO (named pipe). | Writer, Reader |
| 7 | Send and receive a message using a message queue. | Sender, Receiver |
| 8 | Write and read a message using shared memory. | Writer, Reader |
| 9 | Run processes in first come, first served order. | FCFS |
| 10 | Run the shortest available job first. | SJF |
| 11 | Run the available process with the highest priority first. | Priority |
| 12 | Replace the oldest loaded page when frames are full. | FIFO pages |
| 13 | Replace the page that has not been used for the longest time. | LRU pages |
Use Linux or Ubuntu in WSL with GCC. The process and IPC programs need Linux system calls and cannot be run directly with a Windows-only C compiler. Compile each source separately, for example from the project folder:
gcc -std=c11 -Wall -Wextra November12/parent_odd_child_even_sum.c -o /tmp/odd_even
/tmp/odd_even
gcc -std=c11 -Wall -Wextra November13/fcfs_scheduling.c -o /tmp/fcfs
/tmp/fcfsFor each IPC pair, compile both files separately in the same way:
- FIFO: start the writer, enter a message, then run the reader in another
terminal from the same directory. The writer waits for the reader. The reader
removes
os_lab_fifoafter reading it. - Message queue: run the sender first, then the receiver. The receiver removes the queue after reading the message.
- Shared memory: run the writer first and let it finish, then run the reader. The reader removes the shared memory after reading it.
Run one pair at a time. The message queue uses key 1234 and shared memory uses
key 5678; use these examples where those keys are free. If a run is interrupted,
ipcs lists remaining IPC objects; remove only this example's queue or memory
with ipcrm -Q 1234 or ipcrm -M 5678. Remove a leftover FIFO with
rm os_lab_fifo from the directory where the writer ran.
Scheduling programs accept up to 20 processes. Arrival and burst times are whole numbers up to 100000; burst time must be positive. SJF and priority are non-preemptive: a running process finishes before another starts. Smaller priority numbers mean higher priority. Ties follow input order.
Page replacement programs accept up to 100 nonnegative page numbers and up to 20 frames. They print the frames after each reference and count hits and faults.
- Child prints numbers; parent waits
- Child Fibonacci; parent factorial
- Create three child processes
- Fork: parent and child messages
- Orphan process demonstration
- Parent and child PIDs/PPIDs
- Parent prints evens; child prints odds
- Parent reads child exit status
- Parent sum, child Fibonacci, grandchild factorial
- Zombie process demonstration
- Child sends even numbers to parent through a pipe
- Pipe example with child exit-status checking
- Zombie process placeholder (empty)
Copilot was used to structure this README.