Skip to main content

What is a process? What is the difference between an orphan process and a zombie process? What is a daemon process? What is a thread? What are the two types of threads? What is the difference between a process and a thread?

 What is a process?

A process is a program being executed and is the basic unit of operating system resource allocation. Generally speaking, a process contains instructions, data, and PCB.

 

What is the difference between an orphan process and a zombie process?

Orphan process means that a parent process exits while one or more of its child processes are still running, then these child processes will become orphan processes. The orphan process will be adopted by the init process (process with process ID 1), and the init process will complete the state collection work for them. Because the orphan process will be adopted by the init process, the orphan process will not cause harm to the system.

A zombie process is a process descriptor of a child process that will not be released when the child process exits. It will only be released when the parent process obtains the child process information through wait() or waitpid(). If the child process exits and the parent process does not call wait() or waitpid(), then the process descriptor of the child process is still stored in the system. This kind of process is called a zombie process. The status displayed by the zombie process through the ps command is Z.

The number of processes that the system can use is limited. If a large number of zombie processes are generated, the system may not be able to generate new processes because there are no available process numbers. If you want to eliminate a large number of zombie processes in the system, you only need to kill its parent process. At this time, the zombie process will become an orphan process and will be adopted by the init process, so that the init process will release all the zombie processes occupied Resources, thereby ending the zombie process.

 

What is a daemon process?

The daemon process is a special process running in the background, which is independent of the control terminal and performs certain tasks periodically.

 

What is a thread?

Threads are different execution paths within a process, and are the basic unit of independent scheduling by the operating system. There can be multiple threads in a process, and they share process resources. For example, WeChat and the browser are two processes. There are many threads in the browser process, such as HTTP request thread, event response thread, rendering thread, etc. The concurrent execution of threads makes it possible to click on a new link in the browser to initiate HTTP When requested, the browser can also respond to other events of the user.

 

What are the two types of threads?

User level thread: For this type of thread, all work related to thread management is done by the application, and the kernel is not aware of the existence of the thread. After the application is started, the operating system allocates a process number to the program, and its corresponding memory space and other resources. The application usually runs in a thread first, which is called the main thread. At some point in its operation, a new thread running in the same process can be created by calling a function in the thread library. The advantage of user-level threads is that they are very efficient and do not need to enter the kernel space, but the concurrency efficiency is not high.

Kernel level thread: For this type of thread, all work related to thread management is done by the kernel. The application program has no code for thread management and can only call the interface of the kernel thread. The kernel maintains the process and each thread inside, and the scheduling is also done by the kernel based on the thread architecture. The advantage of kernel-level threads is that the kernel can better allocate different threads to different CPUs to achieve true parallel computing.

In fact, in modern operating systems, multithreading is often implemented in combination, that is, thread creation is completely completed in user space, and multiple user-level threads in an application are mapped to some kernel-level threads, which is equivalent to one A compromise solution.

 

What is the difference between a process and a thread?

Own resources

The process is the basic unit of resource allocation, but the thread does not own resources, and the thread can access the resources belonging to the process.

 Scheduling

Thread is the basic unit of independent scheduling. In the same process, thread switching will not cause process switching. When switching from a thread in one process to a thread in another process, it will cause process switching.

 System overhead

When creating or canceling a process, the system must allocate or reclaim resources for it, such as memory space, I/O devices, etc., and the cost is much greater than the cost of creating or canceling threads. Similarly, when performing process switching, involves saving the CPU environment of the current executing process and setting the CPU environment of the new scheduling process, while only a few register contents need to be saved and set during thread switching, and the overhead is small.

 

Communications

 Threads can communicate by directly reading and writing data in the same process, but process communication requires the help of IPC.

 

Comments

Popular posts from this blog

40 Redis interview questions for 2021 - 2022

  Redis interview questions 1.What is Redis?. 2. What is the data type of Redis? 3. What are the benefits of using Redis? 4. What are the advantages of Redis over Memcached? 5. What are the differences between Memcache and Redis? 6. Is Redis single-process and single-threaded? 7. What is the maximum storage capacity of a string type value? 8. What is the persistence mechanism of Redis? Their advantages and disadvantages? 9. Redis common performance problems and solutions: 10. What is the deletion strategy of redis expired keys? 11. Redis recycling strategy (elimination strategy)? 12. Why does edis need to put all data in memory? 13. Do you understand the synchronization mechanism of Redis? 14. What are the benefits of Pipeline? Why use pipeline? 15. Have you used Redis cluster? What is the principle of cluster? 16. Under what circumstances will the Redis cluster solution cause the entire cluster to be unavailable? 17. What are the Java clients supp...

Recursion-maze problem - Rat in the Maze - Game

  package com.bei.Demo01_recursion; public class MiGong {     public static void main(String[] args)  {         //First create a two-dimensional array to simulate the maze         int [][]map=new int[8][7];         //Use 1 for wall         for (int i = 0; i <7 ; i++) {             map[0][i]=1;             map[7][i]=1;         }         for (int i = 0; i <8 ; i++) {             map[i][0]=1;             map[i][6]=1;         }         //Set the bezel         map[3][1]=1;         map[3][2]=1;         //Output         for (int i = 0; i <8 ; i++) {             for (int j = 0; j ...

165 + Big Data and Artificial intelligence ( AI ) terms and terminology Glossary

  Latest and most comprehensive big data/artificial intelligence terms & terminology in English (highly recommended for collection) for years 2021 and 2022   A  1.  Apache Kafka:  named after the Czech writer Kafka, used to build real-time data pipelines and streaming media applications. The reason it is so popular is that it can store, manage, and process data streams in a fault-tolerant manner, and it is said to be very "fast". Given that the social network environment involves a lot of data stream processing, Kafka is currently very popular.