Survey Paper # 1

Download Report

Transcript Survey Paper # 1

Survey Paper # 1
Modern Operating Systems
Unix
by
Sajida Begum
Samina F Choudhry
1
Outline
•
•
•
•
•
•
Brief History of UNIX
Goals of UNIX
Processes and Processes Management
Memory Management
File System Architecture and Management
Interprocess Communication
2
Brief History of UNIX
• 1960’s : MULTICS ( Multiplexed Operating and Computing
System)
by General Electric, Massachusetts Institute for Technology
and Bell Laboratories
• 1969: UNICS (Uniplexed Operating and Computing System )by
Bell Labs .Though the OS has changed, the name stuck and
was shortened to Unix
• 1973 : rewritten in ‘C’ language.
• 1974 : 5th addition of UNIX
• 1978 : 7th addition ; a dividing point for SVR4(System V) and
BSD
• BSD : Berkley version of UNIX
3
• Linux :Borrows from both SVR4 and BSD
Features of UNIX
UNIX is an operating system made by programmers
to programmers.

Multitasking capability.

Multi-user capability.

Portability.

Easy to understand.
 Written in High-level language rather that
assembly language.
 Open system.
4
Processes & Process Management
Process :
• The process is OS abstraction for execution.
- A process is a program (file).
- It is a unit of execution.
- It is a dynamic execution context of a program.
• A process is sometimes called a job or a task or a
sequential process.
• A sequential process is a program in execution
-It defines the sequential, instruction-at-a-time
execution of a program.
5
Process Components
A process contains all of the state for a program in
execution.
• An address space.
• The code for the executing program.
• The data for the executing program.
• An executing stack encapsulating the state of
procedure calls.
• The program counter (PC) indicating the next
instruction.
• A set of general-purpose registers with current
value.
• Operating system resources like open file, n/w
connections etc.
6
Process state
The process has an execution state that indicates what
it is doing currently ?
• Running : Executing instructions on the CPU
- It is the process that has control of the CPU.
• Ready : Waiting to be assigned to the CPU
- Ready to execute but another program is
executing on
the CPU.
• Waiting : Waiting for an event, eg. I/O completion
- It cannot make progress until event is signaled.
• Stopped : Not allowed to execute.
7
As a process executes it moves from state to state
Process state Graph
Create
Process
Ready
New
Unscheduled
Process
Terminated
I/O Done
Schedule
Process
Running
Waiting
I/O Page fault
etc.
Process
Exit
8
Process Creation in UNIX
A process is created by another process.
- Parent is creator and child is created - Process user id is inherited
- After creating a child the parent may either wait for it to finish its
task or continue in parallel or both.
• The processes are created using fork() int fork()
Fork()
• Creates and initializes a new PCB.(Process Control
Block)
• Creates a new address space.
• Initializes the address space with a copy of the entire
contents of the address space of the parent.
• Initializes the kernel resources to point to the resources
used by parent (eg., open file).
9
• Places the PCB in the ready queue.
Fork
Int main( int argc, char *argv[])
{
char *name = argv[0];
int child_pid = fork();
if(child_pid == 0) {
printf(“Child of %s is %d\n”, name,getpid());
return 0;
}else {
printf(“My child is %d\n”, child_pid)
return 0;
}
} // What does this program prints ?
10
Fork
Output:
 My child is 486
