Javatpoint Logo
Javatpoint Logo

Difference between Routine and Process

In this article, you will learn about the difference between routine and process, but before discussing the differences, you have to know briefly about the routine and process.

What is Routine in OS?

In computer programming, a routine is a sequence of code that is intended to be called and used repeatedly during the execution of a program. It can range from a subroutine, co-routine to a function. This makes the program shorter and easier to write and read when necessary.

It is called repeatedly by other codes during the execution of a program. Whenever a program needs to perform a specific task, the main sequence of logic in a program can branch off to a common routine when necessary. When finished, the routine branches back to the next sequential instruction, following the instruction that branched to it. A routine may also be useful in more than one program and save other programmers from writing code that can be shared.

A routine is also known as a function with a specified programming interface in higher-level languages. It can be used in a program to perform a particular task many times, obviously with different data values.

Typically, a routine that requires some variable input can be encoded into a macro definition with a specified interface called a macro instruction in assembler languages. The programmer can then use a macro instruction instead of including and managing the branching to a routine. Macro definitions and instructions also tend to be shared among programmers for use in multiple programs, especially software development projects.

Many commonly-needed routines are prepackaged as functions with specified programming interfaces in higher-level computer languages. Some functions can be compiled in line with other code. Other functions are compiled as a stub that makes dynamic calls for system services during program execution. Functions are sometimes called library routines. The compiler and library routines usually come as part of a related software development package.

In Windows and other personal computer operating systems, the system routines for handling specific tasks such as interacting with specific I/O devices are called dynamic link library routines. These routines are dynamic because their files are not actually loaded into memory until they are called.

For example, a routine may save a file or display the time. Instead of writing the code each time these commonly performed tasks are needed, routines are created and called when these tasks need to be performed.

What is Process in OS?

The process is a program in execution and represents the basic unit of CPU utilization.

The OS helps create, schedule, and terminate the processes used by the CPU. A process is an active entity created when an executable file gets loaded into the main memory for execution. A process created by the main process is called a child process.

A system compromises many processes, some of which execute the system code known as the operating-system processes. In contrast, the rest of the processes that execute the user code are called user processes. The process is divided into the following sections for efficient working:

  • The Text sectionis made up of the compiled program code, read in from non-volatile storage when the program is launched.
  • The Data section is made up of the global and static variables, allocated and initialized before executing the main.
  • The Heapis used for the dynamic memory allocation and is managed via calls to new, delete, malloc, free, etc.
  • The Stackis used for local variables. Space on the stack is reserved for local variables when they are declared.

Sometimes, we get confused with the terms Program and Process, but the two are different entities. The program is a passive entity, while the process is an active entity. A process has numerous states defined by the current activity of that process.

Process Control Block (PCB) considers as the brain of the process, which contains all the crucial information related to processing like process id, priority, state, CPU registers, etc. Each process is represented by a Process Control Block in the operating system. Below are important components of PCB, such as:

  • Process Id: Every process will be given an id called Process Id to identify that process from the other processes uniquely.
  • Process state: Every process has some states associated with it at a particular instant of time. This is denoted by process state. It can be ready, waiting, running, etc.
  • Program counter: The program counter lets you know the address of the next instruction, which should be executed for that process.
  • CPU registers: This componentincludes accumulators, index and general-purpose registers, and condition code information.
  • CPU scheduling information:Each process is executed by using some process scheduling algorithms like FCSF, Round-Robin, SJF, etc.
  • Accounting and business information: It includes the amount of CPU and time utilities like real-time used, job or process numbers, etc.
  • Memory-management information: This information includes the value of the base and limit registers, the page, or segment tables. This depends on the memory system, which is used by the operating system.
  • I/O information: Each process needs some I/O devices for their execution. So, the device information allocated and device need is crucial.

For example, when you want to search for something on the web, you start a browser. So, this can be processed. Another example of a process can be starting your music player to listen to some cool music of your choice.

Difference between Routine and Process

There is a huge difference between a process and a routine in the operating system. A process is a code that is actually in execution. A routine usually means a piece of code such as a subroutine, co-routine, or function that is called by other code somehow. This implies that one routine could be part of the codes executed in two (or more) processes.

Routine vs Process

A routine is a sequence of code, while a process is actually a code in execution. A routine is used to perform a specific task, and it can be a part of multiple processes. Below are some more differences between routine and process, such as:

Terms Routine Process
Definition It is a sequence of code intended to execute user programs and input/output operations. It is a program in execution, unit of work in modern time-sharing systems.
Role The role of a routine is to perform a task, and a routine can be called many a time by other routines or subroutines. Its role is to execute a sequence of code. It represents the basic unit of work to be implemented in a system.
Functionality It can be used in a program to perform a particular task many times. A process can be of two types: one executes the system code, while the other executes the user code.
Example A routine to multiply two numbers, add two numbers, etc., is called repeatedly. A calculator is a process responsible for doing several operations on an operand.






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA