[R] reading PID

B.Rowlingson@lancaster.ac.uk B.Rowlingson at lancaster.ac.uk
Wed May 23 19:36:30 CEST 2001

Prof Brian D Ripley wrote:

> Let me point out that all of the below is at least as complicated as the
> above.
Okay, but:

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

 isn't. Relies on bash though.

> ???  R's tempfile can produce perfectly meaningful names.

> tempfile("job-output.")
[1] "/tmp/job-output.R10e1S79e2a9e3"

 not terrifically meaningful. The application I had in mind (and I dont
think we know what the original poster's application was!) was running
several R jobs in the background producing several output files. You 
could go to the effort of generating sequence numbers for each job and
encoding that in the tempfile() name, or you could get the PID and throw
that into tempfile(). Then if you decide from looking at the output
that one of the jobs need killing, you get the PID for free from the
name. Less chance of killing off that 10 million iteration MCMC that's
running all month...
> tempfile(paste("job.pid-",pid,"-.",sep=''))
[1] "/tmp/job.pid-4321-.R10e1S5bd062c2"

 Other uses for a process to get its pid include writing it to a
such as that written by the apache web server, so a user can get the pid
without recourse to ps, for the purpose of sending signals to the
Not sure if R lets you install a signal handler though!

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