CSC 322 Operating Systems Concepts - 6:: Special Thanks To
CSC 322 Operating Systems Concepts - 6:: Special Thanks To
Lecture – 6:
2
Multiprogramming
Process is an instance of a program, associated with
registers, variables, and a program counter.
• It has a program, input, output and a state
• A computer manages many computations concurrently
need an abstraction to describe how it does that,
• In multiprogramming system, CPU switches from
process to process quickly, running each process for
tens or hundreds of milliseconds. However at any
instant of time, the CPU is running only one process, but
giving the illusion of parallelism Some times called
pseudo parallelism
3
Multiprogramming
5
1. Process creation while booting OS
When an operating system is booted, several processes
are created. Two categories:
Foreground processes;
• Process that interact with users, such UNIX tty
processes
Background processes;
• Process not associated with particular users, but
instead have some specific function, such as e-mail,
web pages, news, printing, and so on, these
processes are called daemons
6
2. Process creation with system calls
Processes can be created by running process issuing
system calls.
• Useful when the work could be formulated among
several related, but independent processes.
Example:
If a large amount of data to be fetched over a network
for processing, it may be convenient to create one
process to fetch the data and put them in a shared
buffer while a second process removes the data items
and processes them. On a multiprocessor, environment,
each process may run on a different CPU and make the
job go faster.
7
3. Process creation by interactive users
In interactive systems, users can create a new process by
typing a command or (double) clicking an icon.
Both of these actions starts a new process and runs the
selected program in it.
9
Process creation in UNIX and windows
In all the cases, a new process is created by an existing
process executing a system call. The process may be a user
process, a system process or a batch manager process.
11
Process Termination
1. Normal exit (voluntary).
• Process completed its given task. e.g. compile a
code. The process execute exit() in UNIX and
ExitProcess in windows.
12
Process Termination
2. Error exit (voluntary).
• process discovers an error for example, if a user
types the command cc foo.c and the file foo.c does
not exists. the compiler simply exits.
13
Process Termination
3. Fatal error (involuntary).
• The third reason for termination is an error caused
by the process, often due to a program bug.
14
Process Termination
4. Killed by another process (involuntary).
• A process might terminate due to the reason that
some process executes a system call telling the
operating system to kill some other process.
15
Process Hierarchies
UNIX :
• a process creates another process, called a child process
which can further creates more processes, forming a
process hierarchy.
• UNIX initializes a special process, called init, is present
in the boot image. Which then forks off one new
process per terminal.
Windows :
• No process hierarchy all processes are equal.
• The hierarchy created when a process creates a child.
The parent is given a special token (called a handle) to
control the child. However, it is free to pass this token
to some other process, thus invalidate the hierarchy.
16
Process States
Running:
• Actually using the CPU at that instant.
Ready:
• Runnable, temporarily stopped to let other process run.
Blocked:
• Unable to run until some external event happens.
Transitions between
these states.
17
Implementation of Processes
19
OS processes an interrupt
20
How multiprogramming performs
21
Process and Thread
• Process has an address space and a single thread of
control.
• Processes may have multiple threads of control in the
same address space running in quasi-parallel, like
(almost) separate processes.
• Threads are Processes with in process
• Threads are lightweight processes share the same
address space and resources allocated to process.
• Process share the resources offered by operating
system among other processes
22
Usage of Threads
Example:
• Processing a large document, having threads for,
Interactive users, background formatter and backup
file on disk
23
Thread Example-web server