Class: ProcessHelper
- Inherits:
-
Object
- Object
- ProcessHelper
- Defined in:
- lib/common/socket/rlib/process_helper.rb
Overview
require ‘log4s’
This class suply local process related mehtods
- Author
-
chenjie
- Date
-
2009-4-30
Class Method Summary collapse
-
.get_thread_num(module_name) ⇒ Object
获取模块进程的线程数 - module_name return thead number or 0(process not running).
-
.is_process_running?(module_name) ⇒ Boolean
判断进程是否正在运行 return true/false.
-
.kill_process(module_name) ⇒ Object
execute killall to kill a process, if the process is supervised, then it will restart return: void.
-
.start_process(module_name, super_path = "/home/space/space/", child_path = "./bin/") ⇒ Object
用supervise启动单个模块进程 - module_name module name, e.g.: appui - super_path default “/home/space/space” - sample Env.start_process(“/home/space/space”, “loadspace.sh”) return true/false.
Class Method Details
.get_thread_num(module_name) ⇒ Object
获取模块进程的线程数
-
module_name
return thead number or 0(process not running)
58 59 60 61 62 63 64 65 66 |
# File 'lib/common/socket/rlib/process_helper.rb', line 58 def ProcessHelper.get_thread_num(module_name) str = `pstree | grep #{module_name}` mdata = str.scan /.*---(\d+).*/ if mdata.size > 0 then return mdata[0][0].to_i else return 0 end end |
.is_process_running?(module_name) ⇒ Boolean
判断进程是否正在运行return true/false
46 47 48 49 50 51 52 53 |
# File 'lib/common/socket/rlib/process_helper.rb', line 46 def ProcessHelper.is_process_running?(module_name) res = `pstree | grep #{module_name} | wc -l` if res.to_i > 0 then return true else return false end end |
.kill_process(module_name) ⇒ Object
execute killall to kill a process, if the process is supervised, then it will restart return: void
36 37 38 39 40 41 |
# File 'lib/common/socket/rlib/process_helper.rb', line 36 def ProcessHelper.kill_process(module_name) cmd_str = "killall -9 #{module_name}" # $log.debug "kill process cmd = #{cmd_str}" `#{cmd_str}` sleep 1 end |
.start_process(module_name, super_path = "/home/space/space/", child_path = "./bin/") ⇒ Object
用supervise启动单个模块进程
-
module_name module name, e.g.: appui
-
super_path default “/home/space/space”
-
sample Env.start_process(“/home/space/space”, “loadspace.sh”)
return true/false
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/common/socket/rlib/process_helper.rb', line 18 def ProcessHelper.start_process(module_name,super_path="/home/space/space/", child_path="./bin/") cmd_str = "cd #{super_path}; nohup #{child_path}#{module_name} >/dev/null 2>&1 &" # $log.debug "start process: "+cmd_str system "#{cmd_str}" sleep 2 if ProcessHelper.is_process_running?(module_name) then # $log.debug "process #{module_name} is running" return true else # $log.debug "process #{module_name} is not running" return false end end |