← Back to Portfolio

OS CPU Scheduling

Technologies Used

C UNIX/Linux System Calls (fcntl)

Overview

This project consists of five separate C programs, each implementing a fundamental concept in operating systems: four CPU scheduling algorithms and a secure file locking mechanism. They provide practical examples of process management and concurrency control in a UNIX-like environment.

Implementations

Scheduling Algorithms

Secure File Locking

This program demonstrates resource protection using the fcntl() system call. The key logic involves:

  1. Opening a file descriptor for the target file.
  2. Setting a lock type to exclusive write lock (F_WRLCK).
  3. Calling fcntl(fd, F_SETLKW, &myFlock). The F_SETLKW (SET Lock Wait) flag is crucial, as it makes the call a blocking operation. If another process holds the lock, this process will wait indefinitely until the lock is released.
  4. Once the lock is acquired, the process holds it until the user provides input to release it by setting the lock type to F_UNLCK.