Module: ProcessTail
- Defined in:
- lib/process_tail.rb,
lib/process_tail/version.rb,
ext/process_tail/process_tail.c
Defined Under Namespace
Modules: ReadIOExtension
Classes: StopTracing, TraceError, Tracer
Constant Summary
collapse
- VERSION =
'0.0.5'
Class Method Summary
collapse
Class Method Details
.each(pid) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/process_tail.rb', line 57
def each(pid)
tracer = trace(pid, :all) {|tid, fd, str|
yield tid, fd, str
}
tracer.wait
rescue StopTracing
ensure
tracer.detach
end
|
.open(pid, fd = :stdout) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/process_tail.rb', line 69
def open(pid, fd = :stdout)
read_io, write_io = IO.pipe
tracer = trace(pid, fd) {|tid, fd_num, str|
unless read_io.closed?
write_io.write str
else
write_io.close
process_tail.detach
end
}
read_io.extend ReadIOExtension
read_io.process_tail_after_close = -> {
write_io.close unless write_io.closed?
tracer.detach
}
block_given? ? yield(read_io) : read_io
rescue StopTracing
ensure
if block_given?
[read_io, write_io].each do |io|
io.close unless io.closed?
end
end
end
|