OS Unit I
OS Unit I
• System view:
Resource allocator/Manager
Computer system Architecture
• Single processor systems
• Multiprocessor system
(parallel/tightely coupled systems)
Types of Multiprocessor Systems:
(i). Asymmetric multiprocessing system
(ii). Symmetric multiprocessing system
Advantages of multiprocessor system
• Increased throughput
• Economy of scale
• Increased reliability
TYPES OF OPERATING SYSTEM
Preemptive Multitasking
• Definition: In preemptive multitasking, the operating
system has full control over the CPU and can preempt or
interrupt tasks to allocate CPU time to another task. This
ensures fair CPU allocation and better responsiveness.
• How It Works:
– The OS uses a scheduling algorithm (e.g., round-robin, priority
scheduling).
– Tasks are assigned fixed time slices (or quanta).
– If a task exceeds its time slice, the OS forcibly pauses it and
switches to another task.
Distributed OS
Distributed OS is designed for networked
computing environments where multiple
computers are interconnected.
These systems manage resources across
multiple machines, allowing users to access
files and services from different locations.
Distributed OS
• The Distributed OS is separated into sections
and loaded on different machines rather than
placed on a single machine.
• Each machine has a piece of the distributed
OS installed to allow them to communicate.
Distributed Operating System
• Process Management
• I/O Device Management
• File Management
• Network Management
• Main Memory Management
• Secondary Storage Management
• Security Management
Process Management
• The operating system is primarily responsible for all task and activities
happen in the computer system. The various processes in an operating
system must be protected from each other’s activities.
• Security Management refers to a mechanism for controlling the access of
programs, processes, or users to the resources defined by a computer
controls to be imposed, together with some means of enforcement.
Operating System services
User services
1.Program execution
2.User interface
CLI-textbased commands-DOS Os
GUI-widgets,folders,visibility-Windows,linus,Macos
3.I/O operations
Keyboard,mouse,minitor have controllers
These controllers are managed by OS
4.Communication
IPC
5.File system manipulation
create,store,delete,retieve,search the files
6.Error detection
program,hardware-will be reported to the user or debug by itself(OS)
Operating System services
System services
Resource allocation
Multiple jobs,Multiple users
Accounting
keeptrack of which user use how much and what kind
of resources
Protection and security
Acess conrtol and Authentication
Process in a Main memory
When a program is loaded into memory, it may be divided into the four
components stack, heap, text, and data to form a process. The simplified
depiction of a process in the main memory is shown in the diagram below.
1.Stack
The process Stack contains the temporary
data such as method/function parameters,
return address and local variables.
2.Heap
This is dynamically allocated memory to a
process during its run time.
3.Text
It holds Machine code or instructions
executed by the CPU.
4.Data
This section contains the global and static
variables.
Memory Layout of a C Program
Process States
When a process executed, it changes the state, generally
the state of process is determined by the current activity of
the process.
Each process may be in one of the following states:
Thread States:
1. Born State : A thread is just created.
2. ready state : The thread is waiting for CPU.
3. running : System assigns the processor to the thread.
4. sleep : A sleeping thread becomes ready after the designated sleep
time expires.
5. dead : The Execution of the thread finished.
Eg: Word processor. Typing, Formatting, Spell check, saving are threads.
Multithreading
• A process is divided into number of smaller tasks each task is called a Thread.
Number of Threads with in a Process execute at a time is called Multithreading.
• If a program, is multithreaded, even when some portion of it is blocked, the whole
program is not blocked.
• The rest of the program continues working If multiple CPU’s are available
Types of threads
User Threads : Thread creation, scheduling, management happen in user space by
Thread Library. user threads are faster to create and manage.
If one thread in a process blocked remaining threads in same process also gets
blocked
Operating System Concepts – 10th Edition 3.82 Silberschatz, Galvin and Gagne ©2018
IPC – Message Passing
Operating System Concepts – 10th Edition 3.83 Silberschatz, Galvin and Gagne ©2018
Direct Communication
Processes must name each other explicitly:
• send (P, message) – send a message to process P
• receive(Q, message) – receive a message from process Q
Properties of communication link
• Links are established automatically
• A link is associated with exactly one pair of communicating
processes
• Between each pair there exists exactly one link
• The link may be unidirectional, but is usually bi-directional
Operating System Concepts – 10th Edition 3.84 Silberschatz, Galvin and Gagne ©2018
Indirect Communication
Messages are directed and received from mailboxes (also referred
to as ports)
• Each mailbox has a unique id
• Processes can communicate only if they share a mailbox
Properties of communication link
• Link established only if processes share a common mailbox
• A link may be associated with many processes
• Each pair of processes may share several communication links
• Link may be unidirectional or bi-directional
Operating System Concepts – 10th Edition 3.85 Silberschatz, Galvin and Gagne ©2018
Indirect Communication (Cont.)
Operations
• Create a new mailbox (port)
• Send and receive messages through mailbox
• Delete a mailbox
Primitives are defined as:
• send(A, message) – send a message to mailbox A
• receive(A, message) – receive a message from mailbox A
Operating System Concepts – 10th Edition 3.86 Silberschatz, Galvin and Gagne ©2018
System calls for Process management
return 0;
}
exit() system call
The exit system call in Unix/Linux is used to terminate a process.
When a process calls exit, it releases resources allocated to it and sends an
exit status code to its parent process.
Example
#include <stdio.h>
#include <stdlib.h> // Required for the exit() function
int main()
{
printf("Program started.\n");
int error_occurred = 1;
if (error_occurred)
{
printf("Error occurred! Exiting with status 1.\n");
exit(1); // Exit with a non-zero status indicating an error
}