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

Defination of the essential properties of operating systems

Define the essential properties of the following types of operating sys-tems:  Batch  Interactive  Time sharing  Real time  Network  Parallel  Distributed  Clustered  Handheld ANSWERS: a. Batch processing:-   Jobs with similar needs are batched together and run through the computer as a group by an operator or automatic job sequencer. Performance is increased by attempting to keep CPU and I/O devices busy at all times through buffering, off-line operation, spooling, and multi-programming. Batch is good for executing large jobs that need little interaction; it can be submitted and picked up later. b. Interactive System:-   This system is composed of many short transactions where the results of the next transaction may be unpredictable. Response time needs to be short (seconds) since the user submits and waits for the result. c. Time sharing:-   This systems uses CPU scheduling and multipro-gramming to provide economical interactive use of a system. The CPU switches rapidl

What is a Fair lock in multithreading?

  Photo by  João Jesus  from  Pexels In Java, there is a class ReentrantLock that is used for implementing Fair lock. This class accepts optional parameter fairness.  When fairness is set to true, the RenentrantLock will give access to the longest waiting thread.  The most popular use of Fair lock is in avoiding thread starvation.  Since longest waiting threads are always given priority in case of contention, no thread can starve.  The downside of Fair lock is the low throughput of the program.  Since low priority or slow threads are getting locks multiple times, it leads to slower execution of a program. The only exception to a Fair lock is tryLock() method of ReentrantLock.  This method does not honor the value of the fairness parameter.

How do clustered systems differ from multiprocessor systems? What is required for two machines belonging to a cluster to cooperate to provide a highly available service?

 How do clustered systems differ from multiprocessor systems? What is required for two machines belonging to a cluster to cooperate to provide a highly available service? Answer: Clustered systems are typically constructed by combining multiple computers into a single system to perform a computational task distributed across the cluster. Multiprocessor systems on the other hand could be a single physical entity comprising of multiple CPUs. A clustered system is less tightly coupled than a multiprocessor system. Clustered systems communicate using messages, while processors in a multiprocessor system could communicate using shared memory. In order for two machines to provide a highly available service, the state on the two machines should be replicated and should be consistently updated. When one of the machines fails, the other could then take‐over the functionality of the failed machine. Some computer systems do not provide a privileged mode of operation in hardware. Is it possible t