public
Fork of mojombo/god
Description: Ruby process monitor
Homepage: http://god.rubyforge.org
Clone URL: git://github.com/kevinclark/god.git
Search Repo:
use Process.kill(0, ...) instead of shelling out
mojombo (author)
Tue Feb 12 00:42:55 -0800 2008
commit  886f281595c2d8dbeeae12b7ba700922b0dc8fbe
tree    b9c7fea707d0289f1cb9fb409cf761d09760b266
parent  b69311d226b8569c27f2e0ed641f59eb7b018d1a
...
40
41
42
 
43
44
45
 
46
47
48
 
49
50
51
...
40
41
42
43
44
45
 
46
47
48
 
49
50
51
52
0
@@ -40,12 +40,13 @@
0
     
0
     def self.deregister(pid, event=nil)
0
       if watching_pid? pid
0
+ running = ::Process.kill(0, pid.to_i) rescue false
0
         if event.nil?
0
           @@actions.delete(pid)
0
- @@handler.register_process(pid, []) if system("kill -0 #{pid} &> /dev/null")
0
+ @@handler.register_process(pid, []) if running
0
         else
0
           @@actions[pid].delete(event)
0
- @@handler.register_process(pid, @@actions[pid].keys) if system("kill -0 #{pid} &> /dev/null")
0
+ @@handler.register_process(pid, @@actions[pid].keys) if running
0
         end
0
       end
0
     end
...
8
9
10
11
 
12
13
14
...
8
9
10
 
11
12
13
14
0
@@ -8,7 +8,7 @@
0
       
0
       # Return true if this process is running, false otherwise
0
       def exists?
0
- system("kill -0 #{@pid} &> /dev/null")
0
+ !!::Process.kill(0, @pid) rescue false
0
       end
0
       
0
       # Memory usage in kilobytes (resident set size)
...
115
116
117
118
 
119
120
121
...
115
116
117
 
118
119
120
121
0
@@ -115,7 +115,7 @@
0
   # alive?
0
   
0
   def test_alive_should_call_system_process_exists
0
- File.expects(:read).with('blah.pid').).returns('1234')
0
+ File.expects(:read).with('blah.pid').times(2).returns('1234')
0
     System::Process.any_instance.expects(:exists?).returns(false)
0
     assert !@p.alive?
0
   end

Comments

    No one has commented yet.