A short talk I gave about Working with Unix processes based on the ebook by Jesse Storimer at the "Amsterdam.rb Reboot" on June 19th of 2012 at the 80beans office.
it immediately forks a child process. The child processes the job then exits. When the child has exited successfully, the worker reserves another job and repeats the process.
at #{Time.now.to_i}" Process.wait(@child) else procline "Processing #{job.queue} since #{Time.now.to_i}" perform(job, &block) exit! unless @cant_fork end
at #{Time.now.to_i}" Process.wait(@child) else procline "Processing #{job.queue} since #{Time.now.to_i}" perform(job, &block) exit! unless @cant_fork end
at #{Time.now.to_i}" Process.wait(@child) else procline "Processing #{job.queue} since #{Time.now.to_i}" perform(job, &block) exit! unless @cant_fork end
at #{Time.now.to_i}" Process.wait(@child) else procline "Processing #{job.queue} since #{Time.now.to_i}" perform(job, &block) exit! unless @cant_fork end
# For keeping track of child process (worker) pids. wpids = [] # Create 5 workers. 5.times do |i| wpids << fork do loop do connection = socket.accept connection.puts 'Hello Readers!' connection.close end end end Process.waitall
# For keeping track of child process (worker) pids. wpids = [] # Create 5 workers. 5.times do |i| wpids << fork do loop do connection = socket.accept connection.puts 'Hello Readers!' connection.close end end end Process.waitall
= [] # Create 5 workers. 5.times do |i| wpids << fork do trap(:INT) { exit } loop do # ... end end end # Forward any relevant signals to the child processes. trap(:INT) do wpids.each { |wpid| Process.kill(:INT, wpid) } exit end Process.waitall
= [] # Create 5 workers. 5.times do |i| wpids << fork do trap(:INT) { exit } loop do # ... end end end # Forward any relevant signals to the child processes. trap(:INT) do wpids.each { |wpid| Process.kill(:INT, wpid) } exit end Process.waitall