Lecture 8
Short Summary and Lessons
Context Points:
1. Interprocess Communication (IPC): Mechanism for processes to communicate and
synchronize without shared memory.
2. Message Passing Techniques:
o Direct (process-to-process) or Indirect (via mailbox).
o Synchronous (blocking) or Asynchronous (non-blocking).
3. Buffering:
o Zero capacity (blocking sender), bounded capacity, or unbounded capacity.
4. UNIX/Linux IPC Tools:
o Pipes, named pipes (FIFO), sockets, shared memory, and message queues.
5. System Calls:
o read(), write(), and close() handle file descriptors for communication.
6. Pipes for Communication:
o Half-duplex communication using pipe().
o Parent-child processes utilize pipes to exchange data.
Lessons:
1. Message Passing:
o Direct methods require explicit process names, while indirect methods use shared
mailboxes.
2. Synchronization:
o Blocking ensures process order; non-blocking allows multitasking.
3. UNIX/Linux Pipes:
o Pipes enable unidirectional data flow between related processes.
o Use pipe() to create communication channels and fork() to create
communicating child processes.
4. Practical Understanding:
o Parent writes to child via pipefd[1] and reads back using pipefd[0].
o Example code demonstrates a parent process receiving "Hello, world!" from its
child.
Lecture 9
Here’s a very short and quick summary of Operating Systems Lecture 9:
Key Concepts:
1. UNIX/Linux Interprocess Communication (IPC) Tools:
o Pipe: Communication between related processes (parent-child/siblings).
o Named Pipe (FIFO): Communication between related or unrelated processes.
o BSD Socket: Communication between processes on the same or different
systems.
2. Standard File Descriptors:
o Standard Input (0): Keyboard
o Standard Output (1): Screen
o Standard Error (2): Screen
3. Key System Calls for File and IPC:
o open(): Opens/creates a file, returning a file descriptor.
o read(): Reads data from a file/pipe.
o write(): Writes data to a file/pipe.
o close(): Closes a file descriptor.
o pipe(): Creates a pipe for IPC between processes.
4. Sample IPC Code Using Pipe:
o Parent creates a pipe and forks a child.
o Child writes data into the pipe; the parent reads and displays it.
5. Command-Line Pipes:
o Use | to connect processes (e.g., cmd1 | cmd2).
o Example: cat /etc/passwd | grep zaheer finds lines with "zaheer" in the
file.
This lecture focuses on the mechanics of IPC and file handling in UNIX/Linux systems
through system calls and command-line operations.
Lecture 10
Here’s a very short, to-the-point summary of Operating Systems Lecture 10:
Key Concepts
1. I/O and Error Redirection in UNIX/Linux:
o Redirect input (< or 0<), output (> or 1>), and error (2>) to/from files instead of
default devices (keyboard/display).
o
2. FIFOs (Named Pipes):
o Named pipes are persistent communication endpoints stored as files on the
filesystem.
o Unlike unnamed pipes, FIFOs:
Work between unrelated processes.
Are reusable.
o Created using:
mknod() or mkfifo() system calls in C.
mkfifo command in the shell.
o .
Key Commands and Examples
Create FIFO:
mkfifo fifo1
lecture 11
Here’s a concise summary of Lecture 11 of CS-604: Operating Systems:
Key Topics
1. FIFOs for Interprocess Communication (IPC):
o FIFOs are special files used for communication between processes in
UNIX/Linux.
o Client-server communication is implemented using two FIFOs:
FIFO1: Client writes, and the server reads.
FIFO2: Server writes, and the client reads.
2. Code Workflow:
o Server:
[Link] FIFO1 and FIFO2.
[Link] FIFO1 for reading and FIFO2 for writing.
[Link] the client's message via FIFO1, displays it, then sends a response
through FIFO2.
4. Closes and exits.
o Client:
1. Opens FIFO1 for writing and FIFO2 for reading.
2. Sends a message to the server through FIFO1 and waits for a response on
FIFO2.
3. Deletes FIFOs after communication and exits.
3. Compilation and Execution:
o Compile server and client programs (gcc \Run server in the background
(./server &) and then run the client (./client).
o Example output:
o Hello, world!
o Hello, class!
Process Management Commands:
1. ps:
o Displays information about running processes.
o Options:
-e: Show all processes.
-l: Use long format.
-u: User-oriented display.
This lecture focused on practical implementation of client-server communication using FIFOs
and introduced process monitoring commands (ps and top).
Lecture 12
Here’s a very quick summary of the key points from Lecture 12 on Operating Systems:
Process Management Commands:
1. fg: Moves a background job to the foreground.
2. bg: Puts a suspended job into the background.
3. jobs: Displays the status of suspended and background processes.
<Ctrl-Z>: Suspends the foreground process.
1. <Ctrl-C>: Terminates the foreground process.
2. kill: Sends a signal to a process to terminate it (e.g., kill -9 for forceful termination).
Thread Concept:
Thread: A lightweight process that shares the same address space and resources (like
memory) but has its own stack, program counter, and registers.
Single-threaded vs. Multi-threaded: A single thread processes one task at a time, while
multi-threaded processes can handle multiple tasks concurrently within the same process.
Advantages of Threads:
o Responsiveness, resource sharing, cost efficiency, and better use of
multiprocessor systems.
Disadvantages:
o Resource sharing requires synchronization, and writing multi-threaded programs
can be complex.
This is the core of the lecture on process management and threads in UNIX/Linux.
Lecture 13
1. User vs. Kernel Threads:
o User Threads: Managed by user libraries; fast, but block entire process if one
thread makes a system call.
o Kernel Threads: Managed by the OS; slower, but handle system calls without
blocking other threads.
2. Multi-threading Models:
o Many-to-One: Multiple user threads per kernel thread; no concurrency.
o One-to-One: One kernel thread per user thread; true concurrency.
o Many-to-Many: Multiple user threads on fewer kernel threads; no true
concurrency.
3. Solaris 2 Model: User threads mapped to Lightweight Processes (LWPs), with one
kernel thread per LWP.
4. POSIX Threads (Pthreads): Standard API for thread creation and management.
o Functions:
pthread_create(): Creates a thread.
pthread_join(): Waits for a thread.
pthread_exit(): Ends a thread.
5.
lecture14
1. Multiprogramming: Maximizes CPU use by switching between processes while others
wait for I/O.
2. Process Life Cycle: Processes alternate between CPU bursts (execution) and I/O bursts
(waiting).
3. CPU Scheduler & Dispatcher: Scheduler picks a process to run, and the dispatcher
allocates the CPU to it.
4. Preemptive vs Non-Preemptive:
o Non-preemptive: Process runs to completion or until waiting/terminating.
o Preemptive: Process can be interrupted.
5. Scheduling Criteria:
o Maximize CPU use, throughput, and minimize waiting, turnaround, and response
time.
6. FCFS Scheduling: Processes run in the order they arrive. It can cause long wait times for
shorter processes (convoy effect).
7. FCFS Example: For processes P1 (24ms), P2 (3ms), P3 (3ms):
o Waiting time for P1 = 0, P2 = 24, P3 = 27
o Average waiting time = 17ms.
Lecture 15 and 16
Here’s a very quick summary with abbreviations added:
Shortest-Job-First Scheduling (SJF)
Allocates CPU to the process with the shortest next CPU burst.
Difficult to predict next CPU burst; use exponential average (τn+1 = αtn + (1-α)τn).
Preemptive SJF: New process with shorter CPU burst preempts the current process
(called SRTF).
Non-preemptive SJF: The current process finishes before the next one starts.
Priority Scheduling
Each process has a priority (inverse of CPU burst).
Preemptive: Higher priority process preempts CPU.
Non-preemptive: New process goes to the ready queue.
Problem: Indefinite blocking (starvation), solved by aging (increasing priority of long-
waiting processes).
Round-Robin Scheduling (RR)
For time-sharing systems.
Allocates CPU for 1 time quantum, then moves to the next process.
Context switch occurs if CPU burst > quantum.
Issues: Small quantum = frequent context switches, large quantum = like FCFS.
Multilevel Queue Scheduling
Divides processes into queues (foreground, background) with different scheduling
algorithms.
Fixed priority or time-sliced scheduling between queues.
Let me know if you need more details on any part!
Lecture 17
Here’s a quick and concise summary of the lecture:
1. Multilevel Feedback Queue Scheduling:
o Processes move between different queues based on their CPU usage.
o I/O-bound and interactive processes stay in higher-priority queues.
o Processes may be promoted or demoted to avoid starvation.
2. UNIX System V Scheduling Algorithm:
o A multilevel feedback priority queues algorithm with round robin scheduling.
o Priorities are divided into Kernel and User groups.
o Kernel priorities are fixed, while User priorities are recalculated every second.
o CPU-bound processes are penalized in favor of I/O-bound ones.
3. Algorithm Evaluation:
o Scheduling algorithms are evaluated based on:
CPU utilization and response time.
Throughput and turnaround time.
o Analytic Evaluation: Uses modeling techniques like deterministic modeling and
queuing models.
o Simulation: A more accurate evaluation method that models the system but is
expensive and may be inaccurate due to assumptions.