Operations on Process in OS

By | September 13, 2021

Operations on Process in OS

Operations on Process in OS: System that manages processes must be able to perform certain operations on and with processes. These operations are :

  1. Create a process
  2. Destroy a process
  3. Suspend a process
  4. Resume a process
  5. Change the priority of a process
  6. Block a process
  7. Wakeup a process
  8. Dispatch a process
  9. Enable interprocess communication i.e. to enable a process to communicate with another process.

1. Creation of Process

  • OS can create a user process or system process.
  • Operating system creates a user process to represent the execution of a user program. This is done when a user types the name of a program to be executed.
  • A system process may be created by OS for its own purpose, eg. to service a request made by user.
  • A process can also create several new processes using a system call called CREATE. In such a case, the creating process is called the parent process and the created process is called the child process.
  • When a process is created by OS at the explicit request of another process, the action is referred to as process spawing.
  • Only one parent is needed to create a child. Such creation yields a hierarchical process structure as shown in figure.

Process Creation hierarchy

  • As shown in the figure each child has only one parent but each parent may have many children. For example B,C, D are the children of process A.
  • In response to the CREATE call, the OS obtains a new PCB from the pool of free memory, fills its different fields with provided and/or default parameters and inserts the PCB into the ready list.

Thus, OS performs the following actions when a new process is created :

  1. Create a process control block (PCB) for the process.
  2. Assign process id and priority.
  3. Allocate memory and other resources to the process.
  4. Set up the process environment i.e. load the process code in the memory, setup the data space to consist of private and shared data area of the process, set up file pointers for standard files etc.
  5. Initialize resource accounting information for the process.

When a process creates a new child, two possibilities exists in terms of execution: 

  1. The parents continues to execute concurrently with its children.
  2. The parent waits until some or all of its children have terminated.

Four common events lead to the creation of a process. These are given in table:-

  1. First, in batch environment, a process is created in response to the submission of a job.
  2. In interactive environment, a process is created when a new user attempts to log on.
  3. A process may also be created by OS on behalf of an application. For example, if a user requests that a file be printed, the OS can create a process that will manage printing.
  4. A process may be created by another process i.e. parent process creates a child process.

Operations on Process in OS: Reasons for process creation

New Batch job The OS is provided with a batch-job control stream, usually on tape or disk when the OS is ready to take on new work, it reads the next sequence of job-control commands.
Interactive log on  A user at a terminal logs on to the system.
Created by OS to provide a service  The OS can create a process to perform a function on behalf of a user program without having to wait (e.g., printing)
Spawned by existing process.  A user program can create a number of new processes in order to perform modularity or to enable parallel processing.

Examples of process creating :

  1. In UNIX operating system, a system call called FORK is used to create a new process. In such a case, a new process consists of a copy of the address original process. The mechanism allows the parent process to communicate easily with its child process. There is difference in the return value of FORK system call for parent and child process. That is, in the child the return value is zero. In the parent the return value is the process id or number of the child. space of
  2. Ada uses the INITIATE statement to create and activate new processes. When several processes are created with a single INITIATE statement, they are executed concurrently.

2. Destroying a process or terminating a process

  • A process terminates when it finishes the execution of its final statement.
  • In such a situation, OS reclaims or deallocates all the resources (attached I/O devices, memory, open files) allocated to the process and remove it from the system.
  • The process control block (PCB) of this process is then erased and the PCB’s memory space is returned to the free pool.

