Hello,
High level description:
I have a script that (deliberately) runs in an infinite loop, collecting and analyzing data. I am running the script in a batch mode using R CMD BATCH and let it run for days, sometimes for weeks. My question is how can I externally terminate the full execution process. Please note that my question is merely about stopping (killing) the process: my script works as expected in the background, and the output files provided to the batch run contains the expected output.
Some details:
I am running under a tcsh shell. Here is one way I tried running my script:
R CMD BATCH --no-save -- liveDataProcessing.R q.recorder.io.fifo
Here my script file name is liveDataProcessing.R
, and I stream the output to the q.recorder.io.fifo file (it's really a pipe file, or fifo, but I don't think it is relevant).
The only difference between the two is that at the second, I go one level deeper, to guarantee that the process running the script is a child of the shell process I'm running this command from, but I don't think I is really necessary, as I show below.
Here is how the process hierarchy looks like when running using command #1 above from tcsh shell process 07661:
-+= 00001 root /sbin/launchd
\-+- 05316 ylev /Users/ylev/Library/Application Support/iTerm2/iTermServer-3.5.0beta3 /Users/ylev/Library/Application Support/iTerm2/iterm2-daemon-1.socket
\-+= 07661 ylev tcsh
\-+= 25999 ylev sh /Library/Frameworks/R.framework/Resources/bin/Rcmd BATCH --no-save -- liveDataProcessing.R q.recorder.io.fifo
\--- 26002 ylev /Library/Frameworks/R.framework/Resources/bin/exec/R -f liveDataProcessing.R --restore --save --no-readline --no-save
My reading of the above pids:
-
25999
: A new shell process created under the shell I launched my script from, that is running the Rcmd command with the arguments I supplied -
26002
: an R process (session) that RCmd created to run my script. Apparently the output of that R session is captured by RCmd that is running in the parent process
What I would like to do is stopping the batched execution, meaning "killing" both 25999 and 26002 processes. Killing either of the two doesn't terminate the other.
On a final note: the above is somewhat a simplification of how the script is run in practice, that results in a deeper hierarchy and the subtree that I would like to kill starts one or two level above. At the very least, I'm launching the script in the background via:
R CMD BATCH --no-save -- liveDataProcessing.R q.recorder.io.fifo &
and sometimes the statement above is itself inside a shell script that I run in the background. It doesn't change the fact that the last two levels are the ones that are relevant for the script execution, but in practice I wish I would have a way to kill the whole hierarchy that starts in the script that spawns the R CMD BATCH
command all the way to the R session leaf process.
Any help / ideas will be highly appreciated.
Thanks!