Welcome to the Operating Systems repository! This project is a collection of C programs that explore and implement fundamental concepts of operating systems, focusing on system calls, Inter-Process Communication (IPC) mechanisms, threads, signals, and classic synchronization problems.
This repository serves as a practical guide and hands-on implementation hub for key OS concepts. The goal is to provide clear, well-commented code that demonstrates how these low-level functionalities work. Whether you're a student learning about operating systems or a developer looking to refresh your knowledge, you'll find valuable examples here.
This repository contains implementations for the following topics:
A collection of programs demonstrating the use of fundamental system calls for process management found in the basics directory.
- fork(): Creating child processes.
- wait(): Synchronizing parent and child processes.
- sleep(): Suspending process execution.
- getpid() & getppid(): Retrieving process and parent process IDs.
- Threads: Implementations exploring multi-threading concepts.
- Signals: Programs demonstrating how to handle signals for asynchronous event handling. This includes:
- Setting up custom signal handlers using
signal()
andsigaction()
. - Sending signals to processes using the
kill()
system call. - Using signals for inter-process communication, such as in the
sharedmemory_signal
example.
- Setting up custom signal handlers using
Implementations of various IPC mechanisms to allow processes to communicate and synchronize their actions.
- Anonymous Pipes: Unidirectional communication between related processes.
- Named Pipes (FIFO): Communication between unrelated processes (TwoWayCommfifo).
- Shared Memory: Allowing multiple processes to access the same memory segment.
- Polling: Efficiently handling I/O from multiple sources.
Solutions to classic concurrency and synchronization problems, demonstrating how to avoid race conditions and deadlocks.
- Producer-Consumer Problem
- Reader-Writer Problem
- Dining Philosophers Problem
Practical applications built using the concepts above to showcase their real-world utility.
- One-to-One Chat System
- Shared Chat System (Group Chat)
- News Room Synchronization
The code is organized into directories .
Operating_system
βββ Anonymouspipes/
βββ basics/
βββ pipes/
βββ poll/
βββ sharedmemory/
β βββ multi_message_Communication/
β βββ ...
βββ signals/
β βββ sharedmemory_signal/
β βββ sigaction/
| | βββ sharedmemory(using signal and handler function)/
β βββ ...
βββ Threads/
βββ TwoWayCommfifo/
βββ Process_Synchronization/
βββ Basic/
βββ Dinning_Philospher/
βββ Producer_consumer/
βββ Reader_Writer/
Follow these instructions to get the code up and running on your local machine.
You will need a Cpp compiler (like g++) and a Unix-like operating system (Linux, macOS) to run these examples.
-
Clone the repository:
git clone [https://github.com/your-username/your-repo-name.git\](https://github.com/your-username/your-repo-name.git)
cd your-repo-name -
Navigate to a specific implementation's directory:
cd pipes/ -
Compile the C file using gcc:
-
For basic programs:
g++ source_file.cpp -o output_file -
When using threads (pthreads), you must link the pthread library:
g++ -lpthread source_file.cpp -o output_file -
When using the math library, link it with -lm:
g++ -o output_file source_file.c -lm
-
-
Run the compiled executable:
./output_fileNote: Some programs, especially the chat applications, may require running multiple executables (e.g., a server and a client) in separate terminal windows.
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
- Fork the Project
- Create your Feature Branch (git checkout -b feature/AmazingFeature)
- Commit your Changes (git commit -m 'Add some AmazingFeature')
- Push to the Branch (git push origin feature/AmazingFeature)
- Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.
Happy Coding!