Lecture_5-CSCIU511-Jahangir_Majumder-Spring_2025
Page 1: Course Information
Course: CSCI U511 01 Operating Systems
Instructor: AKM Jahangir A Majumder, PhD
Semester: Spring 2025
Lecture Date: January 28, 2025
Note: Some slides are adapted from previous instructors and figures from the textbook.
Page 2: Review and Learning Outcomes
Topics to Discuss:
The Programming Interface
Concurrency and Threads
Implementing UNIX fork and exec
Implementing Shell
Single threaded and Multithreaded Approaches
Important Dates:
Quiz 1 grades and key posted on Blackboard.
Homework 2 will be due on Tuesday, Feb. 4.
Quiz 2 on Thursday, Feb. 6.
Action Items:
Start working on team projects.
Page 3: Review - UNIX Process Management
Important System Calls:
fork(): Creates a copy of the current process and starts it running (no arguments).exec(): Changes the program being run by the current process.wait(): Waits for a process to finish.signal(): Sends a notification to another process.
Page 4: UNIX Process Management Example
Code Pattern:
pid = fork(); if (pid == 0) exec(…); else wait(pid);Displays process creation with forks and how the parent process waits for child processes.
Page 5: fork() Example
A process executes code (forkthem(3)):
fork() fork() fork()Question: How many total child processes will be created?
Page 6: fork() Example Continued
Answer: 7 Child Processes will be created.
Page 7: fork() Process Values
Example:
Process A = 1 (Parent, A=1)
Process B = 2 (Child, B=2)
Modification Example: A=7, B=5 in child before exit.
Page 8: Coverage Summary
Finished coverage on Interface and Communication.
Now beginning coverage on Concurrency and Threads.
Page 9: Concurrency: Motivation
Operating systems and applications handle multiple simultaneous events.
Tasks include process execution, interrupts, background tasks, and system maintenance.
Problem: Humans struggle to track multiple simultaneous tasks.
Solution: Threads act as an abstraction to manage concurrency.
Page 10: Why Concurrency?
Use Cases:
Servers: Handle multiple connections at once.
Parallel programs: Improve performance.
User interfaces: Maintain responsiveness during computations.
Network/disk-bound programs: Hide latency issues.
Page 11: Contexts of Concurrency
Three Contexts of Concurrency:
Multiple Applications: Sharing processing time among applications.
Structured Applications: Extending modular design and structured programming.
Operating System Structure: Implemented as processes or threads.
Page 12: Thread Definitions
Thread Characteristics:
A thread is a single execution sequence, independently scheduled by the OS.
Protection can be orthogonal with multiple threads per protection domain.
Attributed to multithreading, which supports concurrent execution within processes.
Page 13: Examples of Threads
Use Case Examples:
Web Browsers: Threads for displaying images and retrieving network data.
Word Processors: Separate threads for graphics, keystrokes, and spell checking.
Web Servers: Threads for requests and servicing multiple clients simultaneously.
Page 14: Single-Threaded Approaches
Definition: A single thread of execution per process, where the thread concept may not be recognized.
Example: MS-DOS depicts a single-threaded approach where a single process runs a thread.
Page 15: Multithreaded Approaches
Overview: Systems like the Java run-time environment demonstrate multithreaded approaches where one process can have multiple threads.
Page 16: Thread State and Structure
Threads have execution states (Running, Ready, etc.), a saved context, an execution stack, and shared resources within the process.
Page 17: Process Models
Single-Threaded Process Model: Basic structure with block for user address space and stacks.
Multithreaded Process Model: Multiple thread control blocks within a process showcasing user and kernel stacks.
Page 18: Types of Threads
User Level Threads (ULT)
Kernel Level Threads (KLT)
Page 19: User-Level Threads (ULTs)
Thread management is application-based. The kernel is unaware of these threads.
Page 20: Advantages of ULTs
No kernel mode switch is necessary for thread switching.
Scheduling can be tailored to application needs.
ULTs are compatible with any OS.
Page 21: Disadvantages of ULTs
System calls are typically blocking; executing one blocks the application.
Multithreading limitations in a typical OS; the kernel schedules one thread per processor.
Page 22: Kernel-Level Threads (KLTs)
Managed by the kernel with no application-level management necessary; API provided for applications.
Page 23: Advantages of KLTs
Kernel can schedule threads on multiple processors and can switch to another thread when one is blocked.
Allows kernel routines to be multi-threaded.
Page 24: Disadvantage of KLTs
Mode switches required for thread control transfer; can cause delays in execution.
Page 25: Combined Approaches
Threads are mostly managed in user space, allowing for a hybrid scheduling and synchronization application.
Page 26: Threads in Kernel and User-Level
Multi-threaded kernels can share data structures and leverage privileged instructions, optimizing operations.
Page 27: Thread Abstraction
Programmers can create many threads that run on virtual processors with variable speeds. Programs must adapt to schedules.
Page 28: Thread Execution States
Key States:
Running, Ready, Blocked
Thread operations include Spawn, Block, Unblock, and Finish.
Page 29: Multithreading Example
Visual illustrates blocked threads waiting on I/O with multiple threads scheduled on a uniprocessor system.
Page 30: Multithreading Example Continued
Reinforces understanding of timing and quantum expiration in thread management.
Page 31: Programmer vs. Processor View
Possible executions indicate how threads can be interleaved and managed simultaneously without affecting a single thread's perceptions.
Page 32: Possible Interleaved Executions
Examples of three threads executed in an interleaved manner, showing various states of execution.
Page 33: Thread State Management
Most execution state information is maintained in thread-level data structures; suspending and terminating processes affects all their threads.
Page 34: Thread Operations API
Key functions:
thread_create(),thread_yield(),thread_join(), andthread_exit()for managing thread lifecycle.
Page 35: Example of Thread Creation
Example code demonstrates creating ten threads and handling their exit values accordingly.
Page 36: Thread Lifecycle
Overview of lifecycle events from creation to exit and how the scheduler resumes threads based on state.
Page 37: Summary of Coverage
Conclusion of Interface and Communication topics.
Initiation of Concurrency and Threads coverage.
Reading Materials: Textbook Chapters 3.1-3.3 and 4.1-4.2.