Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Operating Systems 2011

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

It is important to note that a process is not a program.

A process is only ONE instant of a


program in execution. There are many processes can be running the same program.

Process Management

The operating system manages many kinds of activities ranging from user programs to system programs like printer

spooler, name servers, file server etc. Each of these activities is encapsulated in a process. A process includes the

complete execution context (code, data, PC, registers, OS resources in use etc.).

The five major activities of an operating system in regard to process management are

 Creation and deletion of user and system processes.

 Suspension and resumption of processes.

 A mechanism for process synchronization.

 A mechanism for process communication.

 A mechanism for deadlock handling

Process is not the same as program. A process is more than a program code. A process is an 'active' entity as oppose to

program which consider to be a 'passive' entity. As we all know that a program is an algorithm expressed in some

suitable notation, (e.g., programming language). Being a passive, a program is only a part of process. Process, on the

other hand, includes:

 Current value of Program Counter (PC)

 Contents of the processors registers

 Value of the variables

 The process stack (SP) which typically contains temporary data such as subroutine parameter, return

address, and temporary variables.

 A data section that contains global variables.

A process is the unit of work in a system.

In Process model, all software on the computer is organized into a number of sequential processes. A process includes

PC, registers, and variables. Conceptually, each process has its own virtual CPU. In reality, the CPU switches back and

forth among processes. (The rapid switching back and forth is called multiprogramming).

Last modified: Wednesday, 7 January 2009, 01:07 PM


Despite of the fact that a thread must execute in process, the process and its associated threads are different concept.

Processes are used to group resources together and threads are the entities scheduled for execution on the CPU.

A thread is a single sequence stream within in a process. Because threads have some of the properties of processes,

they are sometimes called lightweight processes. In a process, threads allow multiple executions of streams. In many

respect, threads are popular way to improve application through parallelism. The CPU switches rapidly back and forth

among the threads giving illusion that the threads are running in parallel. Like a traditional process i.e., process with

one thread, a thread can be in any of several states (Running, Blocked, Ready or Terminated). Each thread has its own

stack. Since thread will generally call different procedures and thus a different execution history. This is why thread

needs its own stack. An operating system that has thread facility, the basic unit of CPU utilization is a thread. A thread

has or consists of a program counter (PC), a register set, and a stack space. Threads are not independent of one other

like processes as a result threads shares with other threads their code section, data section, OS resources  also known

as task, such as open files and signals.

Processes Vs Threads

As we mentioned earlier that in many respect threads operate in the same way as that of processes. Some of the

similarities and differences are:

Similarities

 Like processes threads share CPU and only one thread active (running) at a time.

 Like processes, threads within a processes, threads within a processes execute sequentially.

 Like processes, thread can create children.

 And like process, if one thread is blocked, another thread can run.

Differences

 Unlike processes, threads are not independent of one another.

 Unlike processes, all threads can access every address in the task .

 Unlike processes, thread are design to assist one other. Note that processes might or might not assist one

another because processes may originate from different users.

Why Threads?
Following are some reasons why we use threads in designing operating systems.

1. A process with multiple threads make a great server for example printer server.

2. Because threads can share common data, they do not need to use interprocess communication.

3. Because of the very nature, threads can take advantage of multiprocessors.

Threads are cheap in the sense that

1. They only need a stack and storage for registers therefore, threads are cheap to create.

2. Threads use very little resources of an operating system in which they are working. That is, threads do not

need new address space, global data, program code or operating system resources.

3. Context switching are fast when working with threads. The reason is that we only have to save and/or restore

PC, SP and registers.

But this cheapness does not come free - the biggest drawback is that there is no protection between threads.

User-Level Threads

User-level threads implement in user-level libraries, rather than via systems calls, so thread switching does not need

to call operating system and to cause interrupt to the kernel. In fact, the kernel knows nothing about user-level

threads and manages them as if they were single-threaded processes.

Advantages:

The most obvious advantage of this technique is that a user-level threads package can be implemented on an

Operating System that does not support threads. Some other advantages are

 User-level threads does not require modification to operating systems.

 Simple Representation:

    Each thread is represented simply by a PC, registers, stack and a small control block, all stored in the

user process address space.

 Simple Management:

    This simply means that creating a thread, switching between threads and synchronization between

threads can all be done without intervention of the kernel.

 Fast and Efficient:

    Thread switching is not much more expensive than a procedure call.
Disadvantages:

 There is a lack of coordination between threads and operating system kernel. Therefore, process as whole

gets one time slice irrespect of whether process has one thread or 1000 threads within. It is up to each

thread to relinquish control to other threads.

 User-level threads requires non-blocking systems call i.e., a multithreaded kernel. Otherwise, entire process

will blocked in the kernel, even if there are runable threads left in the processes. For example, if one thread

causes a page fault, the process blocks.

You might also like