Module: Tasks
- Defined in:
- lib/tasks.rb
Class Method Summary collapse
- .love_pact(master, slave, interval = 2) ⇒ Object
-
.spawn(cmd) ⇒ Object
Tasks.spawn spawns a new process.
Class Method Details
.love_pact(master, slave, interval = 2) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/tasks.rb', line 28 def love_pact(master, slave, interval = 2) loop { Process.kill 0, master sleep interval } rescue Errno::ESRCH Process.kill "KILL", slave end |
.spawn(cmd) ⇒ Object
Tasks.spawn spawns a new process.
This code is almost equivalent to the following code:
def spawn(*cmd)
fork { exec(*cmd) }
end
But Tasks.spawn doesn’t use exec() for avoiding making new process.
e.g. spawn(‘sleep 100 | echo’) generates the following two processes:
-
sh -c ‘sleep 100 | echo’
-
sleep 10
18 19 20 21 22 23 24 25 26 |
# File 'lib/tasks.rb', line 18 def spawn(cmd) a = IO.popen(cmd) fork do while b = a.gets puts b end end a.pid end |