2. Operations On Processes
Processes- as we know is an activity/ program under execution.
Execution of a process is a complex activity.
In modern day systems, processes are executed concurrently.
Therefore, it is the duty of an operating system to provide a flexible
mechanism for dynamically creating, maintaining anddeleting processes
in a computer system.
4. Process Creation
Process creation is deemed to be the first step of any process execution
activity. In simpler terms, it can be put as the construction of new processes
for execution.
There are four events that leads to the creation of a “new” process:-
1. System Initialisation.
2. Execution of a process creation system call by a running process.
3. User request to create a new process.
4. Initialization of a batch job.
5. -A new process is created using the system call “fork()”
system call on UNIX systems [ CreateProcess() on
Windows-based systems}. The one which initiates this
call is termed as “Parent Process”; the one derived from
it is termed as “Child Process”.
-After the creation of a new process, the OS assigns a new
Process identifier , an integer value to identify a process,
which creates a new entry on the primary table.
- Then, the required memory for all elements of a process
such as program,data etc is allocated on Process Control
Block. A thing to note is that depending the
implementation of a system, some resources/data may
be shared between a child and it’s parent process. In the
beginning, not much is allocated to a process because a
user has to request to do so but it’s child may inherit
some resource from its parent.
7. After a child process is created, there are two options
for the parent process:
● Wait for the child process to terminate before
proceeding. The parent makes a wait() call. This
is more common with UNIX based systems.
● Run concurrently with the child. A scenario where
a parent process executes for a while and then
pauses, for the child process to execute, is also
possible
8. Process Termination
All created processes have to be terminated at some point of their cycle.
This is when a process is no longer needed for the program or some kind
of problems may have been encountered by the program.
A Process begins its termination when the final piece of the statement in
a program is executed.
9. Types of Process Termination
Normal Termination:- It is a type of voluntary termination, where the process
quits after it has executed the final statement. The process may return a status
value ( typically an integer) to the parent. The shared resources are also de-
allocated by the OS.
Abnormal Termination:- This type of termination occurs mostly due to
programming errors,runtime errors, user intervention etc. There are three
categories under this type of termination.
1. Error Exit: A voluntary type termination which occurs due to program bugs(
like trying to execute an illegal statement, referencing non existing memory
etc.) In some cases in UNIX systems, the process requests the OS itself to
rectify its own mistake, therefore only interrupting instead of terminating
them.
10. 2. Fatal Errors: It is an involuntary execution, in
which there are problems in the code or a non
existent file.
3. Killed by another process:- The Process may
be terminated under the instruction of another
process. This is invoked by an appropriate
system call
11. A Parent may also terminate its Child when:-
1. The task given to the Child is not needed anymore.
2. The Child exceeds the usage of resources allocated
to it.
3. The Parent is exiting, resulting in the termination of
the Child.
Note: If the child is unable to be terminated since
their Parent isn’t waiting, they will be returned to init and
eventually be killed off.
12. Cooperating Processes
There are many Processes which may be independent or cooperates with other
processes in a program. As the name suggests, Independent Processes do not
share any data and is not affected by any other process in any way. On the
other hand, Cooperating processes may be affected by the other process in the
system.
A cooperating process is one that can affect or be affected by other process
executing in the system cooperating process can:
1. Directly share a logical address data space (i.e. code & data) - This
may result in data inconsistency. It is implemented on threads.
2. Share data only through files/ messages - It only deals with orderly
execution of cooperating process so that data consistency is maintained.
13. Reasons that allow Process Cooperation
1. Information Sharing: There may arise a scenario where every user wants the
same piece of information. Thus, it allows concurrent access to all the data
for everyone.
2. Computation Speedup: A Process is expected to execute efficiently. So we
breakup these processes into smaller sub tasks, where they will be
parallely executing with one another.
3. Modularity: Modular systems refers to a system that divides its functions
into separate processes.
4. Convenience: It enables the user to perform some tasks and run some
programs at the same time.
14. Methods of Cooperation
There are two ways:
a) Cooperation by Sharing:- Processes can cooperate with each other by
sharing data,memory,files,databases.
Here, P1 and P2 share memory,variables,files,databases etc.
15. b) Cooperation by communication:- This method is
generally tricky to execute. The processes in this
method communicate through passage of messages.
It may lead to a deadlock, if each process is waiting
for a message. If it never receives, it may lead to
starvation.
In the diagram given, the processes
communicate through messages.