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:
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:
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.
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: