0% found this document useful (0 votes)
93 views24 pages

CSC 322 Operating Systems Concepts - 6:: Special Thanks To

This document discusses processes and threads in operating systems. It defines a process as an abstraction of a running program with its own memory, variables, and program counter. It describes how operating systems use multiprogramming to allow multiple processes to run concurrently by quickly switching the CPU between processes. Processes can be created through system initialization, system calls, user requests, or batch jobs. They terminate through normal exit, errors, fatal errors, or being killed by another process. Processes exist in various states like running, ready, or blocked. The document also introduces threads as lightweight processes that share the same resources within a process.

Uploaded by

Abdul Mohaiman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views24 pages

CSC 322 Operating Systems Concepts - 6:: Special Thanks To

This document discusses processes and threads in operating systems. It defines a process as an abstraction of a running program with its own memory, variables, and program counter. It describes how operating systems use multiprogramming to allow multiple processes to run concurrently by quickly switching the CPU between processes. Processes can be created through system initialization, system calls, user requests, or batch jobs. They terminate through normal exit, errors, fatal errors, or being killed by another process. Processes exist in various states like running, ready, or blocked. The document also introduces threads as lightweight processes that share the same resources within a process.

Uploaded by

Abdul Mohaiman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

CSC 322 Operating Systems Concepts

Lecture – 6:

Special Thanks To:


Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. (Chapter-1)
What is a process?
Process: is an abstraction of a running program.
Multitasking /Multiprogramming: The ability of OS to
handle concurrent operation with only one CPU.
Example:
Web server: Serving Web pages to many clients.
If requested page is available in the cache it is sent
otherwise start a disk process to read page.

• When the system is booted, many processes are


created, e.g a process for incoming e-mail, process
for up dating virus definitions of antivirus, process for
printing files and process for burning a CD ROM, etc.

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

a) Multiprogramming of four programs.


b) Conceptual model of four independent, sequential
processes.
c) Only one program is active at once.
4
Process Creation
Events which can cause process creation:
1. System initialization, while booting operating system.
2. Execution of a process creation system call by a
running process.
3. A user request to create a new process.
4. Initiation of a batch job.

List the current processes use:


• ps command in UNIX
• Task Manager in windows

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.

• In command based UNIX systems running X, new


process takes over the window in which it was started.
• In Microsoft Windows, when a process is started it
does not have a window, but it can create one.
• Using the mouse, the user can select a window and
interact with the process, for example, providing input
when needed.
8
4. Process creation by initiating batch job
The processes are created for batch systems usually found
on large mainframes.

• users can submit batch jobs to the system (possibly


remotely).

• When the operating system decides that it has the


resources to run another job, it creates a new process
and runs the next job from the input queue 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.

• In UNIX a new process is created through fork() system


call. That creates a child which is a clone of parent.
Then child execute execve or a similar system call to
change its memory image and run a new program.
• In Windows, in contrast, a single Win32 function call,
CreateProcess, handles both process creation and
loading the correct program into the new process.
• In both environment after creation of child process it
has its independent address space w.r.t its parent.
10
Process Termination
Events which cause process termination:
1. Normal exit (voluntary).
2. Error exit (voluntary).
3. Fatal error (involuntary).
4. Killed by another process (involuntary).

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.

• Screen-oriented programs support voluntary


termination. Word processors, Internet browsers
and similar programs have an icon that the user can
click to tell the process to remove all files and then
terminate.

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.

• Screen-oriented interactive processes generally do


not exit when given bad parameters. Instead they
pop up a dialog box and ask the user to try again.

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.

• Examples include executing an illegal instruction,


referencing nonexistent memory, or dividing by zero.

• In UNIX, a process can tell the operating system


that it can handle certain errors by itself, in that
case the process is signaled (interrupted) instead of
terminated.

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.

• In UNIX this call is kill. The corresponding Win32


function is TerminateProcess.

• In both cases, the killer must have the necessary


authorization to do the killing .

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

• Instead of interrupts, think about user processes, disk


processes, terminal processes, (sequential processes),
which block when they wait for something
• The lowest layer of a process structured operating system
handles interrupts and scheduling.
18
Structure of Processes Table (Process Control Block PCB)

Some of the fields of a typical Process Table entry.

19
OS processes an interrupt

Skeleton of what the lowest level of the operating system


does when an interrupt occurs.

20
How multiprogramming performs

CPU utilization as a function of the number of processes in


memory.

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

. This model allows the server to be written as a


.
collection of sequential threads.
24

You might also like