Identify notebook being run by kernel

If I run a notebook on jupyterlab I can switch to the terminal and run ps to see the kernel running. I’ll get something like:

    196 ?        Ssl    0:00 /srv/paws/bin/python3 -m ipykernel_launcher -f /home/paws/.local/share/jupyter/runtime/kernel-b5238fdc-3b0b-4622-968d-daa97d7f15b4.json

Though what file is actually being run? In this case it is a file called python-loop.ipynb, though I don’t see that when I run ps nor do I see reference to it in /home/paws/.local/share/jupyter/runtime/kernel-b5238fdc-3b0b-4622-968d-daa97d7f15b4.json

Is there some way to see what files were used with running processes?

Thank you!

You can find out what file is opened in the .json file :slight_smile:

Hi @spookster thanks for the reply! I think I would need some help decoding the json file as I don’t see the expected “python-loop.ipynb” file mentioned in it.

@PAWS:~$ ps ax
    PID TTY      STAT   TIME COMMAND
      1 ?        Ssl    0:06 /srv/paws/bin/python3 /srv/paws/bin/jupyterhub-singleuser --LabApp.collaborative=true
     74 ?        Ssl    0:00 /srv/paws/bin/python3 -m ipykernel_launcher -f /home/paws/.local/share/jupyter/runtime/kernel-69906426-ccd4-47bd-9888-e20efa40758a.json
     91 pts/0    Ss     0:00 /bin/bash -l
     96 pts/0    R+     0:00 ps ax
@PAWS:~$ cat /home/paws/.local/share/jupyter/runtime/kernel-69906426-ccd4-47bd-9888-e20efa40758a.json
{
  "shell_port": 44609,
  "iopub_port": 47119,
  "stdin_port": 49983,
  "control_port": 42175,
  "hb_port": 43483,
  "ip": "127.0.0.1",
  "key": "427a81ca-d9d079e7dea72752aeed7939",
  "transport": "tcp",
  "signature_scheme": "hmac-sha256",
  "kernel_name": "python3",
  "jupyter_session": "beaf2b2a-ce4c-45cf-baf2-e2b13f03514f"
}@PAWS:~$ 

Thank you!

huh?

that’s weird, my jupyter_session entry is the path of the open file…

what version of jupyterlab are you running?

We’re on jupyterlab==3.4.8 (been having some slowness issues in going to 4. Though could try if you think the listing would be there on something newer)

What happens when you run this in the working notebook?

import os

print(os.getenv('JPY_SESSION_NAME'))

It prints dfe3cf8d-02e8-44e0-a8b7-39379f905a9e
Which matches in the file from ps:

}@PAWS:~$ cat /home/paws/.local/share/jupyter/runtime/kernel-d5aff487-36c7-4631-b776-79e3f0692f54.json | grep dfe3cf8d-02e8-44e0-a8b7-39379f905a9e
  "jupyter_session": "dfe3cf8d-02e8-44e0-a8b7-39379f905a9e"

I cannot try this on my side but here is what I’d do:
Run this on a terminal in home directory (update the id if necessary :slight_smile: ):

grep -rnwl . -e "dfe3cf8d-02e8-44e0-a8b7-39379f905a9e"

Maybe you will find another file which then also contains the path to the open notebook?


You can also find the paths to all open notebooks in your workspace file @ ~/.jupyter/lab/workspaces/
But in my case there is are no session strings which connect the PIDs with the paths of open notebooks.

Sure enough there it is in the file.

 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2cff9077-f7e7-40f7-afee-515694375ce7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dfe3cf8d-02e8-44e0-a8b7-39379f905a9e\n"
     ]
    }
   ],

I think that should work for me. Thank you for your help!

1 Like