Created
March 10, 2010 20:17
-
-
Save henryhamon/328317 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ---------- example.rb ---------- | |
#!/usr/bin/ruby | |
# Determine our parent pid | |
puts Process.pid | |
10.times do | |
puts "Before fork" | |
pid = fork do | |
sleep 5 | |
my_pid = Process.pid | |
puts "Child pid: #{my_pid}" | |
script = "/Users/eric/Desktop/daemon_demo/some_script.sh #{my_pid} &" | |
exec script if !fork.nil? | |
exit 99 | |
end | |
Process.detach(pid) | |
puts "Child pid: #{pid}" | |
puts "After fork" | |
sleep 1 | |
end | |
puts "END OF PARENT SCRIPT" | |
# ---------- some_script.sh ---------- | |
#!/bin/bash | |
echo "[$@] Starting child process" | |
sleep 10 | |
echo "[$@] Ending child process" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment