Daemon ppid 1 https://unix.stackexchange.com/questions/240646/why-we-use-setsid-while-daemonizing-a-process nohup modify ppid 1

Daemon


PPID 1


https://unix.stackexchange.com/questions/240646/why-we-use-setsid-while-daemonizing-a-process

nohup modify ppid 1

 

https://pubs.opengroup.org/onlinepubs/7908799/xsh/setsid.html

 

 

https://github.com/karelzak/util-linux/blob/master/sys-utils/setsid.c

 

 

https://unix.stackexchange.com/questions/316186/how-does-nohup-work

 

 

 

The act of using nohup simply changes the PPID of the spawned process to 1 (init) so that when the shell exits, it is no longer a child process of that shell and so therefor doesn't receive a HUP.

EDIT: Should think more before I post sometimes. Leaving it here to remind me of my shame :-(

 

 

https://zh.wikipedia.org/wiki/ orphaned

In the field of operating systems, the orphan processes (Orphan Process) refers in its parent process or the implementation of complete termination of the latter category continues to run the process .

 

Solution

"adoption"

In UNIX-like operating system , in order to avoid not release the occupied resources when the process exits orphans and dead, orphaned when any will immediately generate a system process init or systemd automatically receive as a child process, this process is also known as "adoption "(English: Re-Parenting) [1] . It should be noted here, despite the fact that the process has init as its parent process, but the process of the process of creation does not exist, it should still be called "orphaned."

Process Group

Because the parent process will lead to a corresponding termination or crash the child process orphaned process, so it can not expect a child during the process whether execution will be "abandoned." In view of this, most UNIX-like systems have introduced a process group to prevent orphan processes: when the parent process terminates, the user's Shell will process where the parent group labeled as "orphan process group" and to subordinate the process terminates all sub-process issues SIGHUP signal, in an attempt to end its run, so to avoid the child process continues to run as "orphan process" [2] .

Situation of remote calls

RPC process will also produce orphaned. For example, if the client process after the sudden collapse initiated the request, and the corresponding server-side process is still running, the server process will become orphaned. Such a process will waste server resources orphans, and even potentially dangerous depletion of resources, but also has a corresponding solution [3] :

  1. Termination mechanism: Forced to kill orphan processes (the most commonly used means);
  2. Regeneration mechanism: server looks up client calls within a specified time, if no directly kill orphan process;
  3. Timeout mechanism: each process to specify a certain running time, if the timeout has not yet completed the mandatory termination. If necessary, the application process will also allow delay before the specified time runs out.

"Orphaned" applications

In addition, users may also deliberately making process orphaned process to make it delinked from the user session, and go running in the background. This approach often used to start the process takes a long time to run, that daemon [4] . Further, UNIX command nohup can accomplish this operation [5] .

 

 

https://linux.die.net/man/3/execvp

The exec() family of functions replaces the current process image with a new process image. The functions described in this manual page are front-ends for execve(2). (See the manual page for execve(2) for further details about the replacement of the current process image.)

The initial argument for these functions is the name of a file that is to be executed.

Guess you like

Origin www.cnblogs.com/yuanjiangw/p/12180665.html