KEMBAR78
Os Notes | PDF | Operating System | Process (Computing)
0% found this document useful (0 votes)
4 views27 pages

Os Notes

An Operating System (OS) is software that acts as an intermediary between computer hardware and users, managing resources and providing services. Key functions include process management, memory management, file system management, and user interface. The document also covers the history of OS development, types of OS, process management concepts, and memory management techniques.

Uploaded by

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

Os Notes

An Operating System (OS) is software that acts as an intermediary between computer hardware and users, managing resources and providing services. Key functions include process management, memory management, file system management, and user interface. The document also covers the history of OS development, types of OS, process management concepts, and memory management techniques.

Uploaded by

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

OPERATING SYSTEM

UNIT-I

what is an Operating System (OS)?

An Operating System (OS) is a software program that acts as an intermediary between


computer hardware and the computer user. It manages hardware resources, provides common
services for computer programs, and ensures the efficient execution of tasks.

Main Functions of an OS:

1. Process Management: Handles the execution of processes, including scheduling,


creation, and termination of processes.
2. Memory Management: Controls and coordinates computer memory, ensuring that
each program gets the appropriate amount of memory.
3. File System Management: Organizes, stores, retrieves, and manages files on storage
devices.
4. Device Management: Manages input/output devices, such as printers, disk drives,
and network interfaces.
5. Security & Access Control: Protects the system and data from unauthorized access
and ensures safe execution of tasks.
6. User Interface: Provides a way for users to interact with the system, either through a
command-line interface (CLI) or graphical user interface (GUI).

History of Operating Systems

1. Pre-OS Era (1940s-1950s):


o Early computers were operated manually, and users had to interact directly
with hardware. Programming was done through machine language or
assembly.
o The idea of an OS was not prevalent, and each program ran in isolation,
requiring direct hardware access.
2. First Generation (1950s):
o Machines were vacuum-tube-based, and early batch processing systems were
developed. The user would submit a job (e.g., computation), and the OS would
handle its execution in batches.
o Notable OS: UNIVAC I (Universal Automatic Computer) and early batch
systems.
3. Second Generation (1960s):
o The rise of transistor-based computers led to more sophisticated systems.
Time-sharing began, allowing multiple users to access the computer
simultaneously.
o Multics and CTSS (Compatible Time-Sharing System) were developed,
allowing for better process management and multi-user access.
4. Third Generation (1970s):
o The development of UNIX by AT&T Bell Labs marked a major milestone.
UNIX introduced many concepts, like hierarchical file systems and
multitasking.
o This period also saw the development of minicomputers and mainframe
systems that provided more power and better resource utilization.
5. Fourth Generation (1980s-Present):
o The rise of personal computers (PCs) and microprocessors led to the
development of operating systems like MS-DOS (Microsoft Disk Operating
System) and Windows.
o Graphical User Interfaces (GUIs) became standard with systems like Mac
OS and Windows, replacing command-line interfaces.
o Linux, an open-source OS, became widely used, particularly for servers and
development environments.
6. Current Trends:
o The development of mobile operating systems like iOS and Android
revolutionized computing.
o Cloud computing, virtualization, and IoT (Internet of Things) are
influencing modern operating systems.

Computer Hardware Overview

Computer hardware refers to the physical components that make up a computer system.
These components interact with the OS to perform tasks and execute programs.

Major Components:

1. Central Processing Unit (CPU):


o The "brain" of the computer, responsible for executing instructions from
programs.
o Control Unit (CU): Directs the operation of the processor.
o Arithmetic Logic Unit (ALU): Handles mathematical and logical operations.
2. Memory:
o Primary Memory (RAM): Volatile memory used by the CPU for fast access
to data and instructions.
o Secondary Memory: Non-volatile memory used for long-term storage (e.g.,
hard drives, SSDs).
3. Input Devices:
o Devices used to provide data to the computer (e.g., keyboard, mouse, scanner).
4. Output Devices:
o Devices used to display or output data from the computer (e.g., monitors,
printers, speakers).
5. Storage Devices:
o Hard Disk Drive (HDD), Solid State Drive (SSD), and optical drives used
for persistent data storage.
6. Motherboard:
o The main circuit board that connects all hardware components, including the
CPU, memory, and input/output devices.
7. Power Supply:
o Provides the necessary electrical power to the system components.
8. Bus:
o A communication system that transfers data between the CPU, memory, and
peripherals.

1. Operating Systems (OS):

An Operating System (OS) is system software that manages hardware and software
resources and provides common services for computer programs. The OS serves as an
intermediary between users and the computer hardware, providing a user interface and
managing resources such as CPU, memory, and devices.

2. Key Concepts in Operating Systems:

 Process Management: The OS manages processes (running programs) using


mechanisms like multitasking, process scheduling, and inter-process communication.
 Memory Management: Manages system memory (RAM), ensuring processes have
the memory they need and preventing issues like memory leaks or overflows.
 File System Management: The OS handles data storage, organization, retrieval, and
security. File systems determine how data is stored and accessed on disks.
 Device Management: Manages hardware devices through device drivers, ensuring
proper communication between the system and hardware (e.g., printers, hard drives).
 Security and Access Control: Protects the system from unauthorized access,
malicious activities, and ensures data privacy and integrity.
 User Interface: Provides a way for users to interact with the system, either through a
graphical user interface (GUI) or command-line interface (CLI).

3. Types of Operating Systems:

 Batch OS: Executes jobs in a batch without user interaction (e.g., early mainframe
systems).
 Time-Sharing OS: Allocates CPU time to different processes in a way that gives
users the illusion of simultaneous execution (e.g., UNIX, Linux).
 Distributed OS: Manages a collection of independent computers and makes them
appear as a single system (e.g., Google’s Android OS).
 Embedded OS: Designed to run on embedded systems with specific functions, such
as in smartphones or smart TVs.
 Real-Time OS: Used when timely execution is critical, often in systems like
industrial machines, medical devices, or robotics (e.g., QNX).

4. System Calls:

System calls provide an interface between user programs and the operating system kernel.
They are used for services such as input/output, memory allocation, process creation, and file
management. Examples include:

 File management: open(), read(), write(), close().


 Process management: fork(), exec(), wait(), exit().
 Memory management: malloc(), free(), brk().
 Device management: ioctl(), read(), write().
5. Operating System Structure:

Different operating systems have different internal architectures. Common structures include:

 Monolithic Kernel: A single large kernel that directly interacts with hardware and
provides core services like process management, memory management, file systems,
etc. (e.g., Linux).
 Microkernel: A minimal kernel that only handles basic functions like
communication, with additional services (e.g., file management) provided by user-
level processes. (e.g., Minix, QNX).
 Layered System: The OS is divided into layers, each responsible for specific tasks.
Lower layers handle basic hardware interactions, while upper layers provide user-
facing functionality.
 Modular Structure: The OS is divided into modules that can be loaded or unloaded
dynamically. This allows the OS to be flexible and extensible (e.g., modern Linux
systems).

6. Important OS Concepts:

 Multitasking: The OS allows multiple processes to run concurrently by rapidly


switching between them.
 Context Switching: The process of saving and loading the state of processes when
switching between them.
 Deadlock: A situation where two or more processes are waiting for each other to
release resources, resulting in a standstill.
 Synchronization: Mechanisms to ensure that processes don’t interfere with each
other, such as mutexes or semaphores.
 Virtual Memory: A system that gives the illusion of a larger amount of memory than
is physically available, using disk space to extend RAM.

7. Common Operating Systems:

 Windows: A popular OS with a GUI, used in personal computing and enterprise


environments.
 Linux: An open-source, Unix-like OS used widely in servers, desktops, and
embedded systems.
 macOS: Apple's proprietary operating system for Mac computers.
 Unix: A powerful, multi-user OS commonly used in academic and enterprise
environments.
 Android/iOS: Mobile operating systems based on Linux (Android) and Unix (iOS).

1. What is a Process?

 A process is a program in execution, which consists of the program code, data, and
the state of the program (e.g., program counter, registers).
 Each process has its own memory space, execution context, and system resources.

2. Process States:

 A process can be in one of the following states:


o New: The process is being created.
o Ready: The process is ready to run, but the CPU is not available.
o Running: The process is currently being executed on the CPU.
o Waiting (Blocked): The process is waiting for some event or resource (e.g.,
I/O completion).
o Terminated: The process has finished execution.

3. Process Control Block (PCB):

 The PCB stores all the information about a process. It includes:


o Process ID (PID)
o Process state
o Program counter
o CPU registers
o Memory management information
o I/O status information
o Accounting information

4. Process Scheduling:

 Process scheduling refers to the method by which the operating system decides
which process will run next.
 Key scheduling algorithms:
o First-Come-First-Served (FCFS)
o Shortest Job Next (SJN)
o Round Robin (RR)
o Priority Scheduling

5. Process Creation:

 A new process is created using the fork() system call in Unix-like systems or similar
calls in other OSs.
 The parent process creates a child process.
 The child process can be an exact copy of the parent (via exec()) or run a different
program.

6. Inter-Process Communication (IPC):

 Processes often need to communicate with each other. IPC mechanisms include:
o Shared Memory: Multiple processes can access a common memory region.
o Message Passing: Processes send and receive messages via communication
channels.
o Pipes and Sockets: Used for communication between processes in
Unix/Linux.

7. Context Switching:

 Context switching is the process of saving and restoring the state (context) of a
process when switching from one process to another.
 It involves saving the PCB of the currently running process and loading the PCB of
the next process to be executed.

8. Threads and Multi-threading:

 A thread is the smallest unit of CPU execution within a process.


 Multithreading allows multiple threads to run concurrently within a single process,
enabling more efficient use of CPU resources.

9. Synchronization:

 When multiple processes or threads access shared resources concurrently,


synchronization mechanisms are needed to prevent data corruption or inconsistencies.
o Common synchronization mechanisms include:
 Mutexes (Mutual Exclusion Locks)
 Semaphores
 Monitors
 Condition Variables

10. Process Termination:

 A process terminates when its execution is complete or an error occurs.


 Upon termination, the OS reclaims all the resources (memory, file descriptors)
associated with the process.

1. Processes:

 A process is an instance of a program that is being executed. It contains the program


code, current activity, and necessary resources (memory, I/O devices).
 Each process has its own address space and process control block (PCB), which
stores the process's state, program counter, CPU registers, and other vital information.

Key characteristics of a process:

 Isolation: Processes are independent of each other.


 Concurrency: Multiple processes can run simultaneously.
 Resource management: Processes require various resources like CPU time, memory,
I/O devices, etc.

2. Threads:

 A thread is the smallest unit of execution within a process. A process can contain
multiple threads, all sharing the same memory space but executing independently.
 Threads are sometimes referred to as "lightweight processes" because they share
resources within the process but can still execute concurrently.

Key characteristics of threads:

 Shared Resources: Threads within the same process share resources like memory,
file handles, and I/O devices.
 Concurrency: Multiple threads can run within the same process.
 Faster Context Switching: Switching between threads is generally faster than
switching between processes because threads share memory.

3. Interprocess Communication (IPC):

 IPC refers to the mechanisms that allow processes to communicate with each other.
Since processes are isolated, they need to use special methods to exchange data or
coordinate actions.

Common IPC mechanisms:

 Pipes: Unidirectional communication channels that allow data transfer between


processes.
 Message Queues: Queues for messages that allow processes to send and receive data.
 Shared Memory: Allows multiple processes to access a common memory region.
 Semaphores: Used for signaling between processes to manage resource access.
 Sockets: Provide communication between processes on different machines (often
used in network communication).
 Signals: Simple notification mechanisms to alert a process of an event.

4. Scheduling:

 Process Scheduling refers to the technique that the operating system uses to manage
the execution of processes on the CPU. Scheduling algorithms determine the order in
which processes are given CPU time.

Common scheduling algorithms:

 First-Come, First-Served (FCFS): Processes are scheduled in the order they arrive.
 Shortest Job Next (SJN): The process with the smallest execution time is scheduled
next.
 Round Robin (RR): Each process is given a fixed time slice, and then the next
process is scheduled.
 Priority Scheduling: Processes are assigned priorities, and the highest-priority
process is scheduled first.

5. IPC Problems:

 Race Conditions: Occur when multiple processes or threads access shared resources
concurrently and at least one of them modifies the resource. This can lead to
unpredictable results.

Solutions to Race Conditions:

 Locks: Ensure that only one process/thread accesses a shared resource at a time.
 Semaphores: Use semaphores to control access to shared resources and prevent race
conditions.
 Deadlock: A situation where two or more processes are blocked forever because they
are waiting for each other to release resources.
Deadlock Prevention/Resolution Strategies:

 Deadlock Prevention: Alter the scheduling to avoid deadlock situations.


 Deadlock Detection and Recovery: Periodically check for deadlock and take actions
(e.g., terminating processes) to recover.
 Starvation: Occurs when a process is perpetually denied access to resources because
other processes are constantly being given priority.

Solutions to Starvation:

 Aging: Gradually increase the priority of a process that has been waiting too long,
ensuring that it eventually gets CPU time.

UNIT-II

Memory management refers to the process of managing computer memory resources to


optimize the performance of programs and processes. When there's "no memory abstraction,"
it typically refers to a scenario where the system directly manages memory, without higher-
level abstractions (like virtual memory or memory paging) to separate processes and manage
memory allocation.

Here are some key points to consider for memory management without abstraction:

1. Direct Addressing: In systems with no memory abstraction, each process is aware of


the specific locations in memory where data is stored. There is no isolation between
processes, and memory addresses are handled explicitly by the programmer or
system.
2. Fixed Memory Allocation: Memory allocation is typically done statically, where the
system reserves a specific amount of memory for each process at compile time. The
memory is fixed, and processes cannot dynamically adjust their memory requirements
while running.
3. No Virtual Memory: Without memory abstraction, processes don’t have the illusion
of having their own private memory space. They are limited to the physical memory
available, and there's no swapping between RAM and disk (no paging or
segmentation).
4. Manual Memory Management: In the absence of abstraction, the programmer must
manually manage memory allocation and deallocation. This means explicitly
allocating and freeing memory using low-level functions or instructions.
5. Memory Fragmentation: Over time, memory can become fragmented as processes
allocate and free memory in various sizes. Without memory abstraction techniques
like paging, it becomes harder to manage this fragmentation effectively.
6. No Protection: There's no protection between processes, which means one process
could overwrite the memory of another process, potentially causing crashes or data
corruption.
7. Simplicity vs. Efficiency: Without the overhead of abstraction, systems can be more
straightforward and have less runtime overhead. However, this often comes at the cost
of flexibility, scalability, and safety.
8. Control and Optimization: Systems with no memory abstraction give programmers
direct control over memory, which can lead to highly optimized performance in
environments like embedded systems where resources are limited and fine-grained
control is required.

1. Address Spaces:

 Address Space refers to the range of addresses that a process can use to access
memory.
 Logical Address Space: The set of addresses generated by the CPU during a
program’s execution.
 Physical Address Space: The set of addresses in the physical memory (RAM).
 The OS maps logical addresses to physical addresses using hardware and software
mechanisms.

2. Virtual Memory:

 Virtual memory allows processes to use a larger address space than is physically
available by swapping data between RAM and disk storage.
 It enables programs to use more memory than the system can physically provide,
improving efficiency and flexibility.
 Key Components:
o Page Table: Maps virtual pages to physical frames.
o Page Fault: Occurs when a program accesses a part of memory that is not
currently in physical memory (requires fetching from disk).
o Segmentation: Divides memory into segments (e.g., code, data, stack) for
more efficient access.

3. Page Replacement Algorithms:

These algorithms manage which pages should be swapped out when a page fault occurs,
aiming to optimize memory usage and minimize the number of page faults.

 First-In, First-Out (FIFO): Replaces the oldest page in memory.


 Least Recently Used (LRU): Replaces the page that hasn’t been used for the longest
time.
 Optimal Page Replacement: Replaces the page that won’t be used for the longest
time in the future (ideal but impractical).
 Clock Algorithm: A more efficient approximation of LRU using a circular list.

4. Design Issues for Paging Systems:

 Page Size: Small page sizes result in higher page table sizes, while larger pages can
waste memory due to internal fragmentation.
 Page Table Management: Efficient handling of page tables is crucial for system
performance. Multi-level page tables or inverted page tables are used to manage large
address spaces.
 TLB (Translation Lookaside Buffer): A cache for frequently accessed page table
entries to reduce the time spent on address translation.

5. Implementation Issues:
 Memory Protection: Ensuring that a process cannot access memory belonging to
other processes.
 Sharing of Pages: Some pages (e.g., code) may be shared between processes, but
others (e.g., private data) should not be.
 Context Switching: When switching between processes, the system must save and
restore the state of the page tables and memory mappings.
 Hardware Support: Modern processors support memory management features like
hardware-based page tables and TLBs.

6. Segmentation:

 Segmentation is a memory management scheme that supports the user's view of


memory, where a process is divided into segments such as code, data, stack, etc.
 Unlike paging, which divides memory into fixed-size blocks, segmentation divides
memory into variable-sized blocks.
 Advantages of Segmentation:
o Logical division of memory according to the program’s structure.
o Easier to grow or shrink individual segments.
 Segmentation Fault: Occurs when a process attempts to access memory outside its
assigned segment.

UNIT-III

Deadlocks: Notes

1. Resources:

 Resources refer to physical or logical entities required by processes to perform tasks


(e.g., CPU time, memory, I/O devices).
 Resources can be shared or exclusive.
 Examples include printers, files, CPU, memory, etc.

2. Introduction to Deadlocks:

 A deadlock is a situation where a group of processes is blocked because each process


is waiting for a resource held by another process in the group.
 Four necessary conditions for a deadlock to occur:
1. Mutual Exclusion: At least one resource must be held in a non-shareable
mode.
2. Hold and Wait: A process must be holding at least one resource and waiting
for additional resources held by others.
3. No Preemption: Resources cannot be forcibly removed from processes
holding them.
4. Circular Wait: A set of processes must exist such that each process is waiting
for a resource held by the next process in the set.

3. The Ostrich Algorithm:

 The ostrich algorithm is a strategy to ignore the problem of deadlocks and hope it
doesn't occur.
 It is often used in situations where deadlocks are considered rare or when the cost of
dealing with deadlocks is higher than ignoring them.

4. Deadlock Detection and Recovery:

 Detection: Involves checking the system for cycles in the resource allocation graph or
using a wait-for graph to identify deadlocked processes.
o Can be done periodically or when resources become unavailable.
 Recovery:
o Process Termination: Abort one or more processes to break the deadlock.
This could involve aborting processes until the deadlock cycle is eliminated.
o Resource Preemption: Forcefully take resources from some processes to give
them to others, breaking the cycle.

5. Deadlock Avoidance:

 Deadlock avoidance requires knowing in advance the resource needs of processes.


o Safe State: A system is in a safe state if there is a sequence of processes that
can execute without causing a deadlock.
o The system dynamically checks whether allocating resources would leave it in
a safe state or not.

Techniques:

o Banker’s Algorithm: A resource allocation and deadlock avoidance


algorithm used to allocate resources only if it leads to a safe state.

6. Deadlock Prevention:

 Preventing deadlocks involves structuring resource allocation to prevent one or more


of the necessary conditions for deadlock from occurring.
o Eliminating Mutual Exclusion: This is not always possible since some
resources (e.g., printers) must be used exclusively.
o Eliminating Hold and Wait: Processes must request all the resources they
need at once.
o Eliminating No Preemption: If a process holds some resources and needs
additional ones, the system can preempt resources and allocate them to another
process.
o Eliminating Circular Wait: Impose a strict ordering of resources and require
processes to request resources in this order.

7. Issues in Deadlock Handling:

 Efficiency: Deadlock detection can consume resources and time. The system must
balance detecting deadlocks while maintaining performance.
 Fairness: When recovering from deadlocks (e.g., process termination), fairness
should be ensured to avoid starvation of certain processes.
 System Complexity: Techniques like deadlock avoidance and prevention can add
complexity to the system and may not always be feasible in real-time systems.
1. Overview of Linux

 Linux is an open-source, Unix-like operating system developed by Linus Torvalds in


1991.
 It is widely used for servers, desktops, and embedded systems due to its flexibility,
security, and robustness.
 Kernel: The core part of the operating system that manages hardware and system
resources.
 Linux is composed of the kernel, system libraries, and user space programs.

2. Linux Goals

 Open-source: To make the operating system free for anyone to use, modify, and
distribute.
 Multitasking: Linux is designed to handle multiple tasks concurrently.
 Portability: It is platform-independent, meaning it can run on a wide variety of
hardware architectures.
 Security: Built-in security features like access control and user authentication.
 Performance: Optimized for high performance, especially in server and network
environments.
 Stability: Known for reliability and uptime, making it ideal for servers and critical
systems.

3. Interfaces to Linux

 Command-Line Interface (CLI): The most direct way to interact with Linux, using
terminal commands.
 Graphical User Interface (GUI): Many Linux distributions come with a GUI, such
as GNOME or KDE, providing a more user-friendly interface.
 Network Interfaces: Linux supports many networking protocols (TCP/IP, etc.) for
networking with other systems.

4. The Shell

 The Shell is a command interpreter that provides a user interface to the Linux system.
 Common shells include:
o Bash (Bourne Again Shell)
o Zsh (Z Shell)
o Fish (Friendly Interactive Shell)
 The shell allows users to execute commands, run scripts, and manage processes.
 It can be run interactively or in batch mode.

5. Linux Utility Programs

 Linux comes with a variety of utility programs to perform specific tasks, such as:
o File management: ls, cp, mv, rm, mkdir, etc.
o Text processing: grep, awk, sed, cut, etc.
o System monitoring: ps, top, htop, df, du, etc.
o Networking: ping, ifconfig, ssh, scp, wget, etc.
o Disk management: fdisk, mount, umount, fsck, etc.
o Package management: apt, yum, rpm, pacman, etc.

6. Kernel Structure

 The Kernel is the core part of Linux and manages hardware resources like CPU,
memory, and I/O devices.
 It provides services like process management, memory management, file system
management, device drivers, and networking.
 Key components:
o Process Scheduler: Manages process execution and multitasking.
o Memory Manager: Handles the system's memory, including virtual memory.
o File System: Manages data storage and retrieval.
o Device Drivers: Provide communication between the kernel and hardware.
o System Calls: Interface between user programs and the kernel.

History of Android

 Initial Development: Android was developed by Android Inc., founded in 2003 by


Andy Rubin, Rich Miner, Nick Sears, and Chris White. It was initially intended to be
an operating system for digital cameras, but pivoted to smartphones in 2005 after
being acquired by Google.
 First Release: The first commercial Android device, the T-Mobile G1, was released
in 2008. Android's open-source nature and use of Linux made it highly customizable
and cost-effective for manufacturers.
 Evolution: Over time, Android became the dominant mobile operating system
globally, with various updates to enhance performance, security, and functionality.

Design Goals of Android

 Open Source: Android was designed to be open-source, giving developers and


manufacturers flexibility in customizing and modifying the system.
 Multi-Platform: Android supports a wide variety of devices, from smartphones and
tablets to smartwatches and televisions.
 User-Centric: Focused on providing an intuitive and customizable user interface with
easy access to applications and services.
 Support for Third-Party Applications: Android allowed third-party apps to be
easily developed and distributed via the Google Play Store, fostering a large app
ecosystem.

Android Architecture

 Linux Kernel: The foundation of Android is the Linux kernel, providing low-level
system functions such as memory management, process management, and hardware
abstraction.
 Libraries: Android uses various native libraries written in C and C++, such as
WebKit, OpenGL, and SQLite, to provide functionality for applications.
 Android Runtime (ART): Replaces Dalvik in newer Android versions, executing
apps written in Java or Kotlin. ART compiles the code to native instructions at install
time, improving performance.
 Application Framework: Provides the high-level API used by developers to interact
with the system, including user interface components, content providers, and location-
based services.
 Applications: Android apps are built using Java or Kotlin and run on the Android
Runtime.

Linux Extensions in Android

Android extends the Linux kernel with its own set of services and APIs that are tailored for
mobile devices, such as:

 Binder: A unique inter-process communication (IPC) mechanism used by Android.


 SurfaceFlinger: Manages the display and handles graphics composition.
 Power Management: Android adds power management features, like WakeLocks, to
the Linux kernel to handle device power consumption efficiently.
 Audio and Video: Specialized audio and video frameworks, like AudioFlinger and
Stagefright, are added to support multimedia processing.

Android Applications

Android applications are primarily written in Java or Kotlin and packaged in APK (Android
Package) files. Each app runs in its own virtual machine, and developers interact with
Android's extensive APIs to build apps that can run on various devices.

History of Windows

 MS-DOS-Based Windows:
o Windows 1.0 (1985) was the first graphical user interface (GUI) on top of
MS-DOS. It was limited in functionality, but it introduced basic elements like
windows, menus, and dialog boxes.
o Windows 3.x (1990-1994) significantly improved the interface and added
support for multitasking and virtual memory.
o Windows 95 (1995) was a major leap forward with the introduction of a 32-
bit preemptive multitasking system, a new taskbar, and the Start menu.
 NT-Based Windows:
