Skip to content

Commit b393dcc

Browse files
authored
Minor doc update: "orphan" processes (#14271)
This patch makes two small changes to the documentation: First, "zombie" processes are in a terminated state and will appear in "ps" output in "Z" state. The problem described in our documentation seems to actually be about the "orphan" condition, in which a process continues running after its parent terminates. Most unix systems will reparent the process with PID 1 but this can vary, but there is no convention that the process should stop unless it has been wired using eg. "prctl" to detect a terminated parent. The distinction between zombie and orphan is important because it means the child is still active. Second, our suggestion that the child process should detect stdin closure is a good workaround but is not generally true for applications that aren't doing their work on stdio. I've tried to clean up the text around the example shell script to clarify that developers are free to use this technique to detect parent termination, but it's not the rule for polite unix applications. Hijacking stdin also comes with some drawbacks as is already mentioned. I'm not suggesting a different workaround at the moment—there is a linux-specific technique of using "prctl" which is demonstrated in https://groups.google.com/g/elixir-lang-core/c/yiepKrcEniU , however this isn't portable. See #7495 and #9171
1 parent a6368b7 commit b393dcc

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

lib/elixir/lib/port.ex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,22 +142,22 @@ defmodule Port do
142142
reimplementing core part of the Runtime System, such as the `:user` and
143143
`:shell` processes.
144144
145-
## Zombie operating system processes
145+
## Orphan operating system processes
146146
147147
A port can be closed via the `close/1` function or by sending a `{pid, :close}`
148148
message. However, if the VM crashes, a long-running program started by the port
149149
will have its stdin and stdout channels closed but **it won't be automatically
150150
terminated**.
151151
152-
While most Unix command line tools will exit once its communication channels
153-
are closed, not all command line applications will do so. You can easily check
152+
While some Unix command line tools will exit once its parent process
153+
terminates, not all command line applications will do so. You can easily check
154154
this by starting the port and then shutting down the VM and inspecting your
155155
operating system to see if the port process is still running.
156156
157-
While we encourage graceful termination by detecting if stdin/stdout has been
158-
closed, we do not always have control over how third-party software terminates.
159-
In those cases, you can wrap the application in a script that checks for stdin.
160-
Here is such script that has been verified to work on bash shells:
157+
We do not always have control over how third-party software terminates.
158+
If necessary, one workaround is to wrap the child application in a script that
159+
checks whether stdin has been closed. Here is such a script that has been
160+
verified to work on bash shells:
161161
162162
#!/usr/bin/env bash
163163

lib/elixir/lib/system.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ defmodule System do
997997
ports guarantee stdin/stdout devices will be closed but it does not
998998
automatically terminate the program. The documentation for the
999999
`Port` module describes this problem and possible solutions under
1000-
the "Zombie processes" section.
1000+
the "Orphan operating system processes" section.
10011001
10021002
> #### Windows argument splitting and untrusted arguments {: .warning}
10031003
>

lib/mix/lib/mix/tasks/cmd.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ defmodule Mix.Tasks.Cmd do
3939
4040
* `--cd` *(since v1.10.4)* - the directory to run the command in
4141
42-
## Zombie operating system processes
42+
## Orphan operating system processes
4343
4444
Beware that the Erlang VM does not terminate child processes
4545
when it shuts down. Therefore, if you use `mix cmd` to start
@@ -48,7 +48,7 @@ defmodule Mix.Tasks.Cmd do
4848
4949
A solution is to make sure the child processes listen to the
5050
standard input and terminate when standard input is closed.
51-
We discuss this topic at length in the "Zombie operating system processes"
51+
We discuss this topic at length in the "Orphan operating system processes"
5252
of the `Port` module documentation.
5353
"""
5454

0 commit comments

Comments
 (0)