How to pause R and resume it later?

I have a very large dataset with over 100 million rows. I run a loop in this dataset. The code works two days ago, and I forgot to add a counter to find out how much time is left. I work in the place where the tables first arrive, so you cannot have a specific table, and at the end of each day you need to log out. My problem is that if I log out, I will lose two days of work. Is there a way I can pause R, log out, come back tomorrow morning and resume work? I work with UNIX. I appreciate if anyone can help me with this.

Regards, Mahsa

+5
source share
2 answers

If you are on a unix system, you will most likely get access to a program called a screen.

If available, you can open a terminal, launch a screen, start R, and then close the terminal while R is still running in the background.

Then at a later time or the next day, you simply open another terminal and use the screen to connect to a previously created session.

Steps:

  • in your terminal, launch screen

    screen 
  • run R and run your program

  • Close the terminal, just press x, not ctrl-d.

... a few hours later

  1. open a new terminal, enter

     screen -ls 

    to get a list of current screen sessions

  2. connect to your chosen session

     screen -r 34234 
+9
source

You can send the process to run in the background by following the procedure below:

  • For illustration, I created a file with the sleep command with a wait time of 500 seconds.

    [prompt ~]$ cat test.sh

    sleep 500

  • Once the test script is in runtime, Ctrl + Z send the process to the background. and then type bg 1 so that the process runs in the background.

-

 [prompt ~]$ sh test.sh [1]+ Stopped sh test.sh [prompt ~]$ [prompt ~]$ bg 1 [1]+ sh test.sh & [prompt ~]$ [prompt ~]$ ps -ef | grep -i test.sh user1 20683 17618 0 16:08 pts/17 00:00:00 sh test.sh user1 20925 17618 0 16:08 pts/17 00:00:00 grep -i test.sh 
0
source

Source: https://habr.com/ru/post/1210692/


All Articles