o Windows NT (1993) was designed as a more powerful, secure, and stable
operating system. It introduced a new kernel architecture and was the
foundation for later versions of Windows, such as Windows 2000, XP, and
later.
o Windows XP (2001) merged the consumer-friendly interface of Windows
95/98 with the stability of NT, and it became one of the most widely used
versions.
 Modern Windows:
o Windows Vista (2007) and Windows 7 (2009) focused on improving
security, user interface, and system stability. Windows 7 was especially
popular due to its performance improvements over Vista.
o Windows 8 (2012) introduced a new, tablet-friendly interface with Live Tiles,
but was criticized for its departure from the traditional desktop interface.
o Windows 10 (2015) combined the traditional desktop experience with features
from Windows 8, providing a more user-friendly, unified operating system
across devices.
o Windows 11 (2021) introduced a redesigned Start menu, rounded corners, and
improved performance, with a focus on productivity, gaming, and integration
with cloud services.

UNIT-IV

Basic Features of Linux

 Open Source: Linux is open-source software, meaning its source code is freely
available for modification and distribution.
 Multitasking: Linux supports multitasking, allowing multiple programs to run
simultaneously.
 Multiuser: Linux allows multiple users to use the system at the same time without
interfering with each other's work.
 Portability: Linux can run on many different hardware platforms, including desktops,
servers, mobile devices, and more.
 Security: Linux has a robust security model, including user permissions, file
encryption, and security patches.
 Networking: Linux is well-suited for networking tasks, supporting a wide range of
network protocols.
 Shell Interface: Linux offers a powerful command-line interface (CLI) in addition to
graphical user interfaces (GUIs).
 Package Management: Linux uses package managers like apt, yum, pacman, etc., to
easily install, update, and remove software.

Advantages of Linux

 Cost-Effective: Linux is free to use, and most of its software is also open source.
 Stability and Reliability: Linux is known for being highly stable and less prone to
crashes.
 Customizability: Linux is highly customizable, allowing users to change almost any
part of the system according to their needs.
 Community Support: Being open-source, Linux has a large, active community of
developers and users who provide support.
 Performance: Linux is known for its high performance, particularly in server
environments.
 Security: Linux has strong security mechanisms, with built-in tools like firewalls,
SELinux, and AppArmor.
 Software Availability: Many professional tools, programming languages, and
enterprise applications are available for Linux.
 Resource Efficient: Linux can run on older hardware and has low system resource
requirements.

Installing Requirements for Linux

 Hardware: Minimum requirements usually include:


o A CPU: Any modern processor (x86, ARM, etc.)
o RAM: Typically at least 512MB, though more is recommended for smoother
performance.
o Storage: At least 10-20GB of disk space for the installation (depending on the
Linux distribution).
o A bootable USB or DVD drive to install from.
 Software Requirements:
o A bootable media (USB drive, DVD, or ISO image).
o For certain distributions, a working internet connection for downloading
updates and additional packages during installation.
 System Compatibility: Linux supports a wide variety of hardware, but it’s important
to check that your specific device is supported (e.g., printer drivers, Wi-Fi cards, etc.).

Basic Architecture of Linux System

1. Kernel:
o The kernel is the core part of the Linux system. It interacts with the hardware
and manages system resources like CPU, memory, and storage.
o The kernel handles low-level tasks like process management, device drivers,
file systems, and system calls.
2. System Library:
o These are essential programs that provide functions to applications. Most
libraries are written in C (e.g., the GNU C Library, glibc).
o Libraries help in performing tasks like system calls or file operations without
having to access the kernel directly.
3. System Utilities:
o These are programs that help manage the system. Examples include
command-line utilities (ls, grep, cp, mkdir, etc.) and system management
tools.
4. Shell:
o The shell is an interface for user interaction with the system. It interprets and
executes user commands (e.g., bash, zsh).
o It can be used to execute commands directly or run shell scripts.
5. User Space:
o This is the environment where user applications run. It includes user
applications, system libraries, and utilities.
o User space is isolated from the kernel to maintain system stability.
6. File System:
o Linux uses a hierarchical file system where everything is treated as a file (e.g.,
devices, directories, etc.).
o It follows a standard file system structure with directories like /home, /bin,
/usr, and /etc.
7. Device Drivers:
o Linux uses device drivers to interact with hardware. These drivers are part of
the kernel and enable the system to communicate with various hardware
components.

Here are notes on some essential Linux commands related to files and directories:

1. cd (Change Directory)
 Syntax: cd <directory>
 Changes the current working directory to the specified one.
 Example:

bash
CopyEdit
cd /home/user/Documents

2. cp (Copy Files)

 Syntax: cp <source> <destination>


 Copies files or directories from source to destination.
 Example:

bash
CopyEdit
cp file1.txt /home/user/Documents/
cp -r folder1 /home/user/Backup/ # for copying directories

3. mv (Move or Rename Files)

 Syntax: mv <source> <destination>


 Moves files or directories to another location, or renames them.
 Example:

bash
CopyEdit
mv file1.txt /home/user/Docs/ # move file
mv oldname.txt newname.txt # rename file

4. rm (Remove Files or Directories)

 Syntax: rm <file>
 Removes a file. To remove a directory, use -r for recursive deletion.
 Example:

bash
CopyEdit
rm file1.txt # remove a file
rm -r foldername # remove a directory and its contents
rm -f file1.txt # force deletion without confirmation

