Process And Threads
Process means any program is in execution. Process control block controls the operation of any process. Process control block contains the information about processes for example: Process priority, process id, process state, CPU, register etc. A process can creates other processes which are known as Child Processes. Process takes more time to terminate and it is isolated means it does not share memory with any other process.
Thread is the segment of a process means a process can have multiple threads and these multiple threads are contained within a process. Threads share the address space of the process that created it. A thread have 3 states: running, ready, and blocked. Thread takes less time to terminate as compared to process and like process threads do not isolate. processes have their own copy of the data segment of the parent process and Threads have direct access to the data segment of its process. Both Process and threads used to achieve concurrency in web browsers.
Process and Threads in Chrome
By default, Chrome creates a process for each tab of a web site the user visits and plugins extensions it uses. This ensures that pages from different sites are rendered independently, and that separate visits to the same site are also isolated from each other. Thus, failures (e.g., site crashes) or heavy resource usage in one instance of a site will not affect the rest of the browser. There is also processes for main browser and GPU functionality.
Google Chrome creates three different types of processes: browser, renderers, and plug-ins.
Browser :- There’s only one browser process, which manages the tabs, windows, and “chrome” of the browser. This process also handles all interactions with the disk, network, user input, and display, but it makes no attempt to parse or render any content from the web.
Plug-ins :- The browser process also creates one process for each type of plug-in that is in use, such as Flash, Quicktime, or Adobe Reader. These processes just contain the plug-ins themselves, along with some glue code to let them interact with the browser and renderers.
GPU :- Handles GPU tasks in isolation from other processes. It is separated into different process because GPU handles requests from multiple apps and draw them in the same surface.
The advantage of the multiprocess approach is that websites run in isolation from one another. If one website crashes, only its renderer process is affected. all other processes remain unharmed. Furthermore, renderer processes run in a sandbox, which means that access to disk and network I/O is restricted, minimizing the effects of any security exploits.
Process and Threads Firefox
Currently, the latest versions of Firefox run the browser UI and the web content in separate processes. In the current iteration of this architecture, all browser tabs run within the same process and the browser UI runs in its own individual process.
In future iterations of Firefox, there will be more than one process to exclusively handle web content.
Mozilla started project Electrolysis as a gradual move to a multi-process architecture.
The Current architecture of Firefox has a main process, one GPU process, one extension process, up to 4 tab processes.
Chrome vs Firefox
While both Firefox and Chrome now run using multiple processes, Firefox does some things differently to avoid using up user computer’s limited memory.
By default, Chrome creates a separate content process for each instance of a site that you visit. Open 10 different tabs with 10 sites in Chrome, and it will have 10 different processes. Each of those processes has its own memory — with their own instance of the browser’s engine. One open tab in Chrome typically consumes hundreds of megabytes of RAM. Chrome’s liberal approach to creating processes can lead to very high memory usage.
On the other hand, Firefox’s more conservative approach to using processes often results in Firefox using less memory than Chrome. By default, Firefox now creates up to 4 separate processes for web page content. So, your first 4 tabs each use those 4 processes, and additional tabs run using threads within those processes. Multiple tabs within a process share the browser engine that already exists in memory, instead of each creating their own.