public Method

IO.pid

ios.pid     fixnum

Returns the process ID of a child process associated with ios. This will be set 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

produces:

In child, pid is 26209
In parent, child pid is 26209

Source Code

/*
*  call-seq:
*     ios.pid    => fixnum
*  
*  Returns the process ID of a child process associated with
*  <em>ios</em>. This will be set by <code>IO::popen</code>.
*     
*     pipe = IO.popen("-")
*     if pipe
*       $stderr.puts "In parent, child pid is #{pipe.pid}"
*     else
*       $stderr.puts "In child, pid is #{$$}"
*     end
*     
*  <em>produces:</em>
*     
*     In child, pid is 26209
*     In parent, child pid is 26209
*/

static VALUE
rb_io_pid(io)
   VALUE io;
{
   OpenFile *fptr;

   GetOpenFile(io, fptr);
   if (!fptr->pid)
       return Qnil;
   return INT2FIX(fptr->pid);
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.