I connected from my desktop Linux box to a Linux server using ssh in an xterm, but that xterm was running in Xvnc. I'm running R on the server in that xterm (over ssh). Something went wrong with Xvnc that has caused it to hang, probably this bug: https://bugs.launchpad.net/ubuntu/+source/vnc4/+bug/819473 So I can't get back to that ssh session or to R. I had done a bunch of work in R but the command history hasn't been written out. If I kill R, I assume the command history is gone. I wish I could somehow cause R to dump the command history. Is there any way to tell the running R process to write the history somewhere? Thanks in advance. Mike -- Michael B. Miller, Ph.D. Minnesota Center for Twin and Family Research Department of Psychology University of Minnesota
R process must die - can I save history?
6 messages · Bert Gunter, Brian Ripley, steven mosher +2 more
?history in a fresh R session, to see what might be possible. I'll bet the answer is, "No, you're screwed," though. Nevertheless, maybe Linux experts can save you. May the Force be with you. -- Bert
On Tue, Oct 2, 2012 at 10:17 AM, Mike Miller <mbmiller+l at gmail.com> wrote:
I connected from my desktop Linux box to a Linux server using ssh in an xterm, but that xterm was running in Xvnc. I'm running R on the server in that xterm (over ssh). Something went wrong with Xvnc that has caused it to hang, probably this bug: https://bugs.launchpad.net/ubuntu/+source/vnc4/+bug/819473 So I can't get back to that ssh session or to R. I had done a bunch of work in R but the command history hasn't been written out. If I kill R, I assume the command history is gone. I wish I could somehow cause R to dump the command history. Is there any way to tell the running R process to write the history somewhere? Thanks in advance. Mike -- Michael B. Miller, Ph.D. Minnesota Center for Twin and Family Research Department of Psychology University of Minnesota
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
On 02/10/2012 18:29, Bert Gunter wrote:
?history in a fresh R session, to see what might be possible. I'll bet the answer is, "No, you're screwed," though. Nevertheless, maybe Linux experts can save you.
Maybe not. On a Unix-alike see ?Signals. If you can find the pid of the R process and it is still running (and not e.g. suspended), kill -USR1 <pid> will save the workspace and history.
May the Force be with you. -- Bert On Tue, Oct 2, 2012 at 10:17 AM, Mike Miller <mbmiller+l at gmail.com> wrote:
I connected from my desktop Linux box to a Linux server using ssh in an xterm, but that xterm was running in Xvnc. I'm running R on the server in that xterm (over ssh). Something went wrong with Xvnc that has caused it to hang, probably this bug: https://bugs.launchpad.net/ubuntu/+source/vnc4/+bug/819473 So I can't get back to that ssh session or to R. I had done a bunch of work in R but the command history hasn't been written out. If I kill R, I assume the command history is gone. I wish I could somehow cause R to dump the command history. Is there any way to tell the running R process to write the history somewhere? Thanks in advance. Mike -- Michael B. Miller, Ph.D. Minnesota Center for Twin and Family Research Department of Psychology University of Minnesota
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121002/66a02671/attachment.pl>
Agreed -- very cool trick. Thanks Prof Ripley Michael
On Oct 2, 2012, at 9:59 PM, steven mosher <moshersteven at gmail.com> wrote:
thanks Dr. R. this will come in handy in the future as I have a knack for hanging R. On Oct 2, 2012 12:01 PM, "Prof Brian Ripley" <ripley at stats.ox.ac.uk> wrote:
On 02/10/2012 18:29, Bert Gunter wrote:
?history in a fresh R session, to see what might be possible. I'll bet the answer is, "No, you're screwed," though. Nevertheless, maybe Linux experts can save you.
Maybe not. On a Unix-alike see ?Signals. If you can find the pid of the R process and it is still running (and not e.g. suspended), kill -USR1 <pid> will save the workspace and history.
May the Force be with you. -- Bert On Tue, Oct 2, 2012 at 10:17 AM, Mike Miller <mbmiller+l at gmail.com> wrote:
I connected from my desktop Linux box to a Linux server using ssh in an xterm, but that xterm was running in Xvnc. I'm running R on the server in that xterm (over ssh). Something went wrong with Xvnc that has caused it to hang, probably this bug: https://bugs.launchpad.net/**ubuntu/+source/vnc4/+bug/**819473<https://bugs.launchpad.net/ubuntu/+source/vnc4/+bug/819473> So I can't get back to that ssh session or to R. I had done a bunch of work in R but the command history hasn't been written out. If I kill R, I assume the command history is gone. I wish I could somehow cause R to dump the command history. Is there any way to tell the running R process to write the history somewhere? Thanks in advance. Mike -- Michael B. Miller, Ph.D. Minnesota Center for Twin and Family Research Department of Psychology University of Minnesota
______________________________**________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html <http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~**ripley/<http://www.stats.ox.ac.uk/~ripley/> University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
______________________________**________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html <http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
This is a solution for UNIX/Linux-type OS users and a lot of it is only
related to R in the sense that it can allow you to reconnect to an R
session. I managed to do it and to save history, thanks to helpful
messages from Ista Zahn and Brian Ripley.
To explain this, I will call my two Linux boxes Desktop and Server. I
logged into Desktop, an Ubuntu box, and ran this command:
ps aux | grep ssh
That showed me these ssh processes and a few extraneous things:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
mbmiller 3520 0.0 0.0 46944 4668 pts/5 S+ Jul25 0:23 ssh -X Server
mbmiller 4602 0.0 0.0 47720 5544 pts/9 S+ Aug09 1:07 ssh -X Server
mbmiller 25614 0.0 0.0 45584 3344 pts/11 S+ Sep24 0:00 ssh -X Server
I launched an xterm from which I would try to recapture those ssh
sessions. (Spoiler: This worked for every ssh process.) I was missing
the reptyr binary, so I installed it like so:
sudo apt-get install reptyr
The reptyr man page told me that I had to do this to allow reptyr to work
(I could change the 0 back to 1 after finishing):
$ sudo su
root# echo 0 > /proc/sys/kernel/yama/ptrace_scope
root# exit
After that I just ran reptyr for each process, for example:
reptyr 3520
A few lines of text would appear (the last saying "Set the controlling
tty"), I'd hit "enter" and it would give my my command prompt from my old
shell, or the R prompt if R was running in that shell. I was then able to
save command histories, etc. When I tried to exit from R using q("yes")
it accepted the command, but it did not return my bash prompt. To deal
with that, I tried Brian Ripley's recommendation:
I logged into Server via ssh and ran this command:
ps aux | grep R
Which returned this along with some irrelevant stuff:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
mbmiller 5156 0.0 0.1 213188 9244 pts/1 S+ Aug06 1:00 /share/apps/R-2.15.1/lib64/R/bin/exec/R -q
I tried the kill command...
kill -USR1 5156
...and that returned my bash prompt immediately in the other xterm. R was
done, the .Rhistory looked perfect, and .RData also was there. I logged
into Server, went to the appropriate directory, ran R and found that all
of the objects were there and working correctly.
So that was amazing. I could reattach to the R session and also kill it
without losing history and data. This is a big deal for me because I get
stuck like that about once a year and it's always a huge pain.
Mike
On Tue, 2 Oct 2012, Ista Zahn wrote (off-list):
If you can find the process ID you can try connecting the process to another terminal with reptyr (https://github.com/nelhage/reptyr), and then just use savehistory() as usual. You don't say what flavor of Linux you're dealing with, but it looks like there are packaged versions for at least Ubuntu, Fedora, and Arch.
On Tue, 2 Oct 2012, Prof Brian Ripley wrote:
Maybe not. On a Unix-alike see ?Signals. If you can find the pid of the R process and it is still running (and not e.g. suspended), kill -USR1 <pid> will save the workspace and history.
Original query:
On Tue, 2 Oct 2012, Mike Miller wrote:
I connected from my desktop Linux box to a Linux server using ssh in an xterm, but that xterm was running in Xvnc. I'm running R on the server in that xterm (over ssh). Something went wrong with Xvnc that has caused it to hang, probably this bug: https://bugs.launchpad.net/ubuntu/+source/vnc4/+bug/819473 So I can't get back to that ssh session or to R. I had done a bunch of work in R but the command history hasn't been written out. If I kill R, I assume the command history is gone. I wish I could somehow cause R to dump the command history. Is there any way to tell the running R process to write the history somewhere?