Operating System services: What services an operating system provides?

advertisement
Operating System services:
What services an operating system provides?
- OS provides certain services to programs and to
the users of these programs.
- There are some common classes of services:
Program execution: load, run, end.
I/O operations: - I/O request file or device
- Signal to I/O devices.
File system manipulation:
- Read.
- Write.
- Delete.
- Create files
Error detection: - in the CPU and memory
H/W (memory error, power failure).
- In I/O devices (printer, out of paper).
- User program (arithmetic overflow, attempt
to accept illegal memory location, using too much
CPU time).
- For each type of error, the OS should take the
appropriate action to insure consist and correct
computing.
- Another functions exist for the efficient operation
of the system itself.
Resource allocation: when there are multiple
users or multiple jobs running at the same time,
resources must be allocated to each of them.
Resources are: (CPU cycles, main memory, file
storage)
1
Accounting: We want to keep track of which
users use how much and what kinds of
computing resources.
Protection: When several disjoint jobs are being
executed simultaneously inorder to increase
utilization; it should not be possible for one job
to interfere with the others.
How the OS provides these services?
-Two basic methods: 1. System calls
2. System programs
System calls:
- They provide the interface between the running
program and the OS. They are available as assembly
language instructions.
- Can be grouped into major categories:
1. Process or job control. (halt, load, executer, create
process, terminate process, get process attributes, set
process attributes)
2. File manipulation. (create file, delete file, open, close
file, read, write reposition, get file attributes, set file
attributes)
3. Device management. (request device, release device,
read, writes reposition the device, get and set device
attributes).
2
4. Information maintenance. (get time and date, set time
and date, get system date, set system date, get process,
file or device attribute, set process, file or device
attributes)
System programs:
Most systems supply a large collection of system
programs to solve problems, provide environment for
program development and execution. Divided into:
- File manipulation: create, delete, copy, rename,
print, dump, list (files & directories)
- Status information: date, time, amount of available
memory, disk space, no. of users.
- File modification: text editors (create, modify,
store files).
- Program language support: compilers, assemblers,
interpreters.
- Program loading & execution: absolute loader,
relocatable loader, linker, debugger.
- Application programs: DB, statistical packages,
plotting packages, etc.
- Command interpreter: running when job start or
user log-in gets command and executes it (shell
UNIX)
3
Operating system concepts:
Processes:
- A process is the key concept in all operating
systems. It is a program in execution.
- In various OSs, processes may be called jobs,
users, programs, tasks or activities.
- Process execution is a cycle of CPU execution and
I/O wait.
- Process execution begins with a CPU burst,
followed by an I/O burst, followed by another
CPU burst, then another I/O burst and so on.
- Eventually, the last CPU burst will end with a
system request to terminate execution.
Process state:
- As a process executes, it changed state.
- Each process may be in one of the following
states:
New: the process is being created.
Running: instructions are being executed.
Waiting: the process is waiting for some event
to occur (such as an I/O completion)
Ready: the process is waiting to be assigned to
a processor.
Terminated: the process has finished
execution.
4
New
admitted
exit
interrupt
Ready
Running
Terminate
Scheduler dispatch
I/O or
event
completion
I/O or
event waiting
Waiting
Diagram of process state
Process control block: (PCB)
- Each process is represented in the OS by a PCB
also called task control block.
- PCB is a data block or record containing many
pieces of the information associated with a
specific process, including:
Process state: (new, running, waiting, or
halted)
Program counter: (indicates the address of the
next instruction to be executed for this
process).
5
CPU registers: (vary in numbers and type,
including accumulators, index registers,
general purpose registers, stack pointer, plus
any condition code information)
CPU scheduling information: (including a
process priority, pointers to scheduling
queues, and any other scheduling parameters)
Memory management information: including
such information as the value of the base and
limit registers, the page tables, or the segment
tables depending on the memory system used.
Accounting information: including the amount
of CPU and real time used, time limits,
account numbers, job or process numbers and
so on.
I/O status information: include outstanding I/O
requests, I/O devices allocated to this process,
a list of open files, etc.
- The PCB is the central store of information that
allows the OS to locate all key information about a
process.
Scheduling Queues:
- Multiple programming has many processes in
memory and one is running at all times.
- Uniprocessor system: there will be no more than
one running process.
6
- If there are more processes, the rest will be waiting
until the CPU is free.
- The processes, which are ready and waiting to
executeare, kept in a list called the ready queue,
which is a linked list.
- A ready queue header will contain pointers to the
1st and last PCBs in the list.
PCB#7
PCB#2
Registe
rs
.
Registe
rs
.
.
.
Q Header
Head
RQ
Tail
Mag
Tape
Unit 0
Head
Tail
.
.
.
PCB#3
Disk
Unit0
PCB34
Head
Tail
PCB#5
Terminal
Unit 0
Head
Tail
RQ and various I/O device queues
7
PCB#6
- Each PCB has a pointer field which points to the
next process in the ready queue.
- The RQ is not necessarily a (FIFO) queue. It can
be implemented as a FIFO queue, a priority queue,
or an unordered linked list.
- There are also other queues in the system.
- The list of processes waiting for a particular I/O
device is called a device queue.
- Each device has its own device queue.
CPU
RQ
I/O
I/O queue
I/O request
Time slice
expired
Fork a
child
Child
execute
Wait for
an
interrupt
Interrupt
occures
Queuing diagram representation of CPU scheduling
8
- A new process is initially put in the RQ. It waits in
the RQ until it is selected for execution (or
dispatched) and is given the CPU.
- One of the several events could occur:
1. Process could issue an I/O request. Then placed in
I/O queue.
2. Process may create a new sub process and wait for
its termination.
3. Process could be removed forcibly from the CPU
as a result of an interrupt, and put back in the RQ.
- If the device is a dedicated device (time-sharing
terminal). The device queue will never have more
than one process in it.
- If the device is sharable (Disk), several processes
may be in the device queue.
Scheduling
- A process moves between the various scheduling
queues throughout its lifetime. OS selects for
scheduling purposes, processes by appropriate
scheduler.
- An OS has many schedulers.
- There are two main schedulers:
1. Long-term scheduler (job schedulers), which
selects jobs from the job, pool and load them into
memory for execution.
9
2. Short-term scheduler (CPU scheduler)” which
selects from among the jobs in memory which re
ready to execute and allocates the CPU to one of
them.
long-term
RQ
short-term
CPU
end
I/O waiting
queues
I/O
- The primary distribution between these two
schedulers is the frequency of there execution.
- The short-term must select a new process for the
CPU quite often, and must be very fast. (A process
may execute for only a few milliseconds before
waiting for an I/O request). If it takes 10
milliseconds to decide to execute a process for 100
milliseconds then (10/(100+10)) =9% of the CPU
is being used (waist) simply for scheduling the
work.
- The long-term executes must less frequently. It
may be minutes between the arrivals of new jobs
in the system.
- The long-term scheduler controls the degree of
multiprogramming (no. of processes in memory).
10
- If the degree is stable, then the average rate of
process creation equal to the average departure
rate. Therefore the scheduler invoked only when a
process leaves the system.
- Because of the longer interval between executions,
the long-term scheduler can afford to take more
time to decide which process should be selected
for execution.
- Most processes can be described as either I/O
bound or CPU bound.
- I/O bound: it spends more of its time doing I/O
than it spends doing computation.
- CPU bound process: using more of its time doing
computation.
- Long-term scheduler must select a good mix of
I/O bound & CPU bound processes.
- On some systems, the long-term may be absent or
minimal.
- Example: in time sharing systems often have no
long-time scheduler, but simply put every new
process in memory for the short-term scheduler.
- Some systems (using virtual memory or time
sharing) can have medium-term scheduler to
reduce the degree of multiprogramming by using
the swapping scheme.
11
Swap in
Partially executed
swapped out processes
swap out
CPU
RQ
I/O waiting
queues
I/O
Adding medium term scheduler
- Can remove process from memory and reduce the
degree of multiprogramming some time later,
reintroduce into memory and continued.
12
Download