Class: ProcessWatch
- Inherits:
-
Object
- Object
- ProcessWatch
- Defined in:
- lib/process_watch.rb
Instance Attribute Summary collapse
-
#callback ⇒ Object
Returns the value of attribute callback.
-
#callback_message ⇒ Object
Returns the value of attribute callback_message.
-
#command ⇒ Object
Returns the value of attribute command.
-
#delay ⇒ Object
Returns the value of attribute delay.
-
#num_cycles ⇒ Object
Returns the value of attribute num_cycles.
-
#watch_string ⇒ Object
Returns the value of attribute watch_string.
Class Method Summary collapse
-
.find(watch_string, ps_args = "") ⇒ Object
-xf => my proccesses => $1 is parent pid of watch_string match -x => my processes => $1 is pid of of watch_string match.
Instance Method Summary collapse
- #cycle ⇒ Object
-
#initialize(options) ⇒ ProcessWatch
constructor
# # example : run test_daemon - test_daemon runs forever # # don’t forget to kill the test_daemon pid when you are done playing.
Constructor Details
#initialize(options) ⇒ ProcessWatch
# # example : run test_daemon - test_daemon runs forever # # don’t forget to kill the test_daemon pid when you are done playing. # $ hamster –watch ‘test_daemon ID=1’ –command “test_daemon ID=1”
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/process_watch.rb', line 16 def initialize() self.command = [:command] || nil self.callback = [:callback] || lambda { p 'default callback does nothing'} self. = ([:callback_message] || "Callback Triggered").strip self.watch_string = ([:watch] || "this poem is a pomme").strip self.delay = [:delay] || 60 self.num_cycles = [:num_cycles] || 3 end |
Instance Attribute Details
#callback ⇒ Object
Returns the value of attribute callback.
2 3 4 |
# File 'lib/process_watch.rb', line 2 def callback @callback end |
#callback_message ⇒ Object
Returns the value of attribute callback_message.
2 3 4 |
# File 'lib/process_watch.rb', line 2 def @callback_message end |
#command ⇒ Object
Returns the value of attribute command.
2 3 4 |
# File 'lib/process_watch.rb', line 2 def command @command end |
#delay ⇒ Object
Returns the value of attribute delay.
2 3 4 |
# File 'lib/process_watch.rb', line 2 def delay @delay end |
#num_cycles ⇒ Object
Returns the value of attribute num_cycles.
2 3 4 |
# File 'lib/process_watch.rb', line 2 def num_cycles @num_cycles end |
#watch_string ⇒ Object
Returns the value of attribute watch_string.
2 3 4 |
# File 'lib/process_watch.rb', line 2 def watch_string @watch_string end |
Class Method Details
.find(watch_string, ps_args = "") ⇒ Object
-xf => my proccesses => $1 is parent pid of watch_string match -x => my processes => $1 is pid of of watch_string match
33 34 35 36 |
# File 'lib/process_watch.rb', line 33 def find(watch_string,ps_args = "") cmd = %%ps -x#{ps_args} |grep '#{watch_string}' |grep -v grep | grep -v 'watch #{watch_string}' | awk '{print $1}'% pids = %x{#{cmd}}.split() end |
Instance Method Details
#cycle ⇒ Object
40 41 42 43 44 45 |
# File 'lib/process_watch.rb', line 40 def cycle self.num_cycles.times do _check sleep self.delay end end |