5. mkdir (Make Directory)

 Syntax: mkdir <directory>


 Creates a new directory.
 Example:

bash
CopyEdit
mkdir new_folder
mkdir -p parent/child # create parent directory if it doesn’t exist

6. more (View Files)

 Syntax: more <file>


 Displays the contents of a file one screen at a time. Use space to go to the next page.
 Example:

bash
CopyEdit
more file1.txt

7. less (View Files)

 Syntax: less <file>


 Similar to more, but allows both forward and backward navigation of the file.
 Example:

bash
CopyEdit
less file1.txt

8. cat (Concatenate and Display Files)

 Syntax: cat <file>


 Displays the content of a file.
 Example:

bash
CopyEdit
cat file1.txt
cat file1.txt file2.txt > combined.txt # combine files

9. File Comparisons

 diff compares two files line by line.


o Syntax: diff file1 file2
o Example:

bash
CopyEdit
diff file1.txt file2.txt

 cmp compares two files byte by byte.


o Syntax: cmp file1 file2
o Example:

bash
CopyEdit
cmp file1.txt file2.txt

10. Disk-Related Commands

 df (Disk Free Space)


o Syntax: df
o Displays the amount of disk space available on the file system.
o Example:

bash
CopyEdit
df -h # Human-readable format

 du (Disk Usage)
o Syntax: du <file|directory>
o Displays disk usage for files or directories.
o Example:

bash
CopyEdit
du -sh /home/user/Documents # shows the size of the directory

 lsblk (List Block Devices)


o Syntax: lsblk
o Lists all block devices, such as hard drives and partitions.
o Example:

bash
CopyEdit
lsblk

 fdisk (Partitioning Disk)


o Syntax: fdisk <device>
o Used for partitioning disks.
o Example:

bash
CopyEdit
fdisk /dev/sda

11. Essential Linux Commands

 ls: Lists files and directories.


o Syntax: ls
o Example:

bash
CopyEdit
ls -l # long listing with permissions, owner, size, and date
ls -a # shows hidden files

 pwd (Print Working Directory)


o Syntax: pwd
o Displays the current directory path.
o Example:

bash
CopyEdit
pwd

 touch: Creates an empty file or updates the timestamp of an existing file.


o Syntax: touch <filename>
o Example:

bash
CopyEdit
touch newfile.txt

 chmod: Changes file permissions.


o Syntax: chmod <permissions> <file>
o Example:

bash
CopyEdit
chmod 755 script.sh

 chown: Changes file ownership.


o Syntax: chown <owner>:<group> <file>
o Example:

bash
CopyEdit
chown user:group file1.txt
UNIT-V

Understanding Shells:

 Shell: A command-line interface (CLI) that allows users to interact with the operating
system. Common Linux shells include bash (Bourne Again Shell), sh (Bourne Shell),
zsh, and others.
 Interactive Shell: This is the shell session you use directly, where you can run
commands and see output.
 Non-Interactive Shell: Shells that run scripts and don’t interact with users directly.

Processes in Linux:

 Process: A running instance of a program in Linux.


o Each process has a PID (Process ID), PPID (Parent Process ID), UID (User
ID), etc.
o Parent Process: The process that spawned a child process.
o Child Process: A process created by another process.
 Scheduling of Processes: Linux uses a time-sharing approach to schedule processes.
o Processes are assigned priority levels for CPU time.
o Scheduler manages which processes get to use the CPU and for how long.
o Scheduling algorithms include Round Robin, Priority-based scheduling,
etc.

Common Commands for Process Management:

 ps: Displays a snapshot of current processes.


o Example: ps aux shows all processes for all users.
 top: A real-time view of processes and system resources.
 kill: Terminates processes using their PID.
o Example: kill 1234 (kills the process with PID 1234).
 sleep: Pauses the execution for a specified amount of time.
o Example: sleep 5 (pauses for 5 seconds).
 who: Shows who is currently logged into the system.
o Example: who displays usernames and login times.

Commands for Printing and Searching:

 echo: Prints text or output to the terminal.


o Example: echo "Hello, World!"
 grep: Searches for a pattern in a file or input.
o Example: grep "error" log.txt (finds all occurrences of "error" in log.txt).
 fgrep: A variant of grep that treats the pattern as a fixed string (ignores special
characters).
o Example: fgrep "path/to" file.txt
 find: Searches for files in a directory hierarchy.
o Example: find /home/user -name "*.txt" (finds all .txt files in the /home/user
directory).
 sort: Sorts lines of text files.
o Example: sort file.txt (sorts the lines in file.txt).

Commands for File Handling and Management:

 touch: Changes the timestamp of a file or creates a new empty file.


o Example: touch newfile.txt (creates newfile.txt if it doesn’t exist).
 file: Determines the file type.
o Example: file example.txt (outputs the type of file example.txt is).
 cat: Displays file contents in the terminal.
o Example: cat file.txt (prints the content of file.txt).
 cut: Extracts sections from each line of a file.
o Example: cut -d':' -f1 /etc/passwd (extracts the first field from /etc/passwd).
 dd: Copies and converts files.
o Example: dd if=input.img of=output.img (copies input.img to output.img).

