SlideShare a Scribd company logo
1 of 111
Download to read offline
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Semester: First Semester
Name of the Subject:
Introduction to Operating System
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
DEFINITION
• An operating system is an intermediary
between a computer user and the hardware.
• Make the hardware convenient to use.
• Manages system resources.
• Use the hardware in an efficient manner
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• The main functions of operating systems are:
• • Manages and Interacts with Computer Hardware
• • Process the tasks
• • Provides the User/ Computer Interface (CLI / GUI)
• • Provides the Interface for Application Software
• • Input / Output Operations
• • Error Detection, Resource Allocation, Security and
• Protection
FUNCTION
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• Batch
– submit large number of jobs at one time
– system decides what to run and when
• Time Sharing
– multiple users connected to single machine
– few processors, many terminals
• Single User Interactive
– one user, one machine
TYPES OF OS
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• Parrallel
– traditional multiprocessor system
– higher throughput and better fault tolerance
• Distributed
– networked computers
• Real Time
– very strict response time requirements
– hardware or software
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• Only one program can perform at a time
• Simple to implement
– only one process attempting to use resources
• Few security risks
• Poor utilization of the CPU and other
resources
• Example: MS-DOS
FUNCTION
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• Very complex
• Serious security issues
– how to protect one program from another sharing
the same memory
• Much higher utilization of system resources
• Example: Unix, Windows NT
Multi tasking
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• OS and hardware closely tied together
• Many useful hardware features have been
invented to compliment the OS
• Basic hardware resources
– CPU
– Memory
– Disk
– I/O
Hardware basics
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• CPU controls everything in the system
– if work needs to be done, CPU gets involved
• Most precious resource
– this is what your paying for
– want to get high utilization (from useful work)
• Only one process on a CPU at a time
• Hundreds of millions of instructions / sec
– and getting faster all the time
CPU
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• Limitted in capacity
– never enough memory
• Temporary (volatile) storage
• Electronic storage
– fast, random access
• Any program to run on the CPU must be in
memory
MEMORY
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• Virtually infinite capacity
• Permanent storage
• Orders of magnitude slower than memory
– mechanical device
– millions of CPU instructions can execute in the
time it takes to access a single piece of data on
disk
• All data is accessed in blocks
– usually 512 bytes
DISK
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• Disk is actually part of the I/O subsystem
– they are of special interest to the OS
• Many other I/O devices
– printers, monitor, keyboard, etc.
• Most I/O devices are painfully slow
• Need to find ways to hide I/O latency
– like multiprogramming
I/O
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• OS must protect itself from users
– reserved memory only accessible by OS
– hardware enforced
• OS may protect users from one another
– not all systems do this
– hardware enforced again
PROTECTION AND SECURITY
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• Dual -Mode Operation
– user mode
• limited set of hardware instr and memory available
• mode all user programs run in
– supervisory mode
• all hardware instr and memory are available
• mode the OS runs in
• Never let user run in supervisory mode
PROTECTION AND SECURITY
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• Modern OS’s are event driven
• Event is signaled by special hardware signal sent to
the CPU
• Two types of events
– interrupts
• caused by external devices or timers
• can occur at any moment in time
– exceptions (traps)
• caused by software
– the generic term for both is Interrupt
• sorry for the confusion
INTERRUPPTS
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• One way to handle interrupts is with one
standard program
– big case-switch statement that gets executed on
any interrupt
– inefficient
• Second alternative is to use an interrupt table
and special hardware
– this is the way modern systems operate
INTERRUPT PHILOSOPHY
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• Large array indicating what code to run for a
given interrupt
• Each interrupt has a corresponding number
associated with it
– on Intel processors this is from 0 to 255
– this gives fixed size interrupt table
• Use the interrupt number to index into the
array to find out what code to run
INTERRUPT TABLE
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• Programmable Interrupt Controller (PIC)
– connected to I/O devices via interrupt request lines (IRQ)
• ideally, one IRQ for each I/O device - doesn’t work this way in
reality
• PIC connected to CPU by a special signal
• PIC also connected to CPU via I/O bus
• Besides the PIC, interrupts can also be generated by
software instructions or errors
– again, these are usually referred to as exceptions
INTERRUPT HARDWARE
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• After each instruction executes, CPU checks to see if interrupt
pin has been raised
• If so, the following occurs:
1) sets the system into kernel mode (if not already there)
2) determine interrupt number (from PIC or instruction)
3) read appropriate interrupt table entry
- special register contains base address of interrupt table
- each entry in table is fixed size so easy to calculate where
to look in memory ( memLoc = idtr + 8 * intNum )
4) saves the program counter to the stack (with a couple of others)
5) saves error code to stack (if it exists)
6) loads the program counter with the value stored in the TABLE.
HARDWARE HANDLING OF INTERRUPT
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• The following 6 steps are common to all interrupt handlers:
1) save IRQ to kernel mode stack
2) save registers to kernel mode stack
3) send acknowledgement to PIC
- this allows PIC to then handle other interrupts on IRQ line
4) execute the appropriate handler code
5) restore registers
6) issue an iret instruction
• The steps for exception handlers are almost identical
– simply remove steps 1 & 3 above
Software handaling interrupt
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• As indicated earlier, exceptions are caused by software
– divide by zero error
– page fault
– int instruction
– etc
• Some of these cause the program to stop executing
• Some of them invoke special operating system code that is
invisible to the user
• Some of them invoke operating system code at the user’s
request
– system calls
More of exception
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• The number of IRQ lines is usually limited
• May have more I/O devices than IRQ’s
• Solution: let multiple devices share an IRQ
• Interrupt table contains a pointer to a linked list of
interrupt handlers
– instead of the address of the interrupt handler
• On interrupt, execute all of the handlers associated
with an IRQ
– requires handlers to recognize
Ingle IRQ for multiple device
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
EXAMPLE
Interrupt Table
0
1
2
3
4
5
6
7
8
9
floppy disk
printer scanner camera
hard
disk
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• Assume an interrupt from the scanner arrives at the PIC
1) PIC raises INTR signal on CPU
2) CPU reads PIC over I/O bus to determine IRQ
3) CPU then accesses array in memory to get the first interrupt handler
- printer
4) CPU executes printer handler code
5) printer handler queries printer and notices there is no interrupt
pending
- handler returns immediately
6) next the scanner handler gets executed
7) scanner handler queries scanner and notices there is an interrupt
pending
EXAMPLE
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• An OS’s system calls are called the Application
Programmers Interface (API)
• System calls are routines run by the OS on behalf of
the user
• They are run in supervisory mode
• Allow user to access I/O, create processes, get
system information, etc.
• How many system calls an OS has varies
– Unix: around a hundred
System calls
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• On power up
– everything in system is in random, unpredictable state
– special hardware circuit raises RESET pin of CPU
• sets the program counter to 0xfffffff0
– this address is mapped to ROM (Read-Only Memory)
• BIOS (Basic Input/Output Stream)
– set of programs stored in ROM
– some OS’s use only these programs
• MS DOS
– many modern systems use these programs to load other system
programs
• Windows, Unix, Linux
System startups
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• General operations performed by BIOS
1) find and test hardware devices
- POST (Power-On Self-Test)
2) initialize hardware devices
- creates a table of installed devices
3) find boot sector
- may be on floppy, hard drive, or CD-ROM
4) load boot sector into memory location 0x00007c00
5) sets the program counter to 0x00007c00
- starts executing code at that address
BIOS
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• Small program stored in boot sector
• Loaded by BIOS at location 0x00007c0
• Configure a basic file system to allow system
to read from disk
• Loads kernel into memory
• Also loads another program that will begin
kernel initialization
BOOT LEADER
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• Determines amount of RAM in system
– uses a BIOS function to do this
• Configures hardware devices
– video card, mouse, disks, etc.
– BIOS may have done this but usually redo it
• portability
• Switches the CPU from real to protected mode
– real mode: fixed segment sizes, 1 MB memory addressing, and no
segment protection
– protected mode: variable segment sizes, 4 GB memory addressing,
and provides segment protection
• Initializes paging (virtual memory)
INITIAL KERNEL PROGRAM
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• Sets up page tables and segment descriptor tables
– these are used by virtual memory and segmentation
hardware (more on this later)
• Sets up interrupt vector and enables interrupts
• Initializes all other kernel data structures
• Creates initial process and starts it running
– init in Linux
– smss (Session Manager SubSystem) in NT
FINAL KERNEL PROGRAM
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• Application programs included with the OS
• Highly trusted programs
• Perform useful work that most users need
– listing and deleting files, configuring system
– ls, rm, Windows Explorer and Control Panel
– may include compilers and text editors
• Not part of the OS
– run in user space
SYSTEM PROGRAM
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Processes: The Process Model
 Multiprogramming of four programs
 Conceptual model of 4 independent, sequential processes
 Only one program active at any instant
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Processes and programs
The difference between a process and a program:
 Baking analogy:
o Recipe = Program
o Baker = Processor
o Ingredients = data
o Baking the cake = Process
 Interrupt analogy
o The baker’s son runs in with a wounded hand
o First aid guide = interrupt code
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Main OS Process-related
Goals
 Interleave the execution of existing processes to
maximize processor utilization
 Provide reasonable response times
 Allocate resources to processes
 Support inter-process communication (and
synchronization) and user creation of processes
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
How are these goals achieved?
 Schedule and dispatch processes for execution by
the processor
 Implement a safe and fair policy for resource
allocation to processes
 Respond to requests by user programs
 Construct and maintain tables for each process
managed by the operating system
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Process Creation
When is a new process created?
1. System initialization (Daemons)
2. Execution of a process creation system call by a
running process
3. A user request to create a process
4. Initiation of a batch job
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Process States
 Running - actually using the CPU
 Ready – runnable, temporarily stopped to let
another process run
 Blocked - unable to run until some external event
happens
A process can block itself, but not “run” itself
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Process State Transitions
When do these
transitions occur?
1. Process blocks for input or waits for an
event
2. End of time-slice, or preemption
3. Scheduler switches back to this process
4. Input becomes available, event arrives
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Suspended Processes
 Processor is much faster than I/O so many processes
could be waiting for I/O
 Swap some of these processes to disk to free up
more memory
 Blocked state becomes blocked-suspended state
when swapped to disk, ready becomes
ready-suspended
 Two new states
o Blocked-suspended
o Ready-suspended
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Process Management
Operations
Process creation and termination
 Process scheduling and dispatching
 Process switching
 Process synchronization and support for inter-
process communication
The OS maintains process data in the
Process Control Blocks (PCB)
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Process Table
 Process image consists of program (code/text), data,
stack, and attributes
 Control Attributes form the Process Control Block -
PCB
o Unique ID (may be an index into the PT)
o User ID; User group ID, Parent process ID
o process control information
o Processor state information
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Process Control Information
Additional information needed by the operating
system to control and coordinate the various active
processes
o Execution state: see next slide…
o Scheduling-related information - state; priority;
scheduling info
o inter-process communication - signals; pipes
o Time of next alarm
o memory management - pointers to text/data/stack
segments
o resource ownership and utilization - open files
o Process relationships: Parent, process group…
o Environment variables
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Process Creation
 Assign a unique process identifier
 Allocate space for the process
 Initialize process control block
 Set up appropriate linkage to the scheduling
queue:
o In the former example: add the PCB to the ready queue
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Stop a running process
 Clock event: process has executed a full
time-slice (a.k.a. time-quantum)
 Process becomes blocked
 Another process is ready
 Error occurred
 Signal received
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Process Context Switch
 Save processor context, including program counter
and other registers
 Update the process control block with the new state
and any accounting information
 Move process control block to appropriate queue -
ready, blocked
 Select another process for execution
 Update the process control block of the process
selected
 Update memory-management data structures
 Restore context of selected process
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Inter-Process
Communication
 Shared memory – the fastest way
o Need to avoid race conditions
 Non-shared Memory:
o File/Pipes
o Unbuffered messages - Rendezvous
o Buffered messages – Mailboxes and Sockets
o Sockets: Address – Domain+Port
o Sockets: Types – Stream or Datagrams
o Sockets: API: Socket, Bind, Connect, Read/Write
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Scheduling
• Assign each process time to use CPU
– Determine sequence (order), timing (when)
– Conflicting objectives  need compromise
• Scheduling levels
– High: whether to admit a new process
– Medium: suspend/resume a process
– Low: dispatch (run) a ready process
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Scheduling Objectives
• Maximise throughput
• Give all users a “fair” (not equal) chance
• Provide tolerable performance
– Response time for on-line user
– Turnaround time for batch users
• Degrade performance gracefully
– OK to be slow but avoid complete collapse
• Be consistent, predictable over time
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Scheduling Criteria
• Priority which may be either/both:
– Assigned to job by user
– Determined by properties of the job
• Class of job (real-time > on-line > batch)
• Resources needed (CPU time, memory)
• I/O or CPU bound (the aim is a balance)
• Resources already used
• Time already waited
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Types of Scheduling Policies
• Preemptive (Used by most OS today)
– OS stops one process to run another
• Non-preemptive
– process runs until termination or I/O wait
• Cooperative (Used by Windows 3.11)
– Programs must voluntarily give up CPU
– Not managed by OS; trusts programmers
– If a process hangs the whole PC hangs 
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Scheduling Policies
• First come first served (FCFS/FIFO)
• Shortest job first (SJF)
• Shortest remaining time (SRT)
• Highest response ratio next
• Round robin (RR)
• Multi-level feedback queues (MFQ)
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
First come first served
• Also called first in first out (FIFO)
• Process waiting longest is first in queue
• Favours long jobs
– high run-time/wait-time ratio
• Favours CPU-bound jobs
– I/O devices underused
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Shortest job first (next)
• Run job with shortest estimated run time
• Long jobs may be delayed indefinitely
• JCL commands can specify run time
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Shortest remaining time
• Run job w/ shortest est. remaining time
• Highly favours short jobs
• Long jobs will be delayed indefinitely
• Requires estimating total run time
• Requires measuring elapsed run time
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Highest response ratio next
• P = (time waiting + run time) / run time
• Priority based on two factors
• Favours shorter jobs
• Guarantees a job cannot be starved
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Round Robin
• Each process given a set time slice
• Pre-emption at end of time quantum
– Hardware timer generates interrupts
• After running, go to back of queue
• Used in most interactive operating systems
• How large should each time slice be?
– Small  high context switch overhead
– Large  user response time is reduced
– In practice, about 10-20 ms
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Multi-level feedback queues
• Separate queues for different priorities
– New process  level 1 FIFO (highest)
– After timeout  level 2 FIFO, etc.
– Lowest level is Round Robin
• Adapts to past process behaviours
– high CPU usage  reduced access level
• Long processes may starve
– if wait time is long, promote/increase slice
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Deadlock
• Each thread is waiting on a resource
held by another thread
– So, there is no way to make progress
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Deadlock
• Examples: Traffic Jam :
• Dining Philosophers
• Device allocation
– process 1 requests tape drive 1 & gets it
– process 2 requests tape drive 2 & gets it
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Necessary Conditions for Deadlock
• Mutual exclusion
– Resources cannot be shared
• e.g., buffers, locks
• Hold and wait (subset property)
– A thread must hold a subset of its resource needs
• And, the thread is waiting for more resources
• No preemption
– Resources cannot be taken away
• Circular wait
– A needs a resource that B has
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Resource Allocation Graph with a Deadlock
P => R: request edge
R => P: assignment edge
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Cycle Without Deadlock
P => R: request edge
R => P: assignment edge
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Approaches to Deadlock
1. Avoid threads
2. Deadlock prevention
– Break up one of the four necessary conditions
3. Deadlock avoidance
– Stay live even in the presence of the four
conditions
4. Detect and recover
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Deadlock Detection
• Detection algorithm (sketch)
– Keep track of who is waiting for resources
– Keep track of who holds resources
– Assume that all runnable processes release all
their resources
• Does this unblock a waiting process?
– If yes, release that process’s resources
– If processes are still blocked, we are deadlocked
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Recovery
• Must “back out” of a resource allocation
decision
– By preemption or by killing the process
• This is particularly problematic for lock-based
deadlocks
– System can be in an inconsistent state
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Memory Management
• Linux’s physical memory-management
system deals with allocating and
freeing pages, groups of pages, and
small blocks of memory
• It has additional mechanisms for
handling virtual memory, memory
mapped into the address space of
running processes
• Splits memory into four different zones
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Managing Physical Memory
• The page allocator allocates and frees all
physical pages; it can allocate ranges of
physically-contiguous pages on request
• The allocator uses a buddy-heap algorithm to
keep track of available physical pages
– Each allocatable memory region is paired with an
adjacent partner
– Whenever two allocated partner regions are both
freed up they are combined to form a larger region
– If a small memory request cannot be satisfied
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Managing Physical Memory (Cont.)
• Memory allocations in the Linux kernel occur
either statically (drivers reserve a contiguous area
of memory during system boot time) or
dynamically (via the page allocator)
• Also uses slab allocator for kernel memory
• Page cache and virtual memory system also
manage physical memory
– Page cache is kernel’s main cache for files and main
mechanism for I/O to block devices
– Page cache stores entire pages of file contents
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Splitting of Memory in a Buddy Heap
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Slab Allocator in Linux
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Virtual Memory
• The VM system maintains the address space visible to each
process: It creates pages of virtual memory on demand, and
manages the loading of those pages from disk or their
swapping back out to disk as required.
• The VM manager maintains two separate views of a process’s
address space:
– A logical view describing instructions concerning the layout
of the address space
• The address space consists of a set of non-overlapping
regions, each representing a continuous, page-aligned
subset of the address space
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Virtual Memory (Cont.)
• Virtual memory regions are characterized by:
– The backing store, which describes from where the
pages for a region come; regions are usually backed by a
file or by nothing (demand-zero memory)
– The region’s reaction to writes (page sharing or copy-
on-write
• The kernel creates a new virtual address space
_ When a process runs a new program with the exec()
system call
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Swapping and Paging
• The VM paging system relocates pages of memory from physical
memory out to disk when the memory is needed for something
else
• The VM paging system can be divided into two sections:
– The pageout-policy algorithm decides which pages to write out
to disk, and when
– The paging mechanism actually carries out the transfer, and
pages data back into physical memory as needed
– Can page out to either swap device or normal files
– Bitmap used to track used blocks in swap space kept in physical
memory
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• A program whose necessary library functions are
embedded directly in the program’s executable binary
file is statically linked to its libraries
• The main disadvantage of static linkage is that every
program generated must contain copies of exactly the
same common system library functions
• Dynamic linking is more efficient in terms of both
physical memory and disk-space usage because it loads
the system libraries into memory only once
Static and Dynamic Linking
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Kernel Virtual Memory
• The Linux kernel reserves a constant, architecture-dependent region
of the virtual address space of every process for its own internal use
• This kernel virtual-memory area contains two regions:
– A static area that contains page table references to every available
physical page of memory in the system, so that there is a simple
translation from physical to virtual addresses when running kernel
code
– The reminder of the reserved section is not reserved for any
specific purpose; its page-table entries can be modified to
point to any other areas of memory
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Virtual Memory That is Larger Than Physical Memory
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Virtual-address Space
 Usually design logical address space for
stack to start at Max logical address and
grow “down” while heap grows “up”
 Maximizes address space use
 Unused address space between
the two is hole
 No physical memory needed
until heap or stack grows to a
given new page
 Enables sparse address spaces with
holes left for growth, dynamically linked
libraries, etc
 System libraries shared via mapping into
virtual address space
 Shared memory by mapping pages read-
write into virtual address space
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Shared Library Using Virtual
Memory
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Demand Paging
• Could bring entire process into memory at
load time
• Or bring a page into memory only when it is
needed
– Less I/O needed, no unnecessary I/O
– Less memory needed
– Faster response
– More users
• Similar to paging system with swapping
(diagram on right)
• Page is needed  reference to it
– invalid reference  abort
– not-in-memory  bring to memory
• Lazy swapper – never swaps a page into
memory unless page will be needed
– Swapper that deals with pages is a
pager
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
File Systems
• To the user, Linux’s file system appears as a hierarchical directory tree
obeying UNIX semantics
• Internally, the kernel hides implementation details and manages the
multiple different file systems via an abstraction layer, that is, the virtual
file system (VFS)
• The Linux VFS is designed around object-oriented principles and is
composed of four components:
– A set of definitions that define what a file object is allowed to look
like
• The inode object structure represent an individual file
• The file object represents an open file
• The superblock object represents an entire file system
• A dentry object represents an individual directory entry
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
File Systems (Cont.)
• To the user, Linux’s file system appears as a hierarchical directory tree
obeying UNIX semantics
• Internally, the kernel hides implementation details and manages the
multiple different file systems via an abstraction layer, that is, the virtual
file system (VFS)
• The Linux VFS is designed around object-oriented principles and layer of
software to manipulate those objects with a set of operations on the
objects
– For example for the file object operations include (from struct
file_operations in /usr/include/linux/fs.h
int open(. . .) — Open a file
ssize t read(. . .) — Read from a file
ssize t write(. . .) — Write to a file
int mmap(. . .) — Memory-map a file
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
OVERVIEW
• The file system permits users to create data
collections, called files,with desirable
properties.
• Long-term existence: Files are stored on disk
or other secondary storage and do not
disappear when a user logs off.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• Sharable between processes: Files have names
and can have associated access permissions
that permit controlled sharing.
• Structure: Depending on the file system, a file
can have an internal structure that is
convenient for particular applications. In
addition, files can be organized into hierarchical
or more complex structure to reflect the
relationships among files.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Typical operations include
the following:
• Create: A new file is defined and positioned within the
structure of files.
• Delete: A file is removed from the file structure and
destroyed.
• Open: An existing file is declared to be “opened” by a
process, allowing the process to perform functions on
the file.
• Close: The file is closed with respect to a process, so
that the process no longer may perform functions on
the file, until the process opens the file again.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
FILE ORGANIZATION AND ACCESS
• In choosing a file organization,several criteria
are important:
– Short access time
– Ease of update
– Economy of storage
– Simple maintenance
– Reliability
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
FILE DIRECTORIES
• Associated with any file management system and collection
of files is a file directory. The directory contains information
about the files, including attributes, location, and ownership.
Much of this information, especially that concerned with
M12_STAL6329_06_SE_C12.QXD 2/21/08 9:40 PM Page
56212.3 / FILE DIRECTORIES 563 storage, is managed by the
operating system. The directory is itself a file, accessible by
various file management routines. Although some of the
information in directories is available to users and
applications, this is generally provided indirectly by system
routines.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
FILE SHARING
• The following list is representative of access rights that
can be assigned to a particular user for a particular file:
- None: The user may not even learn of the existence of
the file, much less access it. To enforce this restriction,
the user would not be allowed to read the user
directory that includes this file.
- Knowledge: The user can determine that the file
exists and who its owner is. The user is then able to
petition the owner for additional access rights.
- Execution: The user can load and execute a program
but cannot copy it.Proprietary programs are often
made accessible with this restriction.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Access can be provided to different
classes of users:
• Specific user: Individual users who are
designated by user ID.
• User groups: A set of users who are not
individually defined. The system must have
some way of keeping track of the membership
of user groups.
• All: All users who have access to this system.
These are public files.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Given the size of a block,there are three
methods of blocking that can be used:
• Fixed blocking: Fixed-length records are used, and an
integral number of records are stored in a block. There
may be unused space at the end of each block. This is
referred to as internal fragmentation.
• Variable-length spanned blocking: Variable-length
records are used and are packed into blocks with no
unused space. Thus, some records must span two
blocks, with the continuation indicated by a pointer to
the successor block.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• Variable-length unspanned blocking: Variable-
length records are used, but spanning is not
employed. There is wasted space in most
blocks because of the inability to use the
remainder of a block if the next record is
larger than the remaining unused space.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
What is Unix?
• A multi-task and multi-user Operating System
• Developed in 1969 at AT&T’s Bell Labs by
– Ken Thompson (Unix)
– Dennis Ritchie (C)
– Douglas Mcllroy (Pipes - Do one thing, do it well)
• Some other variants: System V, Solaris, SCO
Unix, SunOS, 4.4BSD, FreeBSD, NetBSD,
OpenBSD, BSDI
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
What is Linux?
• A clone of Unix
• Developed in 1991 by Linus Torvalds, a Finnish graduate
student
• Inspired by and replacement of Minix
• Linus' Minix became Linux
• Consist of
– Linux Kernel
– GNU (GNU is Not Unix) Software
– Software Package management
– Others
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
What is Linux?
• Originally developed for
32-bit x86-based PC
• Ported to other
architectures, eg.
– Alpha, VAX, PowerPC, IBM
S/390, MIPS, IA-64
– PS2, TiVo, cellphones,
watches, Nokia N810, NDS,
routers, NAS, GPS, …
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Which Linux Distribution is better?
• > 300 Linux Distributions
– Slackware (one of the oldest, simple and stable distro.)
– Redhat
• RHEL (commercially support)
• Fedora (free)
– CentOS (free RHEL, based in England)
– SuSe ( based in German)
– Gentoo (Source code based)
– Debian (one of the few called GNU/Linux)
– Ubuntu (based in South Africa)
– Knoppix (first LiveCD distro.)
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Basic Commands
• ls
– $ ls -l
– $ ls -a
– $ ls -la
– $ ls -l --sort=time
– $ ls -l --sort=size -r
• cd
– $ cd /usr/bin
• pwd
– $ pwd
• ~
– $ cd ~
• ~user
– $ cd ~weesan
• What will “cd ~/weesan” do?
• which
– $ which ls
• whereis
– $ whereis ls
• locate
– $ locate stdio.h
– $ locate iostream
• rpm
– $ rpm -q bash
– $ rpm -qa
– $ rpm -qa | sort | less
• find
– $ find / | grep stdio.h
– $ find /usr/include | grep stdio.h
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Basic Commands (cont)
• echo
– $ echo “Hello World”
– $ echo -n “Hello World”
• cat
– $ cat /etc/motd
– $ cat /proc/cpuinfo
• cp
– $ cp foo bar
– $ cp -a foo bar
• mv
– $ mv foo bar
• mkdir
– $ mkdir foo
• rm
– $ rm foo
– $ rm -rf foo
– $ rm -i foo
– $ rm -- -foo
• chgrp
– $ chgrp bar /home/foo
• chsh
– $ chsh foo
• chfn
– $ chfn foo
• chown
– $ chown -R foo:bar /home/foo
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Basic Commands (cont)
• tar
– $ tar cvfp lab1.tar lab1
• gzip
– $ gzip -9 lab1.tar
• untar & ungzip
– $ gzip -cd lab1.tar.gz | tar xvf –
– $ tar xvfz lab1.tar.gz
• touch
– $ touch foo
– $ cat /dev/null > foo
• Pipe
– $ cal > foo
– $ cat /dev/zero > foo
– $ cat < /etc/passwd
– $ who | cut -d’ ‘ -f1 | sort |
uniq | wc –l
• backtick
– $ echo “The date is `date`”
– $ echo `seq 1 10`
• Hard, soft (symbolic) link
– ln vmlinuz-2.6.24.4 vmlinuz
– ln -s firefox-2.0.0.3 firefox
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• Unix Commands:
When you first log into a unix system, you are
presented with something that looks like the
following:
/home/larry#
That “something” is called a prompt. As its name
would suggest, it is prompting you to enter a
command.
Every unix command is a sequence of letters,
numbers and characters.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• Unix is also case-sensitive. This means cat
and Cat are different commands.
• The prompt is displayed by a special
program called the shell. Shells, accept
commands, and run those commands.
• They can also be programmed in their own
language. These are called “shell scripts”.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• Storing Information:
Unix provides files and directories.
A directory is like a folder: it contains pieces of
paper, or files. A large folder can even hold other
folders-directories can be inside directories.
In unix, the collection of directories and files is
called the file system. Initially, the file system
consists of one directory, called the “root”
directory.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• Inside “root” directory, there are more directories,
and inside those directories are files and yet more
directories.
• Each file and each directory has a name. **
• A short name for a file could be joe, while it’s “full
name” would be /home/larry/joe. The full name
is usually called the path.
• The path can be decote into a sequence of
directories.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• The second lesson is more general. Many unix
commands are like ls. They have options, which
are generally one character after a dash, and
they have parameters. Unlike ls, some
commands require certain parameters and/or
options.
• pwd (present working directory) , cd
Unix shells have a feature called the “current” or
“present” or “working” directory.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• If you omit the optional parameter directory,
you’re returned to your home, or original
directory. Otherwise, cd will change you to
the specified directory. **
• Creating and Removing Directories Creating
your own directories is extremely simple
under unix, and can be a useful organizational
tool.
To create a new directory, use the command
mkdir.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• mkdir stands for make directory.
mkdir can take more than one parameter,
interpreting each parameter as another directory
to create.
• The opposite of mkdir is rmdir (remove directory).
rmdir works exactly like mkdir. rmdir will refuse
to remove a non-existant directory, as well as a
directory that has anything in it.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• Moving Information: The primary commands for
manipulating files under unix are cp, mv, and rm. They
stand for copy, move, and remove, respectively.
• cp cp is a very useful utility under unix, and extremely
powerful. It enables one person to copy more information
in a second than a fourteenth century monk could do in a
year.
cp file1 file2
(one of file1 copied to file2 in the same directory)
cp folder1/file1 folder2
(one of file1 copied to file2 in the inside of folder2 directory)
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Some Other UNIX Commands
• The Power of Unix: The power of unix is hidden in
small commands that don’t seem too useful when
used alone, but when combined with other
commands produce a system that’s much more
powerful, and flexible than most other operating
systems. The commands I’m going to talk about in
this chapter include sort, grep, more, cat, wc,
spell, diff, head,and tail.
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
• Operating on Files: In addition to the commands
like cd, mv, and rm you learned in shell section,
there are other commands that just operate on
files, but not the data in them. These include
touch, chmod, du, and df. All of these files don’t
care what is in the file-the merely change some
of the things unix remembers about the file.
Some of the things these commands manipulate:
Chanderprabhu Jain College of Higher Studies & School of Law
Plot No. OCF, Sector A-8, Narela, New Delhi – 110040
(Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
Working with Unix
• Unix is a powerfull system for those who know how
to harness its power. In this chapter, we’ll try to
describe various ways to use Unix’s shell, bash, more
efficently.
• Wildcards
You might want to copy all the files beginning with
data into a directory called ˜backup. You could do
this by either running many cp commands, or you
could list every file on one command line. Both of
these methods would take a long time.

More Related Content

Similar to Introduction to Operating System

Similar to Introduction to Operating System (20)

Operating System
Operating SystemOperating System
Operating System
 
Operating system
Operating systemOperating system
Operating system
 
Introduction to IT
Introduction to ITIntroduction to IT
Introduction to IT
 
Management Information System
Management Information SystemManagement Information System
Management Information System
 
Introduction To Database Management System
Introduction To Database Management SystemIntroduction To Database Management System
Introduction To Database Management System
 
Management Information System
Management Information SystemManagement Information System
Management Information System
 
Computer Architecture
Computer ArchitectureComputer Architecture
Computer Architecture
 
AN INTRODUCTION TO OPERATING SYSTEMS : CONCEPTS AND PRACTICE - PHI Learning
AN INTRODUCTION TO OPERATING SYSTEMS : CONCEPTS AND PRACTICE - PHI LearningAN INTRODUCTION TO OPERATING SYSTEMS : CONCEPTS AND PRACTICE - PHI Learning
AN INTRODUCTION TO OPERATING SYSTEMS : CONCEPTS AND PRACTICE - PHI Learning
 
Software Engineering
Software EngineeringSoftware Engineering
Software Engineering
 
SOFTWARE ENGINEERING
SOFTWARE ENGINEERING SOFTWARE ENGINEERING
SOFTWARE ENGINEERING
 
Computer architecture BCA 203
Computer architecture BCA 203Computer architecture BCA 203
Computer architecture BCA 203
 
Computer networks BBA(CAM) 209
Computer networks BBA(CAM)  209Computer networks BBA(CAM)  209
Computer networks BBA(CAM) 209
 
Software Engineering
Software EngineeringSoftware Engineering
Software Engineering
 
Operating Systems
Operating SystemsOperating Systems
Operating Systems
 
OPERATING SYSTEM
OPERATING SYSTEMOPERATING SYSTEM
OPERATING SYSTEM
 
Production Management & Total Quality Management
Production Management & Total Quality ManagementProduction Management & Total Quality Management
Production Management & Total Quality Management
 
Introduction to IT
Introduction to ITIntroduction to IT
Introduction to IT
 
Kernel security Concepts
Kernel security ConceptsKernel security Concepts
Kernel security Concepts
 
Linux environment
Linux environment Linux environment
Linux environment
 
Introduction To Computer Network
Introduction To Computer NetworkIntroduction To Computer Network
Introduction To Computer Network
 

More from cpjcollege

More from cpjcollege (20)

Tax Law (LLB-403)
Tax Law (LLB-403)Tax Law (LLB-403)
Tax Law (LLB-403)
 
Law and Emerging Technology (LLB -405)
 Law and Emerging Technology (LLB -405) Law and Emerging Technology (LLB -405)
Law and Emerging Technology (LLB -405)
 
Law of Crimes-I ( LLB -205)
 Law of Crimes-I  ( LLB -205)  Law of Crimes-I  ( LLB -205)
Law of Crimes-I ( LLB -205)
 
Socio-Legal Dimensions of Gender (LLB-507 & 509 )
Socio-Legal Dimensions of Gender (LLB-507 & 509 )Socio-Legal Dimensions of Gender (LLB-507 & 509 )
Socio-Legal Dimensions of Gender (LLB-507 & 509 )
 
Family Law-I ( LLB -201)
Family Law-I  ( LLB -201) Family Law-I  ( LLB -201)
Family Law-I ( LLB -201)
 
Alternative Dispute Resolution (ADR) [LLB -309]
Alternative Dispute Resolution (ADR) [LLB -309] Alternative Dispute Resolution (ADR) [LLB -309]
Alternative Dispute Resolution (ADR) [LLB -309]
 
Law of Evidence (LLB-303)
Law of Evidence  (LLB-303) Law of Evidence  (LLB-303)
Law of Evidence (LLB-303)
 
Environmental Studies and Environmental Laws (: LLB -301)
Environmental Studies and Environmental Laws (: LLB -301)Environmental Studies and Environmental Laws (: LLB -301)
Environmental Studies and Environmental Laws (: LLB -301)
 
Code of Civil Procedure (LLB -307)
 Code of Civil Procedure (LLB -307) Code of Civil Procedure (LLB -307)
Code of Civil Procedure (LLB -307)
 
Constitutional Law-I (LLB -203)
 Constitutional Law-I (LLB -203) Constitutional Law-I (LLB -203)
Constitutional Law-I (LLB -203)
 
Women and Law [LLB 409 (c)]
Women and Law [LLB 409 (c)]Women and Law [LLB 409 (c)]
Women and Law [LLB 409 (c)]
 
Corporate Law ( LLB- 305)
Corporate Law ( LLB- 305)Corporate Law ( LLB- 305)
Corporate Law ( LLB- 305)
 
Human Rights Law ( LLB -407)
 Human Rights Law ( LLB -407) Human Rights Law ( LLB -407)
Human Rights Law ( LLB -407)
 
Labour Law-I (LLB 401)
 Labour Law-I (LLB 401) Labour Law-I (LLB 401)
Labour Law-I (LLB 401)
 
Legal Ethics and Court Craft (LLB 501)
 Legal Ethics and Court Craft (LLB 501) Legal Ethics and Court Craft (LLB 501)
Legal Ethics and Court Craft (LLB 501)
 
Political Science-II (BALLB- 209)
Political Science-II (BALLB- 209)Political Science-II (BALLB- 209)
Political Science-II (BALLB- 209)
 
Health Care Law ( LLB 507 & LLB 509 )
Health Care Law ( LLB 507 & LLB 509 )Health Care Law ( LLB 507 & LLB 509 )
Health Care Law ( LLB 507 & LLB 509 )
 
Land and Real Estate Laws (LLB-505)
Land and Real Estate Laws (LLB-505)Land and Real Estate Laws (LLB-505)
Land and Real Estate Laws (LLB-505)
 
Business Environment and Ethical Practices (BBA LLB 213 )
Business Environment and Ethical Practices (BBA LLB 213 )Business Environment and Ethical Practices (BBA LLB 213 )
Business Environment and Ethical Practices (BBA LLB 213 )
 
HUMAN RESOURCE MANAGEMENT (BBA LLB215 )
HUMAN RESOURCE MANAGEMENT (BBA LLB215 )HUMAN RESOURCE MANAGEMENT (BBA LLB215 )
HUMAN RESOURCE MANAGEMENT (BBA LLB215 )
 

Recently uploaded

Recently uploaded (20)

HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 

Introduction to Operating System

  • 1. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Semester: First Semester Name of the Subject: Introduction to Operating System
  • 2. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) DEFINITION • An operating system is an intermediary between a computer user and the hardware. • Make the hardware convenient to use. • Manages system resources. • Use the hardware in an efficient manner
  • 3. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • The main functions of operating systems are: • • Manages and Interacts with Computer Hardware • • Process the tasks • • Provides the User/ Computer Interface (CLI / GUI) • • Provides the Interface for Application Software • • Input / Output Operations • • Error Detection, Resource Allocation, Security and • Protection FUNCTION
  • 4. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • Batch – submit large number of jobs at one time – system decides what to run and when • Time Sharing – multiple users connected to single machine – few processors, many terminals • Single User Interactive – one user, one machine TYPES OF OS
  • 5. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • Parrallel – traditional multiprocessor system – higher throughput and better fault tolerance • Distributed – networked computers • Real Time – very strict response time requirements – hardware or software
  • 6. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • Only one program can perform at a time • Simple to implement – only one process attempting to use resources • Few security risks • Poor utilization of the CPU and other resources • Example: MS-DOS FUNCTION
  • 7. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • Very complex • Serious security issues – how to protect one program from another sharing the same memory • Much higher utilization of system resources • Example: Unix, Windows NT Multi tasking
  • 8. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • OS and hardware closely tied together • Many useful hardware features have been invented to compliment the OS • Basic hardware resources – CPU – Memory – Disk – I/O Hardware basics
  • 9. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • CPU controls everything in the system – if work needs to be done, CPU gets involved • Most precious resource – this is what your paying for – want to get high utilization (from useful work) • Only one process on a CPU at a time • Hundreds of millions of instructions / sec – and getting faster all the time CPU
  • 10. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • Limitted in capacity – never enough memory • Temporary (volatile) storage • Electronic storage – fast, random access • Any program to run on the CPU must be in memory MEMORY
  • 11. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • Virtually infinite capacity • Permanent storage • Orders of magnitude slower than memory – mechanical device – millions of CPU instructions can execute in the time it takes to access a single piece of data on disk • All data is accessed in blocks – usually 512 bytes DISK
  • 12. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • Disk is actually part of the I/O subsystem – they are of special interest to the OS • Many other I/O devices – printers, monitor, keyboard, etc. • Most I/O devices are painfully slow • Need to find ways to hide I/O latency – like multiprogramming I/O
  • 13. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • OS must protect itself from users – reserved memory only accessible by OS – hardware enforced • OS may protect users from one another – not all systems do this – hardware enforced again PROTECTION AND SECURITY
  • 14. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • Dual -Mode Operation – user mode • limited set of hardware instr and memory available • mode all user programs run in – supervisory mode • all hardware instr and memory are available • mode the OS runs in • Never let user run in supervisory mode PROTECTION AND SECURITY
  • 15. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • Modern OS’s are event driven • Event is signaled by special hardware signal sent to the CPU • Two types of events – interrupts • caused by external devices or timers • can occur at any moment in time – exceptions (traps) • caused by software – the generic term for both is Interrupt • sorry for the confusion INTERRUPPTS
  • 16. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • One way to handle interrupts is with one standard program – big case-switch statement that gets executed on any interrupt – inefficient • Second alternative is to use an interrupt table and special hardware – this is the way modern systems operate INTERRUPT PHILOSOPHY
  • 17. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • Large array indicating what code to run for a given interrupt • Each interrupt has a corresponding number associated with it – on Intel processors this is from 0 to 255 – this gives fixed size interrupt table • Use the interrupt number to index into the array to find out what code to run INTERRUPT TABLE
  • 18. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • Programmable Interrupt Controller (PIC) – connected to I/O devices via interrupt request lines (IRQ) • ideally, one IRQ for each I/O device - doesn’t work this way in reality • PIC connected to CPU by a special signal • PIC also connected to CPU via I/O bus • Besides the PIC, interrupts can also be generated by software instructions or errors – again, these are usually referred to as exceptions INTERRUPT HARDWARE
  • 19. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • After each instruction executes, CPU checks to see if interrupt pin has been raised • If so, the following occurs: 1) sets the system into kernel mode (if not already there) 2) determine interrupt number (from PIC or instruction) 3) read appropriate interrupt table entry - special register contains base address of interrupt table - each entry in table is fixed size so easy to calculate where to look in memory ( memLoc = idtr + 8 * intNum ) 4) saves the program counter to the stack (with a couple of others) 5) saves error code to stack (if it exists) 6) loads the program counter with the value stored in the TABLE. HARDWARE HANDLING OF INTERRUPT
  • 20. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • The following 6 steps are common to all interrupt handlers: 1) save IRQ to kernel mode stack 2) save registers to kernel mode stack 3) send acknowledgement to PIC - this allows PIC to then handle other interrupts on IRQ line 4) execute the appropriate handler code 5) restore registers 6) issue an iret instruction • The steps for exception handlers are almost identical – simply remove steps 1 & 3 above Software handaling interrupt
  • 21. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • As indicated earlier, exceptions are caused by software – divide by zero error – page fault – int instruction – etc • Some of these cause the program to stop executing • Some of them invoke special operating system code that is invisible to the user • Some of them invoke operating system code at the user’s request – system calls More of exception
  • 22. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • The number of IRQ lines is usually limited • May have more I/O devices than IRQ’s • Solution: let multiple devices share an IRQ • Interrupt table contains a pointer to a linked list of interrupt handlers – instead of the address of the interrupt handler • On interrupt, execute all of the handlers associated with an IRQ – requires handlers to recognize Ingle IRQ for multiple device
  • 23. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) EXAMPLE Interrupt Table 0 1 2 3 4 5 6 7 8 9 floppy disk printer scanner camera hard disk
  • 24. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • Assume an interrupt from the scanner arrives at the PIC 1) PIC raises INTR signal on CPU 2) CPU reads PIC over I/O bus to determine IRQ 3) CPU then accesses array in memory to get the first interrupt handler - printer 4) CPU executes printer handler code 5) printer handler queries printer and notices there is no interrupt pending - handler returns immediately 6) next the scanner handler gets executed 7) scanner handler queries scanner and notices there is an interrupt pending EXAMPLE
  • 25. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • An OS’s system calls are called the Application Programmers Interface (API) • System calls are routines run by the OS on behalf of the user • They are run in supervisory mode • Allow user to access I/O, create processes, get system information, etc. • How many system calls an OS has varies – Unix: around a hundred System calls
  • 26. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • On power up – everything in system is in random, unpredictable state – special hardware circuit raises RESET pin of CPU • sets the program counter to 0xfffffff0 – this address is mapped to ROM (Read-Only Memory) • BIOS (Basic Input/Output Stream) – set of programs stored in ROM – some OS’s use only these programs • MS DOS – many modern systems use these programs to load other system programs • Windows, Unix, Linux System startups
  • 27. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • General operations performed by BIOS 1) find and test hardware devices - POST (Power-On Self-Test) 2) initialize hardware devices - creates a table of installed devices 3) find boot sector - may be on floppy, hard drive, or CD-ROM 4) load boot sector into memory location 0x00007c00 5) sets the program counter to 0x00007c00 - starts executing code at that address BIOS
  • 28. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • Small program stored in boot sector • Loaded by BIOS at location 0x00007c0 • Configure a basic file system to allow system to read from disk • Loads kernel into memory • Also loads another program that will begin kernel initialization BOOT LEADER
  • 29. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • Determines amount of RAM in system – uses a BIOS function to do this • Configures hardware devices – video card, mouse, disks, etc. – BIOS may have done this but usually redo it • portability • Switches the CPU from real to protected mode – real mode: fixed segment sizes, 1 MB memory addressing, and no segment protection – protected mode: variable segment sizes, 4 GB memory addressing, and provides segment protection • Initializes paging (virtual memory) INITIAL KERNEL PROGRAM
  • 30. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • Sets up page tables and segment descriptor tables – these are used by virtual memory and segmentation hardware (more on this later) • Sets up interrupt vector and enables interrupts • Initializes all other kernel data structures • Creates initial process and starts it running – init in Linux – smss (Session Manager SubSystem) in NT FINAL KERNEL PROGRAM
  • 31. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • Application programs included with the OS • Highly trusted programs • Perform useful work that most users need – listing and deleting files, configuring system – ls, rm, Windows Explorer and Control Panel – may include compilers and text editors • Not part of the OS – run in user space SYSTEM PROGRAM
  • 32. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Processes: The Process Model  Multiprogramming of four programs  Conceptual model of 4 independent, sequential processes  Only one program active at any instant
  • 33. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Processes and programs The difference between a process and a program:  Baking analogy: o Recipe = Program o Baker = Processor o Ingredients = data o Baking the cake = Process  Interrupt analogy o The baker’s son runs in with a wounded hand o First aid guide = interrupt code
  • 34. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Main OS Process-related Goals  Interleave the execution of existing processes to maximize processor utilization  Provide reasonable response times  Allocate resources to processes  Support inter-process communication (and synchronization) and user creation of processes
  • 35. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) How are these goals achieved?  Schedule and dispatch processes for execution by the processor  Implement a safe and fair policy for resource allocation to processes  Respond to requests by user programs  Construct and maintain tables for each process managed by the operating system
  • 36. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Process Creation When is a new process created? 1. System initialization (Daemons) 2. Execution of a process creation system call by a running process 3. A user request to create a process 4. Initiation of a batch job
  • 37. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Process States  Running - actually using the CPU  Ready – runnable, temporarily stopped to let another process run  Blocked - unable to run until some external event happens A process can block itself, but not “run” itself
  • 38. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Process State Transitions When do these transitions occur? 1. Process blocks for input or waits for an event 2. End of time-slice, or preemption 3. Scheduler switches back to this process 4. Input becomes available, event arrives
  • 39. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Suspended Processes  Processor is much faster than I/O so many processes could be waiting for I/O  Swap some of these processes to disk to free up more memory  Blocked state becomes blocked-suspended state when swapped to disk, ready becomes ready-suspended  Two new states o Blocked-suspended o Ready-suspended
  • 40. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Process Management Operations Process creation and termination  Process scheduling and dispatching  Process switching  Process synchronization and support for inter- process communication The OS maintains process data in the Process Control Blocks (PCB)
  • 41. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Process Table  Process image consists of program (code/text), data, stack, and attributes  Control Attributes form the Process Control Block - PCB o Unique ID (may be an index into the PT) o User ID; User group ID, Parent process ID o process control information o Processor state information
  • 42. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Process Control Information Additional information needed by the operating system to control and coordinate the various active processes o Execution state: see next slide… o Scheduling-related information - state; priority; scheduling info o inter-process communication - signals; pipes o Time of next alarm o memory management - pointers to text/data/stack segments o resource ownership and utilization - open files o Process relationships: Parent, process group… o Environment variables
  • 43. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Process Creation  Assign a unique process identifier  Allocate space for the process  Initialize process control block  Set up appropriate linkage to the scheduling queue: o In the former example: add the PCB to the ready queue
  • 44. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Stop a running process  Clock event: process has executed a full time-slice (a.k.a. time-quantum)  Process becomes blocked  Another process is ready  Error occurred  Signal received
  • 45. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Process Context Switch  Save processor context, including program counter and other registers  Update the process control block with the new state and any accounting information  Move process control block to appropriate queue - ready, blocked  Select another process for execution  Update the process control block of the process selected  Update memory-management data structures  Restore context of selected process
  • 46. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Inter-Process Communication  Shared memory – the fastest way o Need to avoid race conditions  Non-shared Memory: o File/Pipes o Unbuffered messages - Rendezvous o Buffered messages – Mailboxes and Sockets o Sockets: Address – Domain+Port o Sockets: Types – Stream or Datagrams o Sockets: API: Socket, Bind, Connect, Read/Write
  • 47. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Scheduling • Assign each process time to use CPU – Determine sequence (order), timing (when) – Conflicting objectives  need compromise • Scheduling levels – High: whether to admit a new process – Medium: suspend/resume a process – Low: dispatch (run) a ready process
  • 48. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Scheduling Objectives • Maximise throughput • Give all users a “fair” (not equal) chance • Provide tolerable performance – Response time for on-line user – Turnaround time for batch users • Degrade performance gracefully – OK to be slow but avoid complete collapse • Be consistent, predictable over time
  • 49. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Scheduling Criteria • Priority which may be either/both: – Assigned to job by user – Determined by properties of the job • Class of job (real-time > on-line > batch) • Resources needed (CPU time, memory) • I/O or CPU bound (the aim is a balance) • Resources already used • Time already waited
  • 50. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Types of Scheduling Policies • Preemptive (Used by most OS today) – OS stops one process to run another • Non-preemptive – process runs until termination or I/O wait • Cooperative (Used by Windows 3.11) – Programs must voluntarily give up CPU – Not managed by OS; trusts programmers – If a process hangs the whole PC hangs 
  • 51. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Scheduling Policies • First come first served (FCFS/FIFO) • Shortest job first (SJF) • Shortest remaining time (SRT) • Highest response ratio next • Round robin (RR) • Multi-level feedback queues (MFQ)
  • 52. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) First come first served • Also called first in first out (FIFO) • Process waiting longest is first in queue • Favours long jobs – high run-time/wait-time ratio • Favours CPU-bound jobs – I/O devices underused
  • 53. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Shortest job first (next) • Run job with shortest estimated run time • Long jobs may be delayed indefinitely • JCL commands can specify run time
  • 54. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Shortest remaining time • Run job w/ shortest est. remaining time • Highly favours short jobs • Long jobs will be delayed indefinitely • Requires estimating total run time • Requires measuring elapsed run time
  • 55. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Highest response ratio next • P = (time waiting + run time) / run time • Priority based on two factors • Favours shorter jobs • Guarantees a job cannot be starved
  • 56. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Round Robin • Each process given a set time slice • Pre-emption at end of time quantum – Hardware timer generates interrupts • After running, go to back of queue • Used in most interactive operating systems • How large should each time slice be? – Small  high context switch overhead – Large  user response time is reduced – In practice, about 10-20 ms
  • 57. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Multi-level feedback queues • Separate queues for different priorities – New process  level 1 FIFO (highest) – After timeout  level 2 FIFO, etc. – Lowest level is Round Robin • Adapts to past process behaviours – high CPU usage  reduced access level • Long processes may starve – if wait time is long, promote/increase slice
  • 58. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Deadlock • Each thread is waiting on a resource held by another thread – So, there is no way to make progress
  • 59. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Deadlock • Examples: Traffic Jam : • Dining Philosophers • Device allocation – process 1 requests tape drive 1 & gets it – process 2 requests tape drive 2 & gets it
  • 60. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Necessary Conditions for Deadlock • Mutual exclusion – Resources cannot be shared • e.g., buffers, locks • Hold and wait (subset property) – A thread must hold a subset of its resource needs • And, the thread is waiting for more resources • No preemption – Resources cannot be taken away • Circular wait – A needs a resource that B has
  • 61. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Resource Allocation Graph with a Deadlock P => R: request edge R => P: assignment edge
  • 62. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Cycle Without Deadlock P => R: request edge R => P: assignment edge
  • 63. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Approaches to Deadlock 1. Avoid threads 2. Deadlock prevention – Break up one of the four necessary conditions 3. Deadlock avoidance – Stay live even in the presence of the four conditions 4. Detect and recover
  • 64. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Deadlock Detection • Detection algorithm (sketch) – Keep track of who is waiting for resources – Keep track of who holds resources – Assume that all runnable processes release all their resources • Does this unblock a waiting process? – If yes, release that process’s resources – If processes are still blocked, we are deadlocked
  • 65. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Recovery • Must “back out” of a resource allocation decision – By preemption or by killing the process • This is particularly problematic for lock-based deadlocks – System can be in an inconsistent state
  • 66. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Memory Management • Linux’s physical memory-management system deals with allocating and freeing pages, groups of pages, and small blocks of memory • It has additional mechanisms for handling virtual memory, memory mapped into the address space of running processes • Splits memory into four different zones
  • 67. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Managing Physical Memory • The page allocator allocates and frees all physical pages; it can allocate ranges of physically-contiguous pages on request • The allocator uses a buddy-heap algorithm to keep track of available physical pages – Each allocatable memory region is paired with an adjacent partner – Whenever two allocated partner regions are both freed up they are combined to form a larger region – If a small memory request cannot be satisfied
  • 68. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Managing Physical Memory (Cont.) • Memory allocations in the Linux kernel occur either statically (drivers reserve a contiguous area of memory during system boot time) or dynamically (via the page allocator) • Also uses slab allocator for kernel memory • Page cache and virtual memory system also manage physical memory – Page cache is kernel’s main cache for files and main mechanism for I/O to block devices – Page cache stores entire pages of file contents
  • 69. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Splitting of Memory in a Buddy Heap
  • 70. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Slab Allocator in Linux
  • 71. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Virtual Memory • The VM system maintains the address space visible to each process: It creates pages of virtual memory on demand, and manages the loading of those pages from disk or their swapping back out to disk as required. • The VM manager maintains two separate views of a process’s address space: – A logical view describing instructions concerning the layout of the address space • The address space consists of a set of non-overlapping regions, each representing a continuous, page-aligned subset of the address space
  • 72. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Virtual Memory (Cont.) • Virtual memory regions are characterized by: – The backing store, which describes from where the pages for a region come; regions are usually backed by a file or by nothing (demand-zero memory) – The region’s reaction to writes (page sharing or copy- on-write • The kernel creates a new virtual address space _ When a process runs a new program with the exec() system call
  • 73. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Swapping and Paging • The VM paging system relocates pages of memory from physical memory out to disk when the memory is needed for something else • The VM paging system can be divided into two sections: – The pageout-policy algorithm decides which pages to write out to disk, and when – The paging mechanism actually carries out the transfer, and pages data back into physical memory as needed – Can page out to either swap device or normal files – Bitmap used to track used blocks in swap space kept in physical memory
  • 74. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • A program whose necessary library functions are embedded directly in the program’s executable binary file is statically linked to its libraries • The main disadvantage of static linkage is that every program generated must contain copies of exactly the same common system library functions • Dynamic linking is more efficient in terms of both physical memory and disk-space usage because it loads the system libraries into memory only once Static and Dynamic Linking
  • 75. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Kernel Virtual Memory • The Linux kernel reserves a constant, architecture-dependent region of the virtual address space of every process for its own internal use • This kernel virtual-memory area contains two regions: – A static area that contains page table references to every available physical page of memory in the system, so that there is a simple translation from physical to virtual addresses when running kernel code – The reminder of the reserved section is not reserved for any specific purpose; its page-table entries can be modified to point to any other areas of memory
  • 76. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Virtual Memory That is Larger Than Physical Memory
  • 77. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Virtual-address Space  Usually design logical address space for stack to start at Max logical address and grow “down” while heap grows “up”  Maximizes address space use  Unused address space between the two is hole  No physical memory needed until heap or stack grows to a given new page  Enables sparse address spaces with holes left for growth, dynamically linked libraries, etc  System libraries shared via mapping into virtual address space  Shared memory by mapping pages read- write into virtual address space
  • 78. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Shared Library Using Virtual Memory
  • 79. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Demand Paging • Could bring entire process into memory at load time • Or bring a page into memory only when it is needed – Less I/O needed, no unnecessary I/O – Less memory needed – Faster response – More users • Similar to paging system with swapping (diagram on right) • Page is needed  reference to it – invalid reference  abort – not-in-memory  bring to memory • Lazy swapper – never swaps a page into memory unless page will be needed – Swapper that deals with pages is a pager
  • 80. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) File Systems • To the user, Linux’s file system appears as a hierarchical directory tree obeying UNIX semantics • Internally, the kernel hides implementation details and manages the multiple different file systems via an abstraction layer, that is, the virtual file system (VFS) • The Linux VFS is designed around object-oriented principles and is composed of four components: – A set of definitions that define what a file object is allowed to look like • The inode object structure represent an individual file • The file object represents an open file • The superblock object represents an entire file system • A dentry object represents an individual directory entry
  • 81. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) File Systems (Cont.) • To the user, Linux’s file system appears as a hierarchical directory tree obeying UNIX semantics • Internally, the kernel hides implementation details and manages the multiple different file systems via an abstraction layer, that is, the virtual file system (VFS) • The Linux VFS is designed around object-oriented principles and layer of software to manipulate those objects with a set of operations on the objects – For example for the file object operations include (from struct file_operations in /usr/include/linux/fs.h int open(. . .) — Open a file ssize t read(. . .) — Read from a file ssize t write(. . .) — Write to a file int mmap(. . .) — Memory-map a file
  • 82. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) OVERVIEW • The file system permits users to create data collections, called files,with desirable properties. • Long-term existence: Files are stored on disk or other secondary storage and do not disappear when a user logs off.
  • 83. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • Sharable between processes: Files have names and can have associated access permissions that permit controlled sharing. • Structure: Depending on the file system, a file can have an internal structure that is convenient for particular applications. In addition, files can be organized into hierarchical or more complex structure to reflect the relationships among files.
  • 84. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Typical operations include the following: • Create: A new file is defined and positioned within the structure of files. • Delete: A file is removed from the file structure and destroyed. • Open: An existing file is declared to be “opened” by a process, allowing the process to perform functions on the file. • Close: The file is closed with respect to a process, so that the process no longer may perform functions on the file, until the process opens the file again.
  • 85. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 86. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) FILE ORGANIZATION AND ACCESS • In choosing a file organization,several criteria are important: – Short access time – Ease of update – Economy of storage – Simple maintenance – Reliability
  • 87. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 88. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) FILE DIRECTORIES • Associated with any file management system and collection of files is a file directory. The directory contains information about the files, including attributes, location, and ownership. Much of this information, especially that concerned with M12_STAL6329_06_SE_C12.QXD 2/21/08 9:40 PM Page 56212.3 / FILE DIRECTORIES 563 storage, is managed by the operating system. The directory is itself a file, accessible by various file management routines. Although some of the information in directories is available to users and applications, this is generally provided indirectly by system routines.
  • 89. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India)
  • 90. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) FILE SHARING • The following list is representative of access rights that can be assigned to a particular user for a particular file: - None: The user may not even learn of the existence of the file, much less access it. To enforce this restriction, the user would not be allowed to read the user directory that includes this file. - Knowledge: The user can determine that the file exists and who its owner is. The user is then able to petition the owner for additional access rights. - Execution: The user can load and execute a program but cannot copy it.Proprietary programs are often made accessible with this restriction.
  • 91. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Access can be provided to different classes of users: • Specific user: Individual users who are designated by user ID. • User groups: A set of users who are not individually defined. The system must have some way of keeping track of the membership of user groups. • All: All users who have access to this system. These are public files.
  • 92. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Given the size of a block,there are three methods of blocking that can be used: • Fixed blocking: Fixed-length records are used, and an integral number of records are stored in a block. There may be unused space at the end of each block. This is referred to as internal fragmentation. • Variable-length spanned blocking: Variable-length records are used and are packed into blocks with no unused space. Thus, some records must span two blocks, with the continuation indicated by a pointer to the successor block.
  • 93. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • Variable-length unspanned blocking: Variable- length records are used, but spanning is not employed. There is wasted space in most blocks because of the inability to use the remainder of a block if the next record is larger than the remaining unused space.
  • 94. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) What is Unix? • A multi-task and multi-user Operating System • Developed in 1969 at AT&T’s Bell Labs by – Ken Thompson (Unix) – Dennis Ritchie (C) – Douglas Mcllroy (Pipes - Do one thing, do it well) • Some other variants: System V, Solaris, SCO Unix, SunOS, 4.4BSD, FreeBSD, NetBSD, OpenBSD, BSDI
  • 95. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) What is Linux? • A clone of Unix • Developed in 1991 by Linus Torvalds, a Finnish graduate student • Inspired by and replacement of Minix • Linus' Minix became Linux • Consist of – Linux Kernel – GNU (GNU is Not Unix) Software – Software Package management – Others
  • 96. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) What is Linux? • Originally developed for 32-bit x86-based PC • Ported to other architectures, eg. – Alpha, VAX, PowerPC, IBM S/390, MIPS, IA-64 – PS2, TiVo, cellphones, watches, Nokia N810, NDS, routers, NAS, GPS, …
  • 97. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Which Linux Distribution is better? • > 300 Linux Distributions – Slackware (one of the oldest, simple and stable distro.) – Redhat • RHEL (commercially support) • Fedora (free) – CentOS (free RHEL, based in England) – SuSe ( based in German) – Gentoo (Source code based) – Debian (one of the few called GNU/Linux) – Ubuntu (based in South Africa) – Knoppix (first LiveCD distro.)
  • 98. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Basic Commands • ls – $ ls -l – $ ls -a – $ ls -la – $ ls -l --sort=time – $ ls -l --sort=size -r • cd – $ cd /usr/bin • pwd – $ pwd • ~ – $ cd ~ • ~user – $ cd ~weesan • What will “cd ~/weesan” do? • which – $ which ls • whereis – $ whereis ls • locate – $ locate stdio.h – $ locate iostream • rpm – $ rpm -q bash – $ rpm -qa – $ rpm -qa | sort | less • find – $ find / | grep stdio.h – $ find /usr/include | grep stdio.h
  • 99. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Basic Commands (cont) • echo – $ echo “Hello World” – $ echo -n “Hello World” • cat – $ cat /etc/motd – $ cat /proc/cpuinfo • cp – $ cp foo bar – $ cp -a foo bar • mv – $ mv foo bar • mkdir – $ mkdir foo • rm – $ rm foo – $ rm -rf foo – $ rm -i foo – $ rm -- -foo • chgrp – $ chgrp bar /home/foo • chsh – $ chsh foo • chfn – $ chfn foo • chown – $ chown -R foo:bar /home/foo
  • 100. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Basic Commands (cont) • tar – $ tar cvfp lab1.tar lab1 • gzip – $ gzip -9 lab1.tar • untar & ungzip – $ gzip -cd lab1.tar.gz | tar xvf – – $ tar xvfz lab1.tar.gz • touch – $ touch foo – $ cat /dev/null > foo • Pipe – $ cal > foo – $ cat /dev/zero > foo – $ cat < /etc/passwd – $ who | cut -d’ ‘ -f1 | sort | uniq | wc –l • backtick – $ echo “The date is `date`” – $ echo `seq 1 10` • Hard, soft (symbolic) link – ln vmlinuz-2.6.24.4 vmlinuz – ln -s firefox-2.0.0.3 firefox
  • 101. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • Unix Commands: When you first log into a unix system, you are presented with something that looks like the following: /home/larry# That “something” is called a prompt. As its name would suggest, it is prompting you to enter a command. Every unix command is a sequence of letters, numbers and characters.
  • 102. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • Unix is also case-sensitive. This means cat and Cat are different commands. • The prompt is displayed by a special program called the shell. Shells, accept commands, and run those commands. • They can also be programmed in their own language. These are called “shell scripts”.
  • 103. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • Storing Information: Unix provides files and directories. A directory is like a folder: it contains pieces of paper, or files. A large folder can even hold other folders-directories can be inside directories. In unix, the collection of directories and files is called the file system. Initially, the file system consists of one directory, called the “root” directory.
  • 104. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • Inside “root” directory, there are more directories, and inside those directories are files and yet more directories. • Each file and each directory has a name. ** • A short name for a file could be joe, while it’s “full name” would be /home/larry/joe. The full name is usually called the path. • The path can be decote into a sequence of directories.
  • 105. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • The second lesson is more general. Many unix commands are like ls. They have options, which are generally one character after a dash, and they have parameters. Unlike ls, some commands require certain parameters and/or options. • pwd (present working directory) , cd Unix shells have a feature called the “current” or “present” or “working” directory.
  • 106. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • If you omit the optional parameter directory, you’re returned to your home, or original directory. Otherwise, cd will change you to the specified directory. ** • Creating and Removing Directories Creating your own directories is extremely simple under unix, and can be a useful organizational tool. To create a new directory, use the command mkdir.
  • 107. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • mkdir stands for make directory. mkdir can take more than one parameter, interpreting each parameter as another directory to create. • The opposite of mkdir is rmdir (remove directory). rmdir works exactly like mkdir. rmdir will refuse to remove a non-existant directory, as well as a directory that has anything in it.
  • 108. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • Moving Information: The primary commands for manipulating files under unix are cp, mv, and rm. They stand for copy, move, and remove, respectively. • cp cp is a very useful utility under unix, and extremely powerful. It enables one person to copy more information in a second than a fourteenth century monk could do in a year. cp file1 file2 (one of file1 copied to file2 in the same directory) cp folder1/file1 folder2 (one of file1 copied to file2 in the inside of folder2 directory)
  • 109. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Some Other UNIX Commands • The Power of Unix: The power of unix is hidden in small commands that don’t seem too useful when used alone, but when combined with other commands produce a system that’s much more powerful, and flexible than most other operating systems. The commands I’m going to talk about in this chapter include sort, grep, more, cat, wc, spell, diff, head,and tail.
  • 110. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) • Operating on Files: In addition to the commands like cd, mv, and rm you learned in shell section, there are other commands that just operate on files, but not the data in them. These include touch, chmod, du, and df. All of these files don’t care what is in the file-the merely change some of the things unix remembers about the file. Some of the things these commands manipulate:
  • 111. Chanderprabhu Jain College of Higher Studies & School of Law Plot No. OCF, Sector A-8, Narela, New Delhi – 110040 (Affiliated to Guru Gobind Singh Indraprastha University and Approved by Govt of NCT of Delhi & Bar Council of India) Working with Unix • Unix is a powerfull system for those who know how to harness its power. In this chapter, we’ll try to describe various ways to use Unix’s shell, bash, more efficently. • Wildcards You might want to copy all the files beginning with data into a directory called ˜backup. You could do this by either running many cp commands, or you could list every file on one command line. Both of these methods would take a long time.