20: def getpid
21: unless @resource[:pattern]
22: @resource.fail "Either stop/status commands or a pattern must be specified"
23: end
24: ps = Facter["ps"].value
25: unless ps and ps != ""
26: @resource.fail "You must upgrade Facter to a version that includes 'ps'"
27: end
28: regex = Regexp.new(@resource[:pattern])
29: self.debug "Executing '#{ps}'"
30: IO.popen(ps) { |table|
31: table.each { |line|
32: if regex.match(line)
33: ary = line.sub(/^\s+/, '').split(/\s+/)
34: return ary[1]
35: end
36: }
37: }
38:
39: return nil
40: end