summaryrefslogtreecommitdiff
path: root/code/snippets/zombie_process.rb
diff options
context:
space:
mode:
Diffstat (limited to 'code/snippets/zombie_process.rb')
-rw-r--r--code/snippets/zombie_process.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/code/snippets/zombie_process.rb b/code/snippets/zombie_process.rb
new file mode 100644
index 0000000..bf2413e
--- /dev/null
+++ b/code/snippets/zombie_process.rb
@@ -0,0 +1,17 @@
+message = 'Good Morning'
+recipient = 'tree@mybackyard.com'
+
+pid = fork do
+ # In this contrived example the parent process forks a child to take
+ # care of sending data to the stats collector. Meanwhile the parent
+ # process has continued on with its work of sending the actual payload.
+
+ # The parent process doesn't want to be slowed down with this task, and
+ # it doesn't matter if this would fail for some reason.
+ StatsCollector.record message, recipient
+end
+
+# This line ensures that the process performing the stats collection
+# won't become a zombie.
+Process.detach(pid)
+