3
3
Process Management
Process ://2marks
A Program does nothing unless its instructions are executed by a CPU. A program
in execution is called a process. For example, when we write a program in C or C+
+ and compile it, the compiler creates binary code. The original code and binary
code are both programs. When we actually run the binary code, it becomes a
process.
Text Section:A Process, sometimes known as the Text Section, also includes the
current activity represented by the value of the Program Counter.
Stack: The Stack contains the temporary data, such as function parameters, returns
addresses, and local variables.
Data Section: Contains the global variable and static variables .
Heap Section: Dynamically allocated memory to process during its run time.
Process state – It indicates current state of a process. Process state can be new,
ready, running, waiting and terminated.
Process ID – Every process is assigned with a unique id known as process ID
or PID which stores the process identifier.
Priority :Priority of the process.
Program counter: The program counter lets you know the address of the next
instruction, which should be executed for that process.
Registers
This specifies the registers that are used by the process. They may include
accumulators, index registers, stack pointers, general purpose registers etc.
Accounting information
This information includes the amount of CPU used, time limits, account
holders, job or process number and so on. It also includes information about
listed I/O devices allocated to the process such as list of open files.
Memory Management Information
The memory management information includes the page tables or the
segment tables depending on the memory system used. It also contains the
value of the base registers, limit registers etc.
Open files list – This information includes the list of files opened for a
process.
Process Queues
The Operating system manages various types of queues for each of the process
states. The PCB related to the process is also stored in the queue of the same state.
If the Process is moved from one state to another state then its PCB is also
unlinked from the corresponding queue and added to the other state queue in which
the transition is made.
In this, all processes who want to communicate with other processes can access a
region of the memory residing in an address space of a process creating a shared
memory segment.
All the processes using the shared memory segment should attach to the address
space of the shared memory. All the processes can exchange information by
reading and/or writing data in shared memory segment.
The form of data and location are determined by these processes who want to
communicate with each other.
These processes are not under the control of the operating system.
The processes are also responsible for ensuring that they are not writing to the
same location simultaneously.
After establishing shared memory segment, all accesses to the shared memory
segment are treated as routine memory access and without assistance of kernel.
2. Message Passing
In this model, communication takes place by exchanging messages between
cooperating processes.
It allows processes to communicate and synchronize their action without sharing
the same address space.
It is particularly useful in a distributed environment when communication process
may reside on a different computer connected by a network.
Communication requires sending and receiving messages through the kernel.
The processes that want to communicate with each other must have a
communication link between them. Between each pair of processes exactly one
communication link.
4. Resource sharing:
Resources like code, data, and files can be shared among all threads within a
process.
5. Communication:
Communication between multiple threads is easier, as the threads shares common
address space. while in process we have to follow some specific communication
technique for communication between two process.
Advantages
Thread switching does not require Kernel mode privileges.
User level thread can run on any operating system.
Scheduling can be application specific in the user level thread.
User level threads are fast to create and manage.
Disadvantages
In a typical operating system, most system calls are blocking.
Kernel Threads:
In systems that use kernel-level threads, the operating system itself is aware of
each individual thread.
Kernel threads are supported and managed directly by the operating system.
A context switch between kernel threads belonging to the same process requires
only the registers, program counter, and stack to be changed; the overall memory
management information does not need to be switched since both of the threads
share the same address space. Thus context switching between two kernel threads
is slightly faster than switching between two processes.
Kernel threads can be expensive because system calls are required to switch
between threads. Also, since the operating system is responsible for scheduling the
threads, the application does not have any control over how its threads are
managed.
Advantages:
More concurrency.because of multiple threads can run in parallel on multiple
CPUs.
Less complication in the processing.
Disadvantages:
One block call from kernel level thread blocks all user level threads.
Cannot take advantage of multiprocessing.
One to One Model:
The one to one model maps each user thread to a single kernel thread.
It provides more concurrency than the many to one model by allowing another
thread to run when a thread makes a blocking system call.
It also allows multiple threads to run in parallel on multiprocessors.
Whenever user level thread is created, it compulsorily creates corresponding
kernel level thread.
This model is used in Linux & Windows version like 95,97,XP, NT.
Advantages:
It allows multiple threads to run in parallel on multiprocessors.
More concurrency
Less complication in processing
Disadvantages:
Creating a user thread requires creating the corresponding kernel thread.
Creating kernel thread may affect the performance of an application.
It reduces performance of the system.
Kernel thread is overhead.
Many-to-Many Model
The many-to-many model multiplexes many user-level threads to a smaller or
equal number of kernel threads.
The number of kernel threads may be specific to either a particular application or
a particular machine (an application may be allocated more kernel threads on a
multiprocessor than on a uniprocessor).
The one-to-one model allows for greater concurrency, but the developer has to be
careful not to create too many threads within an application (and in some instances
may be limited in the number of threads she can create).
The many-to-many model suffers from neither of these shortcomings: developers
can create as many user threads as necessary, and the corresponding kernel threads
can run in parallel on a multiprocessor.
Also, when a thread performs a blocking system call, the kernel can schedule
another thread for execution.
Advantages:
Many threads can be created as per user’s requirement.
Multiple kernel or equal to user threads can be created.
Disadvantages:
True concurrency cannot be achieved.
Multiple threads of kernel is an overhead for operating system