1. What is process?
A process is a running instance of a program. When a program is started, the operating system creates a block of memory for the program to hold the code, the running data, and a main thread to perform the task. We call such a running environment a process. A process is a unit of resource allocation.
2. What are threads?
Thread is attached to process, and using multi-thread parallel processing in process can improve computing efficiency. Threads are the smallest unit of program execution and have no independent address space. A process is a unit of resource allocation.
3. The relationship between processes and threads
- An error in execution by any thread in the process (possibly destroying a shared resource) can cause the entire process to crash.
- Threads share data in a process.
- When a process is shut down, the operating system reclaims the memory occupied by the process.
- The contents of the processes are isolated from each other.
4. What is a child process?
Create a new process from within an existing process. The new process is called a child process, and the process that created the child process is correspondingly called a parent process. The child process completely copies the parent process’s resources, including the process context, code area, data area, heap area, stack area, memory information, open file descriptor, signal processing function, process priority, process group number, current working directory, root directory, resource limits and control terminal information, etc. The child process differs from the parent process by process number, resource usage, timer, and so on.
5. How many processes does a browser need to open a page?
The latest Chrome process architecture includes the following processes: Main browser process (one) : responsible for interface display, user interaction, child process management, and storage. Rendering process (multiple) : The core task is to turn HTML, CSS, and JavaScript into web pages that users can interact with. Both the typography engine Blink and JavaScript engine V8 run in this process. The renderer process runs in a sandbox. GPU process (one) : The UI is drawn on a GPU. Network process (one) : responsible for loading network resources for a page. Plug-in processes (multiple) : Responsible for running plug-ins.
Therefore, the browser needs at least four processes to open a page: the browser main process + rendering process + GPU process + network process.
Typically, browsers create a rendering process for a TAB. However, if several pages belong to the same site, the new page will reuse the parent page’s renderer process and they will be assigned to a renderer process. Because within A rendering process, they share the JS execution environment, meaning that page A can execute scripts directly from page B. So if one page crashes, all the pages on the same site crash at the same time.