0% found this document useful (0 votes)
4 views9 pages

$RHIYKNM

The document provides an in-depth overview of the Linux operating system, focusing on its design principles, kernel modules, process management, and scheduling. Key features include a monolithic kernel architecture, modularity through loadable kernel modules, and efficient process management with a hierarchical structure. Additionally, it discusses memory management techniques such as virtual memory, paging, and various memory allocation mechanisms to optimize performance and security.

Uploaded by

lagimolala3095
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views9 pages

$RHIYKNM

The document provides an in-depth overview of the Linux operating system, focusing on its design principles, kernel modules, process management, and scheduling. Key features include a monolithic kernel architecture, modularity through loadable kernel modules, and efficient process management with a hierarchical structure. Additionally, it discusses memory management techniques such as virtual memory, paging, and various memory allocation mechanisms to optimize performance and security.

Uploaded by

lagimolala3095
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

1.

Explain in detail the design principles, kernel modules, process


management, and scheduling in the Linux system.
Design Principles of Linux
Linux is a Unix-like operating system built with several strong design
principles, including:
a. Monolithic Kernel Design
• Linux follows a monolithic kernel architecture, meaning the entire OS
runs in kernel space and is responsible for managing CPU, memory,
devices, file systems, etc.
• Unlike microkernel designs, the monolithic kernel offers faster
performance due to fewer context switches between kernel and user
space.
b. Portability
• Linux is written in C language with minimal architecture-specific code,
making it easily portable to different hardware platforms including x86,
ARM, and RISC-V.
c. Modularity
• Linux is highly modular with support for loadable kernel modules (LKMs),
allowing dynamic addition/removal of functionality without rebooting.
• This aids in maintainability and flexibility.
d. Multiuser and Multitasking
• Linux supports multiuser environments with permission-based file
access.
• True multitasking is supported, allowing concurrent process execution
with preemptive scheduling.
e. Security and Stability
• Incorporates user-level permissions, process isolation, and secure coding
practices.
• Features such as SELinux further enhance security.
Kernel Modules
A kernel module in Linux is a piece of code that can be loaded into the
kernel as needed and unloaded when it is no longer necessary. These
modules extend the functionality of the kernel without requiring a system
reboot or recompilation of the entire kernel.
Modules are used to add support for:
• Hardware devices (like USB drivers, file systems, network drivers)
• File systems
• System calls
• Network protocols
• Device drivers
This modular approach makes the Linux kernel highly flexible and adaptable
to various hardware and software environments.
Types of Kernel Modules
1. Device Drivers
o Used for controlling hardware devices like keyboards, mice,
storage devices.
o Example: usb-storage, snd-hda-intel for sound devices.
2. File System Modules
o Allow mounting and accessing new types of file systems.
o Example: ext4, ntfs, vfat.
3. Network Protocol Modules
o Provide support for networking stacks or protocols.
o Example: ipv6, bridge, tcp_diag.
4. Security Modules
o Enhance kernel security through mandatory access control.
o Example: SELinux (selinux), AppArmor.
5. Common Commands:
Command Description
lsmod Lists all currently loaded modules
modinfo Shows information about a module
insmod Installs a module manually
rmmod Removes a module manually
modprobe Installs/removes module with dependencies
depmod Creates a list of module dependencies
Process Management
The Linux Operating System is a multitasking, multi-user system that can run multiple
processes simultaneously. Efficient process management and scheduling are critical
components of the kernel, ensuring proper execution, resource sharing, responsiveness, and
overall system performance.
A process is an instance of a program in execution. It includes the program code, current
activity, and all resources allocated by the OS.

Process Management in Linux

a) Process States
Each process in Linux goes through different states:
1. Running – The process is currently executing instructions.
2. Ready – The process is ready to run but waiting for CPU allocation.
3. Blocked (Waiting) – The process is waiting for I/O or other resources.

4. Stopped – The process has been stopped, usually by a signal.


5. Zombie – The process has terminated, but its parent has not yet read its exit status.

b) Process Control Block (PCB)


The kernel maintains a PCB for each process. It stores:

• Process ID (PID)
• Parent Process ID (PPID)
• Process state
• CPU registers
• Program counter
• Memory management info
• Scheduling parameters
This structure helps the OS manage and schedule the processes efficiently.

c) Process Hierarchy
Processes in Linux are organized in a hierarchical structure, where each process is created by
a parent using the fork() system call. The root process is usually init or systemd, having PID 1.
• Use the command pstree to view the process tree.
• fork() – Creates a new process.
• exec() – Replaces the current process image with a new one.
• wait() – Parent waits for the child process to complete.

d) Process Creation and Termination


1. Creation – A process is created using fork(). This creates a copy of the parent.
2. Execution – After creation, exec() is called to load a new program into the child
process.
3. Termination – The process exits using exit(), and the parent collects the termination
status using wait().

e) Process Identifiers
Every process has a unique Process ID (PID). Linux also assigns:
• PGID – Process Group ID
• SID – Session ID

Scheduling in Linux
Scheduling is the strategy used by the kernel to decide which process runs next. The
scheduler ensures CPU time is shared among all processes fairly and efficiently.

a) Types of Scheduling
1. Preemptive Scheduling
o Processes can be interrupted in the middle of execution.
o Ensures responsiveness, especially in real-time applications.
2. Non-Preemptive Scheduling
o Once a process gets the CPU, it holds it until it finishes or blocks.
o Not used in modern Linux due to poor responsiveness.

b) Linux Scheduling Classes


Linux supports multiple scheduling classes:
• SCHED_OTHER (default) – Standard time-sharing scheduling.
• SCHED_FIFO – Real-time, first-in, first-out.

• SCHED_RR – Real-time, round-robin.


• SCHED_DEADLINE – Tasks scheduled based on deadlines.
Each process is associated with one of these classes using the sched_setscheduler() system
call.

c) Completely Fair Scheduler (CFS)


Since Linux 2.6.23, the Completely Fair Scheduler (CFS) is used for normal processes.

Key Features:
• Maintains a red-black tree of runnable processes.
• Each process gets a virtual runtime (vruntime) representing how much CPU time it
has received.
• The process with the smallest vruntime is selected next.
• Ensures fair distribution of CPU among all processes.

Working:
• Uses time slices based on process weight (priority).
• Higher-priority processes get more CPU time.
• Ensures fairness over long term, not immediate response.

d) Real-Time Scheduling
For time-critical applications, Linux provides:
• SCHED_FIFO – Static priority; runs until blocked or preempted.
• SCHED_RR – Like FIFO, but each process gets a fixed time slice.
• SCHED_DEADLINE – Tasks specify runtime, deadline, and period.
These are used in industrial control systems, embedded systems, etc.

2.Memory Management in the Linux System

Memory management in Linux is a fundamental component of the operating system


kernel. It is responsible for managing primary memory (RAM), ensuring optimal
performance, isolation, and security across all running processes. Linux uses a
combination of virtual memory, paging, and dynamic memory allocation to efficiently
manage system memory.

Linux supports multitasking, where multiple processes are run simultaneously. Each of
these processes needs memory to function. The kernel ensures:

• No process interferes with another's memory.


• Memory is allocated and deallocated efficiently.
• Idle memory is reused.

Virtual Memory and Address Spaces

Virtual memory is a core concept of modern operating systems, including Linux. It


provides an abstraction that gives each process the illusion of having its own large,
continuous block of memory, even if the actual physical memory is fragmented or
limited.
Key Features:

• Process Isolation: Each process gets its own private address space, enhancing
security and stability.
• Efficient RAM Usage: Allows only the necessary parts of a program to be loaded into
RAM.
• Swapping and Overcommit: Processes can use more memory than physically
available by using disk-based swap.
Address Space Layout (for a process):
• Text Segment: Stores executable code.
• Data Segment: Stores initialized global/static variables.
• BSS Segment: Stores uninitialized data.
• Heap: Grows upwards as memory is dynamically allocated.
• Stack: Grows downwards for function calls and local variables.

2. Paging and Page Table Management


Linux implements memory virtualization using paging. Physical memory is
divided into fixed-size pages (usually 4 KB), and virtual memory is mapped
to physical pages using page tables.
Types of Pages:
• Virtual Page: Logical unit in the process’s address space.
• Page Frame: Actual block of memory in RAM.
Multi-Level Page Table Structure (x86_64):
• PGD (Page Global Directory)
• PUD (Page Upper Directory)
• PMD (Page Middle Directory)
• PTE (Page Table Entry)
Each level further refines the mapping until it points to a specific frame in
physical memory.
Advantages of Paging:
• Avoids external fragmentation.
• Supports demand paging (load pages only when needed).
• Enables memory protection at the page level.

3. Memory Allocation Mechanisms


Linux uses specialized allocators for efficiently allocating and freeing
memory in both user space and kernel space.
a) Buddy System Allocator:
• Divides memory into blocks of size 2^n.
• When a block is freed, it merges with its buddy to form a larger block.
• Suitable for larger or contiguous allocations.
b) Slab Allocator:
• Used for objects of same size (e.g., task_struct, file descriptors).
• Memory is divided into caches and slabs.
• Reduces internal fragmentation and speeds up frequent allocations.
c) kmalloc() vs vmalloc():
• kmalloc() allocates physically contiguous memory (used in device
drivers).
• vmalloc() allocates virtually contiguous memory (used when large
allocations are needed).
These mechanisms ensure that the kernel can allocate memory with
minimum overhead and fragmentation.

4. Memory Zones and Swapping


Physical memory is divided into zones based on hardware constraints and
usage patterns:

Zone Description

ZONE_DMA Used for Direct Memory Access devices (legacy).

ZONE_NORMAL Used for kernel and normal user memory.

ZONE_HIGHMEM Used in 32-bit systems for user process memory.

Swapping:
When RAM is insufficient, Linux moves inactive pages to a special disk area
called swap space.
• Swap File/Partition: Acts as an extension of RAM.
• Swapping Process: The kernel identifies least-used memory pages and
writes them to swap.

You might also like