Search code examples
google-cloud-platformjupyter-notebooknohup

Connected Jupyter to GCP instance via nohup. How do I exit?


I am trying to connect Jupyter notebook to my GCP instance. After following some information on StackOverflow, I used-

nohup jupyter notebpook --ip=0.0.0.0 &

to run jupyter notebook in the background. And then tunneled by doing an SSH into GCP-

ssh username@<public_ip> -L 8888:127.0.0.1:8888

So, I can access Jupyter notebooks at 127.0.0.1:8888

Since most of these instructions were blindly followed off of a post, I'm a little lost on how nohup actually works. I have the following questions -

  1. How do I close this connection? Will Jupyter stop running on my GCP instance when I quit my SSH connection? (I'm worried about wracking up a huge bill because of this).
  2. How do I even verify that Jupyter is running on my GCP instance? My code seems to be executing faster but is there a way I can confirm?

Sorry for the extremely introductory questions. I appreciate all your help!


Solution

  • Running the process under nohup will keep it running even if you disconnect the ssh session. To kill it find it in the process list and kill:

    killall jupyter
    

    You can tell that you're running on the remote instance by looking at the environment from within a cell in a notebook. Just enter:

    import os
    print(os.environ)
    

    You will be charged for the GCE instance as long as it's running. It doesn't matter whether jupyter is running or not. To stop the instance go into the GCP console, select the instance, and click Stop.