Other Useful Commands:


 cal: Displays a calendar.
o Example: cal (shows the current month’s calendar).
 banner: Prints a large banner of text.
o Example: banner Hello (prints "Hello" in large characters).
 ws: Provides status information for a user or session (less common in some Linux
distributions).

Batch Commands:

 Batch commands can be executed in sequence or background, typically in scripts or


from a batch file. These are used for repetitive tasks.
o Example of a batch script:

bash
CopyEdit
#!/bin/bash
echo "Starting process..."
sleep 2
ps aux
kill 1234

File-Related Commands:

 stat: Displays detailed information about a file or filesystem.


o Example: stat file.txt (shows details like size, permissions, and modification
time).

Mathematical Commands

1. bc (Basic Calculator)
o bc is a command-line calculator in Unix-like systems. It can handle arbitrary
precision arithmetic.
o To start:

bash
CopyEdit
bc

o Example:

bash
CopyEdit
5+3

o You can also use -l for the math library (e.g., sine, cos).

bash
CopyEdit
bc -l
o To perform a more complex calculation:

bash
CopyEdit
echo "scale=2; 10/3" | bc

2. expr
o expr is used to evaluate expressions and perform basic arithmetic operations.
o Example:

bash
CopyEdit
expr 5 + 3

o Example with variables:

bash
CopyEdit
a=5
b=3
expr $a + $b

3. factor
o factor is used to find the prime factors of a number.
o Example:

bash
CopyEdit
factor 100

Output:

makefile
CopyEdit
100: 2 2 5 5

4. units
o units is a command-line tool for converting between different units of
measurement.
o Example:

bash
CopyEdit
units "10 kilometers" "miles"

Output:

CopyEdit
10 kilometers = 6.2137 miles
Text Editors

1. vi (Visual Editor)
o vi is a classic, powerful text editor available on most Unix systems.
o Launch:

bash
CopyEdit
vi filename

o Modes:
 Normal mode: For navigation, editing, and commands.
 Insert mode: For typing text (press i to enter).
 Command mode: For commands like save, quit (:w, :q).
o Example:
 To enter insert mode: i
 To save: :w
 To quit: :q
 To save and quit: :wq
2. joe (Joe's Own Editor)
o joe is a simple and user-friendly text editor.
o Launch:

bash
CopyEdit
joe filename

o Basic commands:
 Move cursor: Arrow keys
 Insert text: Start typing.
 Save: Ctrl+K, then X
 Exit: Ctrl+K, then Q
3. vim (Vi Improved)
o vim is an improved version of vi with more features like syntax highlighting,
better configuration, etc.
o Launch:

bash
CopyEdit
vim filename

o Similar to vi, it has modes (normal, insert, and command), but with extra
features like autocompletion, color schemes, and more.
o To install plugins and customize vim, you can modify ~/.vimrc.

1. Shell Programming Basics

 Shell programming is a way to automate tasks and manage the system using shell
scripts.
 A shell script is a text file that contains a series of commands for the shell to execute.
 The script can be executed by typing the script's name at the command prompt,
provided it has execution permissions.

2. Various Types of Shells

 Bash (Bourne Again Shell): The most common shell used in Linux.
 Bourne Shell (sh): An older shell, but still in use for script compatibility.
 C Shell (csh): A shell with syntax similar to C programming language.
 Korn Shell (ksh): Combines features from both the Bourne and C Shells.
 Z Shell (zsh): An extended version of bash with additional features.

3. Shell Programming in Bash

 Bash is widely used for scripting due to its simplicity and compatibility with most
Linux distributions.
 A basic bash script starts with a shebang (#!/bin/bash), followed by commands.

4. Conditional and Looping Statements

 If-Else Statement:

bash
CopyEdit
if [ condition ]; then
command1
else
command2
fi

 For Loop:

bash
CopyEdit
for var in 1 2 3 4; do
echo $var
done

 While Loop:

bash
CopyEdit
while [ condition ]; do
command
done

5. Case Statements

 Used for branching logic based on different conditions.

bash
CopyEdit
case "$var" in
pattern1)
command1 ;;
pattern2)
command2 ;;
*)
default_command ;;
esac

6. Parameter Passing and Arguments

 Arguments can be passed to a script when executing it:

bash
CopyEdit
./script.sh arg1 arg2

 Access arguments inside the script:


o $1, $2, etc. for positional arguments.
o $# for the number of arguments.
o $@ or $* for all arguments.

7. Shell Variables

 Defining Variables:

bash
CopyEdit
var="value"

 Accessing Variables:

bash
CopyEdit
echo $var

8. Shell Keywords

 if, else, fi – For conditional statements.


 for, do, done – For loops.
 case, esac – For case statements.
 function – For defining functions.

9. Use of grep in Shell

 grep is used to search text using patterns.

bash
CopyEdit
grep "pattern" file

 You can use various options like:


o -i: Ignore case.
o -r: Search recursively.
o -v: Invert match (show lines not matching the pattern).

10. AWK Programming

 awk is a powerful text-processing tool.


 Basic syntax:

bash
CopyEdit
awk '{print $1, $2}' file

 You can use it for processing and manipulating data in files, such as extracting
specific columns or performing arithmetic.

You might also like