Method: IO#pid
- Defined in:
- io.c
#pid ⇒ Integer?
Returns the process ID of a child process associated with the stream, which will have been set by IO#popen, or nil if the stream was not created by IO#popen:
pipe = IO.popen("-")
if pipe
$stderr.puts "In parent, child pid is #{pipe.pid}"
else
$stderr.puts "In child, pid is #{$$}"
end
Output:
In child, pid is 26209
In parent, child pid is 26209
2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 |
# File 'io.c', line 2947
static VALUE
rb_io_pid(VALUE io)
{
rb_io_t *fptr;
GetOpenFile(io, fptr);
if (!fptr->pid)
return Qnil;
return PIDT2NUM(fptr->pid);
}
|