[R] reading PID

B.Rowlingson@lancaster.ac.uk B.Rowlingson at lancaster.ac.uk
Wed May 23 15:44:52 CEST 2001


Prof Brian Ripley wrote:

> That's an OS-specific question, isn't it?  Let me guess, Linux.  There is
> no specific way to get the pid within an R process (what could you do
> with it?), but you can trivially dyn.load some code to tell you via a call
> to getpid.

 On most modern Linux machines you could read in /proc/self/status and
get the
'Pid:' entry. Lots of other useful stuff in there too. I haven't quite
figured
out how to read in the various bits neatly because of all the tab
characters
floating around. 

 And a warning - /proc/ stuff is really meant for human eyes and not for
machines
to parse and obtain info from. That's what system calls are for. The
/proc format
is liable to change. 

 Or you can get it by using system() to run a command and then the $PPID
env
var to get the parent pid:

pid <- system("echo $PPID",intern=T)

> Of course adding a Sys.getpid() function would be easy, but what use would
> it be? 

 Several running R processes could write their output to unique files
labelled
by pid perhaps? Would be more meaningful names than the output of
tempfile()...

Barry

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list