Module: ProcessTail
- Defined in:
- lib/process_tail.rb,
lib/process_tail/version.rb,
ext/process_tail/process_tail.c
Constant Summary collapse
- TRACE_LOCK =
NOTE For now, ProcessTail can’t trace multiple processes at the same time
Mutex.new
- VERSION =
'0.0.2'
Class Method Summary collapse
- .attach(pidv) ⇒ Object
- .detach(pidv) ⇒ Object
- .do_trace(fdp, write_io, read_io, wait_queue) ⇒ Object
- .open(pid, fd = :stdout) ⇒ Object
- .trace(pid, fd = :stdout) ⇒ Object
Class Method Details
.attach(pidv) ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'ext/process_tail/process_tail.c', line 216
static VALUE
pt_attach(VALUE klass, VALUE pidv)
{
int pid = (pid_t)FIX2INT(pidv);
Check_Type(pidv, T_FIXNUM);
if (ptrace(PTRACE_ATTACH, pid, NULL, NULL) < 0) {
rb_sys_fail("PTRACE_ATTACH");
return Qnil;
}
return Qtrue;
}
|
.detach(pidv) ⇒ Object
232 233 234 235 236 237 238 239 240 |
# File 'ext/process_tail/process_tail.c', line 232
static VALUE
pt_detach(VALUE klass, VALUE pidv)
{
Check_Type(pidv, T_FIXNUM);
ptrace(PTRACE_DETACH, (pid_t)FIX2INT(pidv), NULL, NULL);
return Qnil;
}
|
.do_trace(fdp, write_io, read_io, wait_queue) ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'ext/process_tail/process_tail.c', line 242
static VALUE
pt_trace(VALUE klass, VALUE fdp, VALUE write_io, VALUE read_io, VALUE wait_queue)
{
pt_tracee_t *tracee_headp = NULL;
Check_Type(fdp, T_FIXNUM);
Check_Type(write_io, T_FILE);
Check_Type(read_io, T_FILE);
pt_loop((unsigned int)FIX2INT(fdp), write_io, read_io, wait_queue, tracee_headp);
return Qnil;
}
|
.open(pid, fd = :stdout) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/process_tail.rb', line 9 def open(pid, fd = :stdout) io = trace(pid, fd) block_given? ? yield(io) : io ensure io.close if block_given? && !io.closed? end |
.trace(pid, fd = :stdout) ⇒ Object
17 18 19 20 21 |
# File 'lib/process_tail.rb', line 17 def trace(pid, fd = :stdout) TRACE_LOCK.synchronize { trace_without_lock(pid, fd) } end |