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.
Implemented up to: Part 3 Step 4 (inclusive)
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)
- 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
- 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
- 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
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 |
| 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) |
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./programUpon 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):
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
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
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.
- 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
The child process (process) receives two command-line arguments:
- The PID assigned by the application
- 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.
- Dynamic memory allocation is used for both the process collection and owner names
- Error handling uses the
errno.hlibrary 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
- Steps 5 and 6 of Part 3 are not implemented:
- Natural process termination based on C parameter
- Named pipe communication with
stats_process
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.