What a process is - Shawlands Academy

Download Report

Transcript What a process is - Shawlands Academy

Topic 6
Operating Systems
Applications software allow the user to communicate with the
system software.
The system software communicates with the hardware.
The operating system provides a set of system calls that can be
used by the programmer of an application to work the computer
system.
The operating system can also provide a library of subroutines,
often called an Application Programming Interface (API)
The operating system is part of the system software. It can be
regarded as an interface in three different ways.
First, it is an interface between the parts of a computer system.
These work at different speeds and in different ways, and the
operating system enables them to communicate.
Second, the operating system is an interface between an application
package and hardware. Software houses, that create application
packages, write them to run under a particular operating system.
Third, the operating system is an interface between the hardware
and the user.
There are two kinds of user interface:
command-line interfaces (CLIs) and
graphical user interfaces (GUIs).
•MS-DOS had a command line interface.
•Apple Macs from the start offered a GUI.
Operating systems are expected to have similar features. These are:
• memory management;
• processing modes;
• input/output;
• filing system;
• resource sharing;
• user interface;
• applications support;
• security.
Additional criteria required when looking at an operating
system is:• cost;
• ease of installation;
• ease of management
• reliability
•Performance
• range of platforms
•range of software
• customisation
What a process is
The term process is basic to the understanding of the workings of an
operating system.
A programmer writes programs. The source code of these programs
will be in assembly language or in some high level language like
Java.
When a program is actually running, it contains run-time data and a
stack; other information necessary to keep the program running
include a program counter and a stack pointer. All of these things
together make up a process.
A process can be defined as a program in execution.
Another name for process is task.
When you run a program, the operating system has to convert it
into a process. It is the process, rather than the simple program,
that the processor executes. When the process terminates, the
program itself remains (on backing store), fit to be converted
into a process again if needed.
6.3
Pupil task
An operating system needs room in memory for itself and for the
processes it creates, and user programs need memory for themselves
and the data they use.
Part of the operating system, known as the memory manager,
allocates memory to these processes and keeps track of the use of
memory.
Some operating systems, such as early versions of Windows (95, 98, NT)
provides only a single-user environment. Multi-user memory
management is provided by most modern operating systems.
Most operating systems support multi-tasking. In multi-tasking,
several applications or tasks are (apparently) available at the same
time, and the user can switch easily between one application and
another.
Most operating systems also support multi-threading. Threads are
sometimes called lightweight processes.
One process can have several threads.
The threads act independently of one another, but share the same
memory space. For example, in a database application, one thread
might run the user interface and another might handle the actual
database.
Process loading and swapping
If a program is to be run (as a process), it needs to be copied into
memory from backing store. This action - by no means instantaneous
- is known as process loading.
Some systems, as we shall see, also take processes out of memory
and store them on disc, to make room for another process. This is
known as process swapping.
Monoprogramming
The simplest method of memory management is to have just one
process in memory at a time, and to allow it to use all the memory
there is. One obvious problem with this approach is that a program
needs to be entirely self-reliant and contain,
Multiprogramming
Monoprogramming would not do on a large computer that has lots of
users.
Having several programs in memory at once is called multiprogramming.
In multiprogramming, memory is divided into parts, of one kind or
another. Names for these parts include partitions, segments, and
pages.
Multitasking Animation
Log onto scholar 6.3 using web animation..
Fixed partitions
Using fixed partitions is a relatively straightforward way of effecting
multiprogramming.
The partitions are fixed in size but don’t have to be all the same
size.
1000k
700k
400k
Process D
Partition 4
400k
Process C
Partition 3
300k
Process B
200k
Process A
100k
Operating system
Partition 2
200k
Partition 1
100k
Drawbacks to fixed partitions
The main problem with fixed partitions is that, processes don’t usually fit
partitions exactly. As a rule, there will be wasted space in each partition.
A map of memory, as in the diagram above, looks fragmented. This
waste of space is known as internal fragmentation (internal because the
space wasted is inside the partitions).
Another drawback is that a process might come along that is too big for
any of the partitions.
Variable partitions
One solution, is to allocate to each process exactly the amount of
memory it needs.
When a process turns up, it is loaded into the next available area. This
can go on until there is no room left.
1000k
Available Space
750k
Process D
550k
Process C
325k
Process B
175k
Process A
100k
Operating system
The arrival of process E
Process C terminates
Process F can be executed once process B terminates
Pupil task
looked at how the processor is switched between tasks resident in
memory (page 156 Scholar multitasking animation)
Once everything is up and running, new processes need to be
fitted into the HOLES available. (spaces in memory can be known
as holes)
There are three policies to choose from:first fit
best fit
worst fit
Method
First fit
Description
comment
Incoming process is
fitted into the first
space big enough
This method is quick
and simple
Best fit
Incoming process is
fitted into the smallest
space that can take it
This method tends to
leave small and
therefore useless
spaces
Worst fit
Incoming process is
fitted into the largest
space going
This method gets
around the issue of
best fit – the space
left will often be big
enough for another
process.
Information about holes is often kept in a linked list. Coalescing
holes is straightforward.
First fit will take the first hole large enough; the other two methods
will need to scan the entire list before a decision can be made.
Compaction
Fragmentation can be kept down to one hole (of whatever size) by
shifting processes around whenever one leaves memory. All
remaining processes are packed down (compacted) so as to leave
a single hole at the top.
In the previous series of memory maps, process F arrived and
process C terminated.
Process F did not have enough room. However, with compaction,
processes D and E could be moved down in memory, leaving enough
room at the top for F.
Process C Terminated
1000k
Available Space
Memory after Compaction
1000k
Available Space
975k
975k
Process F
Process E
675k
675k
Process E
Process D
525k
525k
Process D
Available Space
325k
325k
Process B
Process B
175k
175k
Process A
Process A
100k
100k
Operating system
Operating system
All such gains in sophistication have a cost in terms of complexity of
implementation.
The more intricate the algorithm, the more intricate the code needed
to make it happen.
Furthermore, an action such as compaction is not instantaneous but
takes time. The overheads that compaction calls for tend, in fact, to
be so great and make things so slow that the scheme is rarely used
in practice.
Paging
if we assume that processes are relatively small and can fit into
memory. From the very early days, there has been the problem that
some programs are too large to fit into memory at all, never mind into
a fraction of it such as a partition.
In a paged system, processes are
chopped up into a number of chunks all
of the same size. These chunks are
called pages.
process
frames
A
5
B
3
C
2
D
6
Complete questions 5 – 12 on page’s 161/162.
Process management is to do with choosing which process to run, and how
long to run it for. This is managed by part of the operating system called the
scheduler.
A scheduler works according to a particular scheduling algorithm. The
algorithm is subject to certain constraints:
 it should be fair, so that each process gets its fair share of the processor;
 it should be efficient, to maximise use of the processor;
 it should achieve high throughput;
 it should have a good response time.
Many processes are, obviously, started directly by the user.
Others are started by the operating system, however processes can themselves
start other processes.
All these processes have a program counter, registers, and other information.
The processor performs what’s called a context switch when it changes from one
process to another
a process, once it had gained control of the processor, would run to completion.
Such an approach is still tenable on PCs that expect to have only one user at a
time (DOS works in this way), but won’t do at all on a multi-user or multi-tasking
system.
One answer is cooperative scheduling where each process would, in principle,
run for a little and get a bit of work done.
The problem with this is that processes tend to act selfishly and keep the
processor to themselves for as long as they can.
This is due to the operating system giving up too much control.
Cooperative scheduling would work even worse in a multi-user system.
Somebody
The scheduler needs, then, to be able to suspend one process, at any point, and give
another process a turn. The operating system keeps control. Such scheduling is
known as pre-emptive scheduling.
Process states
A process enters the system and starts running. When it’s finished, it terminates.
While it’s in the system, the process can be in one of three states:
 running;
 blocked;
 ready.
The process runs until obliged to wait for I/O or pre-empted by the scheduler (to give
another process a turn).
If it is pre-empted, it is still ready to use the processor.
If it is waiting for I/O, it is described as blocked, and stays in that condition until the I/O
is over
look at Diagram 6.9 on page 163
There are 2 different scheduling algorithms.
Round robin
Priority scheduling
Round robin
Processes are put in a sort of circular list.
Each process in turn is assigned a time-slice.
If the process is still running at the end of the time slice, it is pre-empted and has to
wait its turn again
Switching processes takes time and thus wastes processor time. Too long a time
slice might mean irritatingly long waits.
Round robin is suitable to interactive systems ( not real time). The algorithm is also
fair, in that all jobs are treated as though they are equally important
Priority scheduling
In priority scheduling, each process is given a priority, and the job with the highest
priority is processed.
In many systems, there is a queue of jobs for each level or priority, and the jobs within a
certain level are treated to round-robin scheduling. Because low-priority jobs might, on
a busy system, never get a turn, things are sometimes organised so that jobs that have
been waiting a long time have their priority raised.
Three algorithms used for priority scheduling are first come first served,
shortest job first and multi-level feedback queues.
First come, first served (FCFS)
This algorithm is straightforward, and works well enough for long jobs.
Job
Processingtime Turnaroundtime
A
20
20
B
10
30
C
4
34
D
2
36
This gives an average turnaround time of 30 minutes, which compares badly with
an average run-time of 9 minutes.
Shortest job first
In batch systems, and other systems where the running time of a process can be
predicted, we can use the principle that the shortest jobs should be run first.
This gives an average turnaround time of 15 minutes: the longest job does worse
but the three other jobs do a lot better. The shortest-job-first approach gives optimal
turnaround times. On the other hand, long jobs on busy systems might have to wait
indefinitely because shorter jobs keep getting in the way.
Multi-level Feedback Queues
Each of these methods has advantages and also disadvantages. The multilevel feedback queue algorithm tries to combine the best of each.
The top level queue has highest priority, but each process in this queue is only allocated
one very short time slice.
for a longer time independently of the processor (perhaps using DMA).
If it is a longer process, it is given a short time slice, then moved down to the
second level queue, so that the top level queue is not held up.
The second level queue gets processor time if the top level queue is empty. If a process
is till not completed within the longer time slice, it is pushed down to the next queue.
The final queue is a round robin queue, which continues to allocate time slices to
processes (when the processor is not being used by the higher queues) until they are
completed.
Pupil task
Now complete questions 13 -18 on page 166
Input and output (I/O)
Peripheral devices are, in general, different from one another: they work in
different ways and at different speeds.
In the I/O system, the software can be thought of as organised in layers:
the upper one presents an
interface to the user or
application.
Application
program
I/O Control System
_________
Device Driver
I/O Bus
the lower one deals
directly with the
hardware
Device Controller
______________
Device
The device driver communicates
with the device controller, which is
part of the hardware, plugged into the
computer’s I/O bus.
Device independence
The I/O system hides the physical details of a device from the users and
presents then with straightforward means of access and control
Input/Output in Windows
A DLL is a piece of executable code (a device driver, for example) that can
be shared by different processes. The routines in a DLL are only linked into
an application at run time. In Windows, all the device drivers are dynamic
link libraries.
Plug and play
Adding a new device to a system has in the past been rather a fiddly
business. Often a new control card has to be plugged into the computer.
Very often, switches on the device would have to be set by hand.
Plug and play can be regarded as a sort of convention or standard agreed
between computer manufacturers, chip manufacturers, device
manufacturers, and so on. The user has to supply very little information
during installation and nothing at all from then on.
Direct memory access
A device controller will have its own memory on board. This enables it to use
Direct Memory Access (DMA) to get data to and from the computer’s
memory. In DMA, the processor only sets up the transfer. Thereafter, some
clock cycles are used by the I/O system for the data transfer.
Virtual devices
A virtual device seems, to the user, like an actual device but is, in fact, a
simulation maintained by the I/O system. A print spooler is a virtual device, that
takes data sent to the printer, stores them temporarily on disc, and prints them
when the system is ready to do so.
Buffering
Buffering is used in sending blocks of data. Data is transferred into the buffer
until it is full. Then the entire block is sent at once. This is more efficient than
having the data trickle through the system.
Spooling
Spooling involves the input or output of data to a tape or a disk. The print
spooler stores the data in files and sends it to the printer when it is ready, using
a print queue.
Pupil task
Question 19,20 & 21 on page 170
File Management
The most familiar aspect of the Operating System to most users is whenever
they carry out any of the following operations:
• loading an application
• saving a document
• creating a new folder
• renaming a file
• deleting an unwanted application
A major function of the file management section of the operating system is to
map the logical view (as seen by the user) on to the physical view (as seen
by the computer).
Logical View of files
A file is a meaningful collection of data. The file will have
•a name,
•a file type,
•a location (within a folder on a disc),
•a size.
•other attributes such as its creation date,
•date last modified,
•read-only.
Folders and Directories.
•Applications install themselves into folders.
•Users arrange their work into folders.
The arrangement of folders on the root containing folders that contain folders
and so on, is often described as hierarchical.
Paths
In figure 6.11 (page 172), There is no confusion because the folders are on
different paths: their full names, so to speak, are different.
Physical View
Most storage devices are divided up into tracks and sectors, forming blocks of
a fixed size, perhaps 512 bytes. See diagram page 173
The term cluster (or blocks) is also used to describe the smallest section of a
storage device that the operating system will recognise.
Contiguous Allocation
the following sequence of user
commands were required using a disk
with 30 clusters, each of size 32K
Command 1: save file 1 (size 64K)
Command 2: save file 2 (size 97K)
Command 3: save file 3 (size 3K)
Command 4: save file 4 (size 220K)
Command 5: delete file 2
Command 6: save file 5 (220K)
Command 7: copy file 1 (64K)
Command 8: save file 6 (70K)
Command 9: save file 7 (190K)
This will need 6 clusters. These must be contiguous, so clusters
6 and 7 or clusters 26 to 30 cannot be used. Although there
are more than 6 free clusters, the file cannot be copied as the
clusters are not contiguous.
Command 10: add data to file 1
Perhaps file 1 is a word processed document, and the user
loads it up, adds some extra paragraphs, then tries to save it.
The system will be unable to save the file as the next cluster
(cluster 4) is already in use.
Linked Allocation
page 179
Indexed Allocation page 180
File Allocation Tables page 181***(FAT)
The file management system in operation page 182
understand Diagram
Pupil task
REVISION QUESTIONS ON PAGE 185