[Orphans in the Linux world]

In Linux, a process is created by the fork() function and the vfork() function. Processes are created by the parent process. Generally, after the child process exits, the parent process is required to clean up the "garbage" left after the child process exits. The parent process is the termination of the child process obtained by calling the wait() or waitpid() system call. condition.

 

The orphan process

 

1. What is an orphan process

If the parent process of a child process ends before the child process, the child process becomes an orphan process, which is adopted by the init (pid=1) process and becomes the child process of the init process

 

An orphan process is a process whose parent process terminates before the child process. It will be taken over by init, and its parent process will become 1.

 

The concept of an orphan process group: the parent process of each member of the group is either a member of the group or not a member of the session to which the group belongs.

A process group is not an orphan process group: the group has a process whose parent is in another group in the same session. A process group is not an orphan process group, a parent process in another group belonging to the same session has the opportunity to restart a stopped process in that group.

 

The concept of an orphan process group can be understood as all the processes in the group are built into a tree structure according to the parent-child relationship, and the root of the tree is init(1). If all the processes in the group are covered in the nodes of this tree, it means that these processes constitute orphans process group.

 

 

The orphan process is a process without a parent process, and the heavy responsibility of the orphan process falls on the init process. The init process is like a civil affairs bureau, which is specially responsible for the aftermath of the orphan process. Whenever an orphan process occurs, the kernel sets the parent process of the orphan process to init, and the init process cyclically wait() its exited child process. In this way, when an orphan process bleakly ends its life cycle, the init process will handle all its aftermath on behalf of the party and government. So orphaned processes are not harmful.

 

Summarize:

Orphan process: A parent process exits, and one or more of its child processes are still in progress, then those child processes will become orphan processes, and the orphan process will be adopted by the init process (process number 1), and by the init process. Complete the status collection work. Zombie resources cause resource waste, orphan processes do not.

 

2. What is a daemon process?

 

(daemon) A process that runs in the background and has no controlling terminal attached to it. It is independent of the controlling terminal. Usually performs some kind of task periodically.

 

1. Why should the daemon run out of the background?

The daemon is separated from the terminal in order to prevent the information of the process during execution from being displayed on any terminal and the process will not be interrupted by terminal information generated by any terminal.

 

2. Why introduce a daemon process:

Because in Linux, the interface where each system communicates with users is called a terminal, and every process that starts running from this terminal will be attached to this terminal, and this terminal is called the controlling terminal of these processes. When the controlling terminal is closed, The corresponding processes are automatically closed. But the daemon process can overcome this limitation, it starts running from being executed, and does not exit until the whole system is shut down. If you want a process not to be affected by changes in user or terminal or whatever, you have to turn the process into a daemon.

 

3, the characteristics of the daemon process

1> The most important feature of the daemon is to run in the background.

2> Second, the daemon must be isolated from the environment in which it runs. These environments include unclosed file descriptors, controlling terminals, session and process groups, working directories, and file creation masks, among others. These environments are usually inherited by the daemon process from the parent process (specifically the shell) that executes it.

3> Finally, there is something special about the way the daemon is started. It can be started from the startup script /etc/rc.d when the Linux system starts, by the job planning process crond, and by the user terminal (usually a shell).

 

4. There are several ways to start the daemon process:

a. It can be started from the startup script /etc/rc.d when the Linux system starts

b. It can be started by the job planning process crond;

c. Can also be executed by the user terminal (usually the shell).

 

Summarize:

 Daemons are background service processes in Linux. It is a long-lived process that is usually independent of the controlling terminal and periodically performs some kind of task or waits for some event to occur. The daemon is usually started when the system is booted and terminated when the system is shut down. There are many daemon processes in the Linux system. Most services are implemented through daemon processes. At the same time, daemon processes can also complete many system tasks, such as job planning process crond, printing process lqd, etc. (the letter d at the end here means Daemon. ).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326269465&siteId=291194637