How can I shut down Rserve gracefully?

前端 未结 3 639
青春惊慌失措
青春惊慌失措 2020-12-28 18:56

I have tried many options both in Mac and in Ubuntu. I read the Rserve documentation

http://rforge.net/Rserve/doc.html

and that for the Rse

相关标签:
3条回答
  • 2020-12-28 19:33

    On a Windows system, if you want to close an RServe instance, you can use the system function in R to close it down. For example in R:

    library(Rserve)
    Rserve() # run without any arguments or ports specified
    system('tasklist /FI "IMAGENAME eq Rserve.exe"') # run this to see RServe instances and their PIDs
    system('TASKKILL /PID {yourPID} /F') # run this to kill off the RServe instance with your selected PID
    

    If you have closed your RServe instance with that PID correctly, the following message will appear:

    SUCCESS: The process with PID xxxx has been terminated.

    You can check the RServe instance has been closed down by entering

    system('tasklist /FI "IMAGENAME eq Rserve.exe"')

    again. If there are no RServe instances running any more, you will get the message

    INFO: No tasks are running which match the specified criteria.

    More help and info on this topic can be seen in this related question.

    Note that the 'RSClient' approach mentioned in an earlier answer is tidier and easier than this one, but I put it forward anyway for those who start RServe without knowing how to stop it.

    0 讨论(0)
  • 2020-12-28 19:45

    Load Rserve and RSclient packages, then connect to the instances.

    > library(Rserve)
    > library(RSclient)
    
    > Rserve(port = 6311, debug = FALSE)
    > Rserve(port = 6312, debug = TRUE)
    
    Starting Rserve...
     "C:\..\Rserve.exe" --RS-port 6311
    Starting Rserve...
     "C:\..\Rserve_d.exe" --RS-port 6312 
    
    > rsc <- RSconnect(port = 6311)
    > rscd <- RSconnect(port = 6312)
    

    Looks like they're running...

    > system('tasklist /FI "IMAGENAME eq Rserve.exe"')
    > system('tasklist /FI "IMAGENAME eq Rserve_d.exe"')
    
    Image Name                     PID Session Name        Session#    Mem Usage
    ========================= ======== ================ =========== ============
    Rserve.exe                    8600 Console                    1     39,312 K
    Rserve_d.exe                 12652 Console                    1     39,324 K
    

    Let's shut 'em down.

    > RSshutdown(rsc)
    > RSshutdown(rscd)
    

    And they're gone...

    > system('tasklist /FI "IMAGENAME eq Rserve.exe"')
    > system('tasklist /FI "IMAGENAME eq Rserve_d.exe"')
    
    INFO: No tasks are running which match the specified criteria.
    

    Rserve can be used w/o RSclient by starting it with args and/or a config script. Then you can connect to it from some other program (like Tableau) or with your own code. RSclient provides a way to pass commands/data to Rserve from an instance of R.

    Hope this helps :)

    0 讨论(0)
  • 2020-12-28 19:46

    If you are not able to shut it down within R, run the codes below to kill it in terminal. These codes work on Mac.

    $ ps ax | grep Rserve  # get active Rserve sessions
    

    You will see outputs like below. 29155 is job id of the active Rserve session.

    29155  /Users/userid/Library/R/3.5/library/Rserve/libs/Rserve
    
    38562  0:00.00 grep Rserve
    

    Then run

    $ kill 29155 
    
    0 讨论(0)
提交回复
热议问题