What is process?
In computing, a process is the instance of a computer program that is being executed by one or many threads. It contains the program code and its activity. Depending on the operating system(OS), a process may be made up of multiple threads of execution that execute instructions concurrently. process is the actual execution of instructions.
Types of process;
What are threads?
A thread of execution is the smallest sequence of programmed instructions that can be managed independently by a scheduler, which is typically a part of the operating system. The implementation of threads and process differs between operating systems, but in most cases a thread is a component of a process. Multiple threads can exist within one process, executing concurrently and sharing resources such as memory, while different processes do not share these resources.
There are 2 types threads.
1. Single threading
single-threading is the processing of one command at a time.
In the formal analysis of the variables’ semantics and process state, the term single threading can be used differently to mean “backtracking within a single thread”, which is common in the functional programming community.
Multi-threading is mainly found in multitasking operating systems. Multi-threading is a widespread programming and execution model that allows multiple threads to exist within the context of one process. These threads share the process’s resources, but are able to execute independently. The threaded programming model provides developers with a useful abstraction of concurrent execution. Multi-threading can also be applied to one process to enable parallel execution on a multiprocessing system.
Threads Vs. Processes
· processes are typically independent, while threads exist as subsets of a process
· processes carry considerably more state information than threads, whereas multiple threads within a process share process state as well as memory and other resources.
· processes have separate address spaces, whereas threads share their address space
· processes interact only through system-provided inter-process communication mechanisms
· context switching between threads in the same process typically occurs faster than context switching between processes.
Executing program on Process and Thread
A process can be described as an application’s executing program. A thread is the one that lives inside of process and executes any part of its process’s program.
When you start an application, a process is created. The program might create thread to help it do work, but that’s optional. The Operating System gives the process a “slab” of memory to work with and all application state is kept in that private memory space. When you close the application, the process also goes away and the Operating System frees up the memory.
A process can ask the Operating System to spin up another process to run different tasks. When this happens, different parts of the memory are allocated for the new process. If two processes need to talk, they can do so by using Inter Process Communication (IPC). Many applications are designed to work this way so that if a worker process get unresponsive, it can be restarted without stopping other processes which are running different parts of the application.
Chrome was the first browser with a multi-process architecture. Put simply, it encapsulates all logical functions in separate processes. More specifically:
- One main (browser) process
- One GPU process
- Each tab: dedicated process
- Each extension: dedicated process
Chrome is the only browser with a useful task manager. It can be opened with the keyboard shortcut SHIFT+ESC. Task Manager lists all active Chrome processes with their designated functions. For each process, it shows CPU, network and memory resource usage. It also indicates whether frames are hosted in their page’s process or in dedicated processes. Finally, Task Manager shows the Windows OS process ID, which makes it possible to correlate data with other system information tools.
Mozilla started project Electrolysis as a gradual move to a multi-process architecture. The current architecture looks like this:
- One main process
- One GPU process
- One extension process
- Up to 4 content (tab) processes
The current default of 4 content processes might be changed in future versions. At this point, it can be increased to a maximum value of 7 content processes. Work is underway to encapsulate extensions in dedicate processes.
Chrome Vs. Firefox
Chrome and Firefox now both support multi-threading, but they do it in different ways. In Chrome, each and every tab you open gets its own content process. Ten tabs, 10 processes. One hundred tabs, 100 processes. This approach maximizes performance, but you pay a hefty penalty in memory consumption and (when applicable) battery life. Firefox doesn’t take this approach to the problem, but instead spins up to four content process threads by default.
Mozilla claims that Firefox also uses dramatically less memory than other competing browsers, with Chrome using 1.77x more RAM than Firefox in 64-bit and 2.44x in 32-bit mode. The differences were less dramatic in Mac OS X and Linux (1.36x and 1.42x, respectively). According to the team, Firefox leads in every category. RAM usage isn’t a battery life issue — memory consumes about the same amount of power whether you are storing data in it or not, provided that you aren’t running some kind of page-hammering benchmark. But having more RAM available does mean a better, smoother experience when juggling a lot of open tabs while running other programs.
chrome uses multiprocessing and Firefox uses Multi-threading. So each tab in chrome is a process whereas in Firefox each tab is a thread. since multi-threading is faster; Firefox is faster (due to shared memory, context switching is faster in threads).
However, it is important to note that, chrome is less likely to crash since if a tab(process) crashes, it won’t crash the entire browser. opposite is true in case of Firefox.