This series of articles is my learning summary, the original video: time.geekbang.org/column/intr…

Processes and threads

A process is a running instance of a program. When a process is started, the operating system creates an area of memory for the process to store code, running data, and the main thread. Such an environment is called a process.

A process can create and manage multiple threads, which are processed in parallel to improve computing efficiency.

1. The relationship between processes and threads:

– If any thread in the process fails, the process crashes.

– All threads in a process share data in the process.

– When a process is stopped, the OS reclaims the memory occupied by the process. (So in a multi-process browser, when the page crashes in an infinite loop, we just force the page.)

– The contents of processes are isolated from each other. The crash of one process does not affect other processes.

Second, single-process browser

Single-process browser, as its name implies, means that all the functional modules of the browser are in a process, including the network, rendering engine, JS runtime environment, plug-ins, etc.

Problems with single-process browsers include:

  • One thread error can cause the entire browser to crash. Plug-ins, for example. In addition, if we accidentally write an infinite loop in our JS code, the entire browser will crash.
  • Too many operations need to be performed in the page thread, and if a piece of code in JS takes too long to execute, it will block subsequent page rendering and page display.
  • The process data is shared, which means we can exploit vulnerabilities in the browser to directly operate the system, which is not secure.
  • Single-process browsers can also slow down the entire browser due to memory leaks. When a page is more complex, when we close the page, memory is not reclaimed, only when the entire browser is closed, that is, the entire process is closed, so the memory footprint gets higher and higher, and the browser runs slower and slower.

3. Multi-process browser

Early multiprocess browsers

Early browser processes were: plug-in process, renderer process, browser main process, as shown. Single-process browser fixes:

  • Processes are isolated from each other, so a crash of one process only affects the current page, not the entire browser.
  • Plugin processes and renderers run in sandboxes, so even if there is a malicious program in a plugin, it cannot operate the system.
  • Because of the multi-process, browsers don’t get slower and slower because when a page closes, the rendering process is shut down and memory is reclaimed.

2. Today’s multi-process browsers

Now the browser processes are: renderer, main browser process, GPU process, plug-in process, network process.

For security reasons, the renderer and plug-in processes run in a sandbox.

Returning to the topic, how many processes can open a page?

The answer is that at least four processes will open:

– Browser main process,

– process of GPU

– Render process

– Network Indicates the Network process

– Plug-in process (only available when the plug-in is open)

– Storage service: the Storage service is enabled only when the Storage function is used.

If plug-ins are also opened at this point, there is a process for each type of plug-in.