background tasks in Ruby e linux

A volte negli script Ruby ho bisogno di controllare l’esecuzione di un comando eseguito in modalita’ asincrona, ho creato pertanto una classe apposita: class BackgroundJob def initialize(cmd) @pid = fork do # this code is run in the child process # you can do anything here, like changing current directory or reopening STDOUT exec cmd end end def stop! # kill it (other signals than TERM may be used, depending on the program you want # to kill....

November 5, 2012 · Andrea Manzini