I believe that the last part of the question is more about looking at the shell, rather than the kernel. (Simon Urbanek answered the multicore
part better than anyone else, as he is the author. :))
If you use bash, you can find the PID of the most recently launched child process in $!
. You can aggregate PIDs, and then be sure to disable them when you close R.
If you want to be truly gonzo, you can save the parent PID (that is, the output of Sys.getpid()
) and the child PID in a file and have a cleanup daemon that checks if the parent PID exists or not, and if not, it kills orphans. I don't think it will be easy to get a package called oRphanKilleR
on CRAN.
Here is an example of adding a child PID to a file:
system('(sleep 20) & echo $! >> ~/childPIDs.txt', wait = FALSE)
You can change this to create your own shell command and use the R tempfile()
command to create a temporary file (although this will disappear when the R instance is complete unless you take special effort to save the file through permissions).
For some other smart ideas, see this other post in SO .
You can also create a do while
in the shell that will check for the presence or absence of a specific PID. While he is sleeping. When the loop ends (since the PID is no longer in use), the script will kill another PID.
Basically, I think your solution will be in shell scripts, not R.
source share