A process can be terminated because of the number of reasons explained below : 

  1. Normal completion. For the normal completion of a process, the process executes an OS services call to indicate that it has completed running.
  2. Time limit exceeded. A process can be terminated if it has run longer than the specified total time limit. 
  3. Memory unavailable. A process can also be terminated if it requires more memory than the system can provide. 
  4. Bounds violation. If a process tries to access memory location that it is not allowed to access then a process is terminated.
  5. Protection error. A process can be terminated if it attempts to use resource or a file that it is not allowed to use.
  6. Arithmetic error. If a process tries to perform a prohibited computation such as division by zero, it can be ended.
  7. Time overrun. If a process has waited longer than the specified maximum time for a certain event to occur, it can be terminated.
  8. I/O failure.

    When an error occurs in input or output, process can be terminated. For example

    : inability to find a file, failure to read or write after a specified maximum number of tries.
  9. Invalid instruction. When a process attempts to execute a nonexistent instruction, it is terminated. e.g. Branching into a data area and attempting to execute the data. 
  10. Privileged instruction. If a process attempts to use an instruction reserved for the operating system, it can be terminated.
  11. Data misuse. If a piece of data is of the wrong type or is not initialized, a process is terminated.
  12. Parent termination. When a parent terminates, the OS may be designed to automatically terminate all the offspring of that parent. This phenomenon is known as cascading termination.
  13. Parent request. A process can also be terminated by its parent as it has authority to do so. This is done by the parent process when the child has exceeded allocated resource and when the task assigned to child is no longer required.

Operations on Process in OS:

Example a process termination: 

In UNIX operating system, a process can be terminated by EXIT system call, The parent process may wait for the termination of a child process by using the WAT system call. The WAIT system call returns the process id of a terminated child, that the parent can tell which of its possibly many children has terminated.

3. Operations on Process in OS: Suspending a process

  • Suspending a process means stopping the execution of a process temporarily. It is also known as sleep or blocking a process.
  • Suspensions normally last only for short periods of time. A process, however remains in the system.
  • A suspended process cannot proceed until another process resumes it.

Suspended process has following characteristics: 

  1. A suspended process is not immediately available for execution. 
  2. The process may or may not be waiting for an event. If it is, this blocked condition is independent of the suspend condition and occurrence of the blocking event does not enable the process to be executed. 
  3. The process can be placed in a suspend state either by itself, by a parent process or by the operating system
  4. Such a suspended process may not be removed from this state until further actions.

The various reasons for the suspension of a process are

  1. In order to enable a ready process to be brought in the main memory, some process need to be swapped out. Therefore a process may be suspended in order to relieve the pressure on the virtual memory system so that each remaining process has more main memory available to it.
  2. An operating system may employ an auditing or tracing process that monitor the activity on the system. This process may be used to record the level of use of various resources (processor, memory, channels) and the rate of progress of the user- processes in the system. The OS may turn this process on and off from time to time.
  3. If the operating system detects or suspects a problem it may suspend a process eg in case of a deadlock.
  4. If a user suspects a flaw in the program, the user may debug the program by suspending its execution, and then after examining and modifying the program or data, the user may resume its execution.
  5. Timing consideration may also lead to the suspension of a process. For example, ir process is to be activated periodically but is idle most of the time, then it should be swapped out between users. 
  6. A parent process may wish to suspend any of its child process.

Reasons for process suspension: Operations on Process in OS

Swapping The OS needs to release sufficient main memory to bring in process is ready to execute.
Other OS reason  The OS may suspend a background or utility process or a process that is suspected of causing a problem.
Interactive user request A user may wish to suspend the execution of a program for purposes of debugging or in connection with the use of a resource.
Timing A process may be executed periodically (eg- an accounting or system monitoring process) and may suspended while waiting for the next time interval.
Parent process request A parent process may wish to suspend the execution of a descendant to  examine or modify the suspended process or to coordinate the activity of descendants. 

4. Operations on Process in OS: Resuming a process

  • Resuming a process means restarting it from the point at which suspended.
  • A suspended process need another process for its restoration as it cannot resume itself.
  • Whenever a process resumes any suspended process the OS inserts the target process’s PCB in the ready list and update its state from suspended to ready.
  • The resume service also called wakeup in some system.

5. Changing the priority of a process

  • The priority of a process can changed in run time.
  • The process’s priority may changed so as to increase or decrease the process’s ability to compete for system resources.
  • The priority of a process is changed by modifying the priority value in the process control block (PCB) of a process.

One thought on “Operations on Process in OS

  1. Pingback: Difference between High level language and Low level language

Comments are closed.