Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Parent process
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Computing software instance that has created one or more child processes}} {{Multiple issues| {{More citations needed|date=April 2024}} {{Lead too short|date=January 2025}} }} In computing, a '''parent process''' is a process that has created one or more [[child process]]es. == Unix-like systems == In [[Unix-like]] [[operating system]]s, every process except {{nowrap|[[Linux startup process|process 0]]}} (the swapper) is created when another process executes the [[fork (operating system)|fork()]] [[system call]]. The process that invoked fork is the ''parent process'' and the newly created process is the ''child process''. Every process (except process 0) has one parent process, but can have many child processes. The [[operating system kernel]] identifies each process by its process identifier. {{nowrap|Process 0}} is a special process that is created when the system boots; after forking a child process {{nowrap|(process 1),}} {{nowrap|process 0}} becomes the [[Scheduling (computing)|swapper process]] (sometimes also known as the "[[idle task]]"). {{nowrap|Process 1}}, known as {{mono|[[init]]}}, is the ancestor of every other process in the system.<ref name="Tanenbaum">{{cite book |last1=Tanenbaum |first1=Andrew |title=Modern operating systems |date=2007 |publisher=Pearson Prentice Hall |isbn=978-0136006633 |pages=752 |edition=3rd}}</ref> === Linux === In the [[Linux kernel]], in which there is a very slim difference between processes and [[POSIX threads]], there are two kinds of parent processes, namely real parent and parent. Parent is the process that receives the ''SIGCHLD'' 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.<ref>{{cite web|last=Srinivasan |first=Sundar |url=http://sunnyeves.blogspot.com/2010/09/sneak-peek-into-linux-kernel-chapter-2.html |title=An Engineer's Options & Futures: A Sneak-Peek into Linux Kernel - Chapter 2: Process Creation |publisher=Sunnyeves.blogspot.com |date=2010-09-01 |accessdate=2014-04-30}}</ref> == Zombie processes == {{main|Zombie process}} The operating system maintains a table that associates every process, by means of its [[process 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 variable]]s, 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 calling [[exit (system call)|''exit'']] (even if implicitly, by executing a '''return''' command from the ''main'' function) or by receiving a [[signal (computing)|signal]] 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 the [[exit status|termination 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 signal ''[[SIGCHLD]]'' to alert that there is some data about a child to be collected. Such collection is done by calling a function of the [[wait (operating system)|''wait'']] family (either ''wait'' itself or one of its relatives, such as ''waitpid'', ''waitid'' or ''wait4''). 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 a ''zombie process'', or simply a ''zombie'', 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 calls ''wait'' 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 a [[Signal (computing)#Handling signals|handler]] for the ''SIGCHLD'' signal, calling one of the ''wait''-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 for ''SIGCHLD'' through a call to ''sigaction'' with the special option flag ''SA_NOCLDWAIT''.<ref>{{cite web |title=wait man page - System Calls |url=https://www.mankier.com/2/wait#Notes |website=www.mankier.com |language=en}}</ref> == Orphan processes == {{Main|Orphan process}} [[Orphan process]]es 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 the {{Mono|SIGCHLD}} 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.<ref>{{cite web |title=init comes first |url=https://www.tldp.org/LDP/sag/html/init-process.html}}</ref><ref>{{cite web |title=An overview of Linux processes |url=https://www.ibm.com/developerworks/community/blogs/58e72888-6340-46ac-b488-d31aa4058e9c/entry/an_overview_of_linux_processes21?lang=en |publisher=IBM |date=26 March 2012}}</ref> 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{{snd}} unless, of course, that "grandparent" was the init itself. After Linux kernel 3.4 this is no longer true, in fact processes can issue the [http://man7.org/linux/man-pages/man2/prctl.2.html prctl()] 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: <blockquote> 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.<ref>{{cite web |title=Linux Programmer's Manual |url=http://man7.org/linux/man-pages/man2/prctl.2.html}}</ref> </blockquote> == References == {{Reflist}} [[Category:Process (computing)]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Cite book
(
edit
)
Template:Cite web
(
edit
)
Template:Main
(
edit
)
Template:Mono
(
edit
)
Template:Multiple issues
(
edit
)
Template:Nowrap
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Snd
(
edit
)