Duplicating Address:
// Child_pid = 486
Child_pid = fork();
if(child_pid == 0) {
printf(“Child “);
}else {
printf(“Parent”);
}
// Parent
// Child_pid = 0
Child_pid = fork();
if(child_pid == 0){
printf(“Child”);
}else {
printf(“Parent”);
}
// Child
11
Parents & Child processes
• The processes which call fork( ) is the parent.
• The process which result from the fork( ) is the
child.
• Fork( ) returns ‘0’ if the process is the child
process
• Fork ( ) returns the PID of the child if the process
is the parent process.
• In UNIX all the processes ultimately come from
the init process (PID = 1)
12
Long-Term Processes: Daemons
Daemon: Daemon processes run in the background
and spend most of their time waiting for an event
to occur, which they provide them service
• these are started automatically when the system is
booted.
• a typical daemon …cron daemon
• daemons are needed to :
-schedule activities
-startup periodic activities
13
Process Management Description
Pid = fork()
Create a child process
S=waitpid(pid,&status,opts)
Wait for a child to terminate
S= execve(name , argv, envp) Replace a process core image
Exit(status)
Terminate execution and return
status
S= sigaction(sig, &act,&oact) Specify action to take for a
signal
S= kill (pid, sig)
Send a signal to a process
Residual = alarm (seconds)
Pause( )
Schedule a sig alarm signal
later
Suspend the caller unit the14
next signal
Memory Management in UNIX
•
•
•
•
•
The memory management subsystem is one of the
most important parts of the operating system.
It allows:
Large Address Spaces
Protection.
Memory Mapping
Fair Physical Memory Allocation
Shared Virtual Memory
15
Cont’d
•
•
•
•
Physical vs. Virtual Memory
What is a Page Memory?
Cache Memory
How the Kernel Organize Memory
- Dividing the RAM
- System and User Areas
• Paging vs. Swapping
16
File System in Unix
Introduction
• What is File System?
– The abstraction used by kernel to represent and
organize the storage resources.
• UNIX File System in general
–
–
–
–
File system is organized in tree structure.
File tree can be arbitrarily deep.
File name must NOT LONGER than 256 chars.
Single path name must NOT LONGER than
1023 chars.
17
Creating File System
• Mounting File System
– File tree is composed of File System
– Use mount command to map a directory within
the existing file tree (mount point) to the root of
the new file system.
• mount /dev/hda2 /usr
– Use umount command to detach the file system.
• Detaching will fail if the file system is busy.
18
Types of files
Every thing in Unix is a file.
There are 3 types of files:
Regular files , Directory files and Device files.
1. Regular files:
• Most common type.
• Hold programs and data.
• Example
- Source code of a program
- Email received from a friend
- Executable programs and applications such as (ls,
cat etc.,)
19
Types of files cont..
2. Directory files:
A directory is like a file folder, it can contain files, and
other directories and hold programs and data.
• Like a cabinet in real life, the files that contains other
files.
• Saves information of files such as location, size etc.,
• A directory in the file system tree may have many
children, but it can only have one parent.
20
Types of files (cont.)
3. Device Files:
1. Allows programs to communicate with the
hardware.
2. Kernel modules handles device management.
- Character Device
• Accepts a stream of characters, without regard to
any block structure.
• It is not addressable, therefore no seek operation
- Block Device
• Information stored in fixed-sized block.
• It is addressable, therefore seek operation is
21
possible.
Types of files cont..
Device files (cont..)
Devices are also represented by special files.
• Each hardware is treated as a file like: Terminals,
keyboards, printers etc.
• Example:
- read the user input from the keyboard device
- print a text file: copy a file to the printer device
22
Organizing of The File System
/
/bin or /sbin
The root directory
Commands for basic
system operation
/dev
Device entries
/etc
Critical startup and
configuration files.
/lib
Library for the C
compiler
/tmp
Temporary files
/var/adm or /var/log Accounting file, log
files
23
File System Structure
/
bin
usr
admin
jon
lib
user
etc
stev
staff
stud
24
File Structure cont..
Absolute path: The path to a location can be defined
as an absolute path from the root anchor point.
Relative path: The path starting from the current
location.
Current working directory: The place in the
filesystem tree where you are located is called the
current working directory.
25
INODES
• INODES
– Kernel maintains file information in a structure
called inode.
• Creation, modification time stamps
• Ownership, file size etc.
– Commonly used INODE information can be
found by using ls command
– Group information and be modified by using
chgrp command.
26
File Management
File: File is a collection of permanent data with a
global name.
- The data are permanent in the sense that they
remain in existence until they are destroyed
explicitly by a process or a user (through some
process).
- The name is global in the sense that it does not
belong to the address space.
• they have a name
• the name refers to some data
• the data may be examined or modified
• access to the name and the data is controlled
27
File and Directory permissions
Three class of users and three types of permissions.
Classes of Users:
• Owner : I created the file.
• Group : The owner and I are in the same working
group.
• World : I just want to use the file.
Types of Permissions:
• Read permission : Read.
• Write permission : Alter, add or delete.
• Execute permission : Run.
28
Access Methods
Definition: An access method defines the way
processes read and write files.
1. Sequential Access:The file is associated with a
read/write mark, which is advanced on each access.
If several processes are reading or writing from the
same file, then the system may define one
read/write mark or several.
2. Direct Access: This access allows a user to position
the read/write mark before reading or writing. This
feature is useful for applications such as editors
that need to randomly access the contents of the
file.
29
Access Methods cont..
3. Mapped Access:When a process opens a file, it is
mapped to a segment. The open call returns the
number of this segment. The process can thus
access the file as part of its virtual store.
4. Structured Files:. Database applications often wish
to treat them as records that may be accessed by
some key. To accommodate these applications,
some systems support typed or structured files that
are considered streams of records
30
Interprocess Communication using
Unix Domain
Socket: A socket is an endpoint of communication
between processes.
• It is a software entity that provides the basic building
block for interprocess communications.
• Sockets function either as clients or servers.
• A server typically advertises some service at a wellknown address and waits for clients to request
connections.
• Clients requiring a particular service attempt to
connect to a server at the server's advertised
transport address.
31
Unix Domain Sockets
Types of Sockets:
Unix Domain Socket : UNIX domain sockets
communicate between processes on the same
system only.
Internet domain sockets : which can be used to
communicate with processes on other systems
Two types of Unix Domain Sockets:
1. Stream sockets : Most commonly used socket, It
provides bi-directional, sequenced, and
unduplicated flow of data without boundaries.
- This service is reliable and connection-oriented.
- Data is transmitted on a full-duplex, flowcontrolled byte stream.
32
Unix Domain sockets cont..
Cont.. - Message boundaries are not preserved on a stream
socket.
- it is supported by the Internet transport protocol TCP.
2. Datagram sockets:A datagram service is connectionless
and unreliable.
- used in applications where reliability of an individual
packet is not essential.
- message boundaries are maintained. This means that
individual datagrams (i.e., messages sent with separate
calls) will be kept separate when they are received at the
other end.
- it is supported by the Internet transport protocol UDP.
33
How to create a socket ?
s = socket(domain, type, protocol);
domain :The domain is specified as a manifest constant.
Type, Types are: SOCK_STREAM and
SOCK_DGRAM
Protocol: is a set of communication conventions for
regulating the exchange of information between
two parties eg. TCP, UDP.
34