Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Parent process

From Wikipedia, the free encyclopedia
Computing software instance that has created one or more child processes
This article has multiple issues. Please helpimprove it or discuss these issues on thetalk page.(Learn how and when to remove these messages)
icon
This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed.
Find sources: "Parent process" – news ·newspapers ·books ·scholar ·JSTOR
(April 2024) (Learn how and when to remove this message)
icon
This article'slead sectionmay be too short to adequatelysummarize the key points. Please consider expanding the lead toprovide an accessible overview of all important aspects of the article.(January 2025)
(Learn how and when to remove this message)

In computing, aparent process is aprocess that has created one or morechild processes.

Unix-like systems

[edit]

InUnix-likeoperating systems, every process exceptprocess 0 (the swapper) is created when another process executes thefork()system call. The process that invoked fork is theparent process and the newly created process is thechild process. Every process (except process 0) has one parent process, but can have many child processes.[1]

Theoperating system kernel identifies each process by its process identifier.Process 0 is a special process that is created when the system boots; after forking a child process(process 1),process 0 becomes theswapper process (sometimes also known as the "idle task").Process 1, known asinit, is the ancestor of every other process in the system.[2]

Linux

[edit]

In theLinux kernel, in which there is a very slim difference between processes andPOSIX threads, there are two kinds of parent processes, namely real parent and parent. Parent is the process that receives theSIGCHLD signal on child's termination, whereas real parent is the thread that actually created this child process in a multithreaded environment. For a normal process, both these two values are same, but for a POSIX thread which acts as a process, these two values may be different.[3]

Zombie processes

[edit]
Main article:Zombie process

The operating system maintains a table that associates every process, by means of itsprocess identifier (generally referred to as "pid") to the data necessary for its functioning. During a process's lifetime, such data might include memory segments designated to the process, the arguments it's been invoked with,environment variables, counters about resource usage, user-id, group-id and group set, and maybe other types of information.

When a process terminates its execution, either by callingexit (even if implicitly, by executing areturn command from themain function) or by receiving asignal that causes it to terminate abruptly, the operating system releases most of the resources and information related to that process, but still keeps the data about resource utilization and thetermination status code, because a parent process might be interested in knowing if that child executed successfully (by using standard functions to decode the termination status code) and the amount of system resources it consumed during its execution.

By default, the system assumes that the parent process is indeed interested in such information at the time of the child's termination, and thus sends the parent the signalSIGCHLD to alert that there is some data about a child to be collected. Such collection is done by calling a function of thewait family (eitherwait itself or one of its relatives, such aswaitpid,waitid orwait4). As soon as this collection is made, the system releases those last bits of information about the child process and removes its pid from the process table. However, if the parent process lingers in collecting the child's data (or fails to do it at all), the system has no option but keep the child's pid and termination data in the process table indefinitely.

Such a terminated process whose data has not been collected is called azombie process, or simply azombie, in the UNIX parlance. The name is a humorous analogy due to considering terminated process as "no longer alive" or "dead"—since it has really ceased functioning—and a lingering dead process still "incarnated" in the "world of the living" processes—the process table—which is therefore actually "undead", or "zombie".

Zombie processes might pose problems on systems with limited resources or that have limited-size process tables, as the creation of new, active processes might be prevented by the lack of resources still used by long lasting zombies.

It is, therefore, a good programming practice in any program that might spawn child processes to have code to prevent the formation of long lasting zombies from its original children. The most obvious approach is to have code that callswait or one of its relatives somewhere after having created a new process. If the program is expected to create many child processes that may execute asynchronously and terminate in an unpredictable order, it is generally good to create ahandler for theSIGCHLD signal, calling one of thewait-family function in a loop, until no uncollected child data remains. It is possible for the parent process to completely ignore the termination of its children and still not create zombies, but this requires the explicit definition of a handler forSIGCHLD through a call tosigaction with the special option flagSA_NOCLDWAIT.[4]

Orphan processes

[edit]
Main article:Orphan process

Orphan processes are an opposite situation to zombie processes, referring to the case in which a parent process terminates before its child processes, which are said to become "orphaned". Unlike the asynchronous child-to-parent notification that happens when a child process terminates (via theSIGCHLD signal), child processes are not notified immediately when their parent finishes. Instead, the system simply redefines the "parent PID" field in the child process's data to be the process that is the "ancestor" of every other process in the system, whose PID generally has the value of 1 (one), and whose name is traditionally "init" (except in the Linux kernel 3.4 and above [more info below]). Thus, it was said that init "adopts" every orphan process on the system.[5][6]

A somewhat common assumption by programmers new to UNIX was that the child processes of a terminating process will be adopted by this process's immediate parent process (hence those child processes' "grandparent"). Such assumption was incorrect – unless, of course, that "grandparent" was the init itself.

After Linux kernel 3.4 this is no longer true, in fact processes can issue theprctl() system call with the PR_SET_CHILD_SUBREAPER option, and as a result they, not process #1, will become the parent of any of their orphaned descendant processes. This is the way of working of modern service managers and daemon supervision utilities including systemd, upstart, and the nosh service manager.

This is an abstract of the manual page, reporting that:

A subreaper fulfills the role of init(1) for its descendant processes. When a process becomes orphaned (i.e., its immediate parent terminates) then that process will be reparented to the nearest still living ancestor subreaper. Subsequently, calls to getppid() in the orphaned process will now return the PID of the subreaper process, and when the orphan terminates, it is the subreaper process that will receive a SIGCHLD signal and will be able to wait(2) on the process to discover its termination status.[7]

References

[edit]
  1. ^This article is based on material taken fromParent+process at theFree On-line Dictionary of Computing prior to 1 November 2008 and incorporated under the "relicensing" terms of theGFDL, version 1.3 or later.
  2. ^Tanenbaum, Andrew (2007).Modern operating systems (3rd ed.). Pearson Prentice Hall. p. 752.ISBN 978-0136006633.
  3. ^Srinivasan, Sundar (2010-09-01)."An Engineer's Options & Futures: A Sneak-Peek into Linux Kernel - Chapter 2: Process Creation". Sunnyeves.blogspot.com. Retrieved2014-04-30.
  4. ^"wait man page - System Calls".www.mankier.com.
  5. ^"init comes first".
  6. ^"An overview of Linux processes". IBM. 26 March 2012.
  7. ^"Linux Programmer's Manual".
Retrieved from "https://en.wikipedia.org/w/index.php?title=Parent_process&oldid=1313590006"
Category:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp