Skip to content

dalouc/process-scheduler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Process Scheduler Emulator

A C-based application that emulates the simplified behavior of a process scheduler, allowing users to interactively manage a scheduling table. This project was developed as part of the Systems Architecture course at Carlos III University of Madrid.

Project Status

Implemented up to: Part 3 Step 4 (inclusive)

Overview

This application simulates a process scheduler with the following capabilities:

  • Interactive management of a process schedule (add, delete, search, display, sort)
  • File I/O operations for saving and loading schedules
  • Process execution emulation using fork/exec with round-robin scheduling
  • Signal handling for process control (SIGINT, SIGALRM, SIGSTOP, SIGCONT)

Features

Part 1: Core Functionality

  • Add Process: Create new processes with owner name, priority, and execution time
  • Delete Process: Remove a process by its PID
  • Process Information: Display details of a specific process
  • Show Schedule: Display all processes in the current schedule
  • Delete Schedule: Clear all processes from the schedule
  • Sort Schedule: Sort processes by PID, priority (P), execution time (C), or owner name using function pointers

Part 2: File Operations

  • Load from File: Import a schedule from a binary file using fread
  • Save to File: Export the current schedule to a binary file using fwrite

Part 3: Process Execution

  • Execute Schedule: Launch child processes and manage them with round-robin scheduling
  • Round-Robin Scheduling: Each process receives a 1-second timeslot before being suspended
  • Signal Handling: Graceful termination with CTRL+C, displaying execution summary

Data Structures

Each process contains the following fields:

Field Description
pid Process identifier (unique, auto-assigned, never reused)
user Owner name (dynamically allocated, unlimited length)
p Priority (integer > 0)
C Execution time (integer > 0)
state Process state: READY, RUNNING, or TERMINATED

Project Structure

File Description
program.c Main program with menu logic and error handling
menu.c / menu.h Menu display module
input_usr.c / input_usr.h Keyboard input handling module
item.c / item.h Process (item) definition and management
collection.c / collection.h Process collection management (dynamic array)
errors.c / errors.h Error handling with custom error codes
execute_schedule.c / execute_schedule.h Schedule execution with fork/exec
process.c Child process executable (separate compilation)

Compilation

The project requires two separate compilations:

# Compile main program
gcc -g -Wall collection.c errors.c execute_schedule.c input_usr.c item.c menu.c program.c -o program

# Compile child process executable
gcc -g -Wall process.c -o process

Execution

./program

Usage

Upon execution, the following menu is displayed:

Program that emulates a process scheduler.

Select one of the following options:

1. Add a new process to the schedule
2. Delete a certain process from the schedule
3. Information about a process
4. Show the entire schedule
5. Delete the current schedule
6. Sort the schedule according to a criteria
7. Load from file
8. Save to file
9. Execute schedule
10. Help
0. Exit

If you enter CTRL+D:
- In this menu, the program will terminate in a controlled manner.
- In a submenu, the program will return to this menu.

Please enter an option (help: 10):

Example: Adding a Process

Please enter an option (help: 10): 1
Adding a new process.
Enter the name of the owner: Ada Lovelace
Enter the priority of the process: 1
Enter the execution time (C): 10
Process added to the schedule at position 1

Example: Executing the Schedule

Please enter an option (help: 10): 9
Executing the current schedule
POS   PID     P       C       STAT            OWNER
  1     2     4       5       READY       Annie Easley
  2     5     3      15       READY      Maria Mitchell
  3    12     2      25       READY       Grace Hopper
I launched the child processes.
[9980] Process 2 **** iter 1
[9980] Process 2 **** iter 2
[9981] Process 5 *** iter 1
...
^C
Execution summary:
  PID   real PID        STAT   NUM-EXEC   END-STATUS
    2       9980       READY          2            0
    5       9981     RUNNING          2            0
   12       9982       READY          1            0

Input Validation

The program enforces strict input validation:

Input Type Expected Format
Name Characters or integers
PID Integer
Execution time Integer
Priority Integer
Yes/No YES, Yes, yes, y, Y, NO, No, no, n, N

Invalid inputs will prompt the user to re-enter the value until a valid input is received.

Signal Handling

  • CTRL+D in main menu: Terminates the program gracefully
  • CTRL+D in submenus: Returns to the main menu
  • CTRL+C during schedule execution: Kills all child processes and displays execution summary
  • CTRL+C outside execution: Terminates the program

Process Execution Details

The child process (process) receives two command-line arguments:

  1. The PID assigned by the application
  2. The priority of the process

It prints an infinite loop with the format:

[<real_PID>] Process <app_PID> [<stars>] iter <iteration>

where the number of stars equals the priority value.

Technical Notes

  • Dynamic memory allocation is used for both the process collection and owner names
  • Error handling uses the errno.h library with custom error codes
  • Function pointers are used for sorting operations (required by specification)
  • The schedule uses a dynamic array that doubles in capacity when full
  • PIDs are never reused, even after process deletion

Limitations

  • Steps 5 and 6 of Part 3 are not implemented:
    • Natural process termination based on C parameter
    • Named pipe communication with stats_process

Acknowledgments

Some functions in collection.c, collection.h, errors.c, errors.h, input_usr.c, item.c, and item.h were adapted from course materials provided in lecture slides.

Authors

Noel Andolz Aguado and Daniel Lozano Uceda

About

UC3M "Systems Architecture" Lab Project

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages