Osd Unit 1
Osd Unit 1
UNIT 1
1. Process Management:
o Scheduler:
▪ The Scheduler is a crucial component responsible for
determining which process should run and for how long.
▪ It maintains a queue of processes and decides which one gets
access to the CPU.
o Process Control Block (PCB):
▪ The PCB contains information about a process, including its
state, program counter, registers, and other context-switching
information.
▪ Linux uses the task_struct structure to represent the PCB.
o System Calls:
▪ Processes interact with the kernel through system calls.
▪ The kernel provides various system calls for process-related
operations like fork (creating a new process), exec (loading a
new program), and exit (terminating a process).
2. Memory Management:
o Virtual Memory:
3
UNIT 1
.
4
UNIT 1
1. Interrupt Sources:
o Hardware Devices:
▪ Interrupts can be triggered by various hardware devices such as
I/O devices, timers, or external interrupts.
2. Interrupt Controller:
o External Hardware Interrupt Controller:
▪ Many systems use external interrupt controllers (e.g., PIC -
Programmable Interrupt Controller or APIC - Advanced
Programmable Interrupt Controller) to manage interrupt lines
from multiple devices.
▪ The interrupt controller receives interrupt signals from devices
and forwards them to the CPU.
3. CPU and Kernel Interaction:
o Interrupt Descriptor Table (IDT):
▪ The Linux kernel maintains an Interrupt Descriptor Table,
which is a data structure that contains entries for various
interrupt vectors.
▪ Each entry in the IDT points to an interrupt service routine
(ISR) or a handler.
o Interrupt Service Routine (ISR):
▪ When an interrupt occurs, the CPU stops its current execution
and transfers control to the corresponding ISR.
▪ The ISR is a function written in kernel space to handle the
specific interrupt.
o Softirqs and Tasklets:
▪ Some interrupts are deferred and handled later by softirqs or
tasklets. These mechanisms allow interrupt handling to be
deferred to a more suitable time in the kernel's execution
context.
4. Interrupt Handling Process:
o Interrupt Occurs:
▪ A hardware device triggers an interrupt, causing the CPU to
stop its current execution.
o IDT Lookup:
5
UNIT 1
1. Process Descriptor:
o The process descriptor in Linux is represented by the task_struct
structure.
o It serves as a data structure to store essential information about a
process.
o The primary purpose of the process descriptor includes:
▪ Identification:
▪ The process descriptor uniquely identifies each process in
the system.
▪ It contains information such as the process ID (PID),
parent process ID (PPID), and other identification details.
▪ State Information:
6
UNIT 1
▪ Scheduling:
▪ Contains fields related to scheduling, such as priority,
policy, and runtime information.
▪ Helps the scheduler make decisions regarding process
execution.
▪ File System Information:
▪ Manages file-related information, including file
descriptors, file locks, and filesystem-related context.
▪ Enables the process to interact with the filesystem.
▪ Memory Management:
▪ Stores information about the process's address space,
memory mappings, and page tables.
▪ Essential for managing memory resources and virtual-to-
physical address translations.
▪ Signal Handling:
▪ Maintains data structures for handling signals, including
signal handlers, signal masks, and pending signals.
▪ Enables the process to respond to asynchronous events.
▪ Security:
▪ Includes security-related information, such as credentials
and capabilities, to enforce access controls and
permissions.
1. Context Switch:
o Definition:
▪ A context switch is the process of saving and restoring the state
of a CPU or process so that execution can be resumed from the
same point later.
o Explanation:
▪ In a multitasking environment, multiple processes or threads
share the CPU. When the operating system decides to switch
from executing one process to another, it performs a context
switch.
▪ The operating system saves the current context (registers,
program counter, etc.) of the running process and restores the
saved context of the next process to be executed.
▪ Context switches are essential for multitasking and allow the
illusion of simultaneous execution of multiple processes.
2. Task Interruptible:
o Definition:
▪ In the context of an operating system, a task is said to be
interruptible if it can be stopped or paused during its execution
in response to an external event, typically an interrupt or a
signal.
o Explanation:
▪ When a task is interruptible, it can yield the CPU voluntarily or
in response to signals (e.g., SIGSTOP or SIGTERM).
▪ The task is cooperative and allows the operating system to
perform a context switch, switching to another task that needs
to run.
▪ Interruptible tasks are generally more responsive to external
events or signals.
3. Uninterruptible:
o Definition:
▪ An uninterruptible task or process is one that cannot be stopped
or paused in response to external events, such as signals or
interrupts, until it completes a specific operation.
o Explanation:
10
UNIT 1
1. Open Source:
• Linux:
o The Linux kernel is open source, and the entire operating system is
built on the principles of free and open-source software (FOSS).
o The source code is freely available, allowing users to view, modify,
and distribute their versions of the kernel.
• Unix:
o Traditional Unix systems often come with proprietary
implementations, and the source code is not always open for public
modification.
o Some Unix-like operating systems, like the various BSD (Berkeley
Software Distribution) versions, are open source, similar to Linux.
2. Development Model:
• Linux:
o Developed using a collaborative and distributed development model
with contributions from a large community of developers worldwide.
o Frequent updates and releases, allowing for rapid integration of new
features and bug fixes.
11
UNIT 1
• Unix:
o Development models can vary; some Unix systems are developed in a
closed, centralized manner, while others, like FreeBSD or OpenBSD,
follow open-source collaborative models.
3. Portability:
• Linux:
o Linux has been successfully ported to a wide range of architectures
and platforms, making it highly portable.
o Supported on various hardware, including x86, ARM, MIPS,
PowerPC, and more.
• Unix:
o Traditional Unix implementations may be less portable across
different architectures compared to Linux.
o Some Unix-like systems, especially the BSD variants, have good
portability across different hardware platforms.
4. Filesystem Support:
• Linux:
o Supports a variety of filesystems, including ext4, Btrfs, XFS, and
more.
o Native support for a wide range of filesystem features.
• Unix:
o Traditionally supports filesystems like UFS (Unix File System) or
variations like ZFS (in some cases).
o Filesystem support may vary between different Unix-like systems.
5. Device Drivers:
• Linux:
o Boasts a large number of built-in device drivers, and the kernel
community actively maintains and adds support for new hardware.
o Features a modular architecture allowing the loading and unloading of
device drivers dynamically.
• Unix:
o Device driver support can vary between different Unix
implementations.
o May have a more monolithic approach to device driver inclusion.
12
UNIT 1
1. Fragmentation:
o The open-source nature of Linux has led to the existence of numerous
distributions, contributing to some fragmentation in terms of package
management and system administration tools.
2. Compatibility Challenges:
o Some proprietary Unix applications may not run seamlessly on Linux,
leading to compatibility challenges in certain enterprise environments.
3. Vendor Support:
o In certain enterprise settings, Unix systems from established vendors
may have better vendor support than Linux for specific applications.
Definition of a Process:
multitasking operating system like Linux, multiple processes run concurrently, and
the operating system manages the execution of these processes.
In Linux, a process can exist in various states, and the transitions between these
states are managed by the operating system scheduler. The common process states
include:
1. Running:
o The process is currently being executed by the CPU.
2. Ready:
o The process is ready to run but is waiting for the CPU to be assigned
to it.
3. Blocked (or Waiting):
o The process is waiting for an event or a resource to become available.
The transitions between process states are managed through system calls and
events triggered during the execution of the process. Relevant system calls and
events include:
1. Creation:
o The process is created using the fork() or exec() system calls.
o fork() creates a new process, and exec() replaces the current
process with a new one.
2. Ready to Running:
o The scheduler assigns the CPU to a ready process.
o No specific system call is directly responsible for this transition, as it
is managed by the scheduler.
3. Running to Blocked:
o The process can transition from the running state to the blocked state
if it performs I/O operations or waits for a resource.
o System calls like read(), write(), or sleep() may result in the
process entering the blocked state.
4. Blocked to Ready:
o An event or resource becomes available, allowing a blocked process
to move back to the ready state.
o Interrupts or signals can trigger this transition.
14
UNIT 1
5. Running to Ready:
o The scheduler may decide to preempt the currently running process
and move it back to the ready state, allowing another process to run.
o This is managed by the scheduler and doesn't involve a specific
system call.
6. Termination:
o The process may terminate voluntarily using the exit() system call.
o The exit() system call releases resources and signals the end of the
process.
Note:
• The wait() system call is often used by a parent process to wait for the
termination of its child process.
• Signals, such as kill(), can be used to interrupt or terminate a process.
Diagram Representation:
sql
+------------+ +------------+ +----------
--+
| Running | -----> | Blocked | -----> | Ready
|
+------------+ +------------+ +----------
--^
| |
| |
+-------------------------------------------+
|
v
+------------+
| Terminated |
+------------+
In the diagram:
• The diagram illustrates the possible transitions a process can undergo during
its lifecycle in a Linux-based operating system.
When a fork is executed, the child process is created as a copy of the parent
process. Here are some key characteristics and the work done by the fork system
call:
1. Parent-Child Relationship:
o After the fork, both the parent and the child processes continue their
execution independently.
o The child process is a copy of the parent process at the time of the
fork.
2. Memory Copy:
o The address space of the parent process, including variables, code,
and data, is duplicated for the child process. This is done using a
copy-on-write mechanism.
o Initially, the child and parent processes share the same memory pages.
If either process modifies a shared page, a copy is made, and the
modification is applied to the copy, ensuring that each process has its
own copy of modified data.
3. File Descriptors:
o File descriptors, which represent open files or communication
channels, are shared between the parent and child processes after the
fork.
o This sharing allows the parent and child to communicate through files
or pipes.
4. Process IDs:
o The child process is assigned a new unique process ID (PID), distinct
from the parent's PID.
o The parent retains its original PID.
5. Return Values:
o In the parent process, the fork system call returns the child's PID.
16
UNIT 1
c
#include <stdio.h>
#include <unistd.h>
int main() {
pid_t childPid;
if (childPid == 0) {
// Code executed by the child process
printf("Child Process\n");
} else if (childPid > 0) {
// Code executed by the parent process
printf("Parent Process\n");
} else {
// Forking failed
fprintf(stderr, "Fork failed\n");
return 1;
}
return 0;
}
.
17
UNIT 1
• Kernel Space:
o Definition: Kernel space refers to the privileged mode of the
operating system where the kernel executes. It has direct access to the
hardware and performs critical tasks like managing system resources
and handling hardware communication.
o Privileges: Code running in kernel space has elevated privileges and
can perform operations that are restricted in user space.
o Examples: Device drivers, kernel modules, and core operating system
functions reside in kernel space.
• User Space:
o Definition: User space is where user applications and tasks run. It is a
restricted mode without direct access to hardware resources. User
space processes rely on system calls to request services from the
kernel.
o Privileges: Code running in user space has limited privileges and
cannot perform certain operations directly.
o Examples: Applications, utilities, and user-level programs reside in
user space.
• Boundary: The boundary between kernel space and user space is enforced
by the hardware and the operating system. System calls act as a bridge
between these two spaces, allowing user space programs to request services
from the kernel.
• Function Call:
o Definition: A function call refers to the execution of a specific
sequence of code within a program. It involves transferring control to
a function, executing the function's code, and returning control to the
calling code.
o Context: Function calls are part of the normal flow of execution
within a program and typically involve operations within the same
address space.
18
UNIT 1
Completion/Future:
If you were referring to a specific term used in a particular context, please provide
more details or clarify, and I'll do my best to assist you.
ChatGPT
Let me clarify:
1. Linux Kernel:
o Advantages:
▪ Open Source and Community-Driven: The Linux kernel is
open-source, allowing users to view, modify, and distribute the
source code. This fosters a large and active community of
developers contributing to its development.
▪ Portability: Linux supports a wide range of hardware
architectures, making it highly portable across different
systems.
▪ Modularity: The Linux kernel is modular, allowing the loading
and unloading of kernel modules dynamically.
▪ Frequent Updates: Linux receives frequent updates, providing
users with the latest features, security patches, and
improvements.
o Disadvantages:
▪ Fragmentation: The open-source nature of Linux has led to the
existence of numerous distributions, contributing to some
fragmentation in terms of package management and system
administration tools.
▪ Compatibility Challenges: Some proprietary Unix
applications may not run seamlessly on Linux, leading to
compatibility challenges in certain enterprise environments.
▪ Vendor Support: In certain enterprise settings, Unix systems
from established vendors may have better vendor support than
Linux for specific applications.
2. Unix Kernel:
o Advantages:
▪ Stability: Traditional Unix systems are known for their
stability and reliability, which makes them suitable for critical
enterprise environments.
20
UNIT 1
In summary, Linux and Unix are both families of operating systems, and the Linux
kernel is a specific open-source kernel within the Unix-like family. The choice
between Linux and a specific Unix variant depends on factors such as the specific
requirements of the environment, hardware support, and vendor preferences.
1. New:
o The process is being created.
2. Ready:
o The process is ready to run but is waiting for the CPU to be assigned
to it.
3. Running:
o The process is currently being executed by the CPU.
4. Blocked (Waiting):
o The process is waiting for an event or a resource to become available.
5. Terminated:
o The process has finished its execution.
21
UNIT 1
plaintext
+--------------+
| New |
+------+-------+
|
v
+--------------+
| Ready |
+------+-------+
|
v
+--------------+
| Running |
+------+-------+
|
v
+--------------+
| Blocked |
+------+-------+
|
v
+--------------+
| Terminated |
+--------------+
.
22
UNIT 1
1. System Context:
o The system context refers to the overall state and information
associated with the execution of a process within the operating
system.
o It includes various aspects such as process-specific data, kernel data
structures, and information needed by the operating system to manage
the process.
o Elements of the system context include the process control block
(PCB), which contains information about the process, such as process
ID (PID), registers, program counter, scheduling information, and
more.
o The system context allows the operating system to manage and
control the execution of processes effectively.
2. Address Context:
o The address context pertains to the memory-related information
associated with a process.
o It includes details about the virtual memory space of the process,
including code, data, stack, and heap segments.
o The address context also involves information about memory
mappings, page tables, and the virtual-to-physical address translation.
o Changes in the address context are essential for proper memory
management and isolation between processes.
3. Hardware Context:
o The hardware context is related to the state of the processor and other
hardware-specific information associated with a process.
o It includes the contents of the processor registers, the program
counter, the stack pointer, and other CPU-specific information.
o Switching the hardware context is a crucial aspect of context
switching, where the operating system transitions from executing one
process to another.
o The hardware context reflects the state of the CPU and is
saved/restored during context switches to maintain the execution state
of different processes.
Context Switching:
23
UNIT 1
Importance:
• Understanding and managing these context components are essential for the
efficient execution and multitasking capabilities of an operating system.
• They enable the operating system to switch between processes, allocate
resources, and maintain isolation among concurrent task
plaintext
/linux
|-- arch # Architecture-specific code (e.g.,
x86, ARM, MIPS)
|-- block # Block I/O layer
|-- certs # Certificate files for signing
kernel modules
|-- crypto # Cryptographic algorithms and
modules
|-- Documentation # Kernel documentation
|-- drivers # Device drivers
| |-- block # Block device drivers
| |-- char # Character device drivers
| |-- gpu # Graphics Processing Unit drivers
| |-- net # Network device drivers
| |-- usb # USB device drivers
| |-- ...
|-- firmware # Firmware files used by some drivers
|-- fs # Filesystem code
24
UNIT 1