Mahsa
Mahsa

Reputation: 561

how to pause R and resume it later?

I have a very big dataset with more than 100 millions of rows. I am running a loop on that dataset. The code has been running since two days ago and I forgot to add a counter to see how much time is left. I am working at a place that the desks are first come first serve so you cannot have a specific desk and at the end of each day, you have to logout the system. My problem is if I logout the system, I will loose the two days of work. Is there any way that I can pause R, logout my system, come back tomorrow morning and resume my work? I am working with UNIX. I appreciate if someone can help me with this.

Regards, Mahsa

Upvotes: 6

Views: 4668

Answers (2)

kith
kith

Reputation: 5566

If you're on a unix system, you'll most likely have access to a program called "screen".

If it's available, you can open up a terminal, start screen, start R, then close the terminal while R is still running in the background.

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

the steps:

  1. in your terminal, start screen

    screen
    
  2. start R, and run your program

  3. Close your terminal, just click the x, don't ctrl-d.

...hours later

  1. open a new terminal, type

    screen -ls
    

    to get a list of currently running screen sessions

  2. reconnect to the session of your choosing

    screen -r 34234
    

Upvotes: 9

consva
consva

Reputation: 1

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

  1. For illustration i have created a file with sleep command with sleep time of 500 seconds

    [prompt ~]$ cat test.sh

    sleep 500

  2. Once the test script is in execution mode, please Ctrl+Z to send the process to background. and then enter 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

Upvotes: 0

Related Questions