nvidia – command aliasing in ~/.bashrc doesn’t work after sourcing or rebooting

I want to add an alias to my ~/.bashrc such that when I use killp it kills the python process(es) that use GPU.

I am not sure why neither of these commands work. I have sourced my bashrc using source ~/.bashrc command. How can I fix it?

alias killp="lsof /dev/nvidia* | grep python333  | awk '{print $2}' | tail -1 | xargs kill -9"

or

alias killp="ps -aux | grep python | awk '{print $2}' | xargs kill -9"

Here’s an example of nvidia-smi output that shows a Python code using GPU:

$ nvidia-smi
Tue Jan 26 23:34:00 2021       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.32.03    Driver Version: 460.32.03    CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  GeForce GTX 165...  Off  | 00000000:01:00.0 Off |                  N/A |
| N/A   48C    P0    12W /  N/A |   1777MiB /  3911MiB |      8%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1114      G   /usr/lib/xorg/Xorg                133MiB |
|    0   N/A  N/A      1730      G   /usr/lib/xorg/Xorg                759MiB |
|    0   N/A  N/A      1920      G   /usr/bin/gnome-shell              122MiB |
|    0   N/A  N/A      2289      G   ...gAAAAAAAAA --shared-files      162MiB |
|    0   N/A  N/A      2621      G   /usr/lib/firefox/firefox            1MiB |
|    0   N/A  N/A      2683      G   /usr/lib/firefox/firefox            1MiB |
|    0   N/A  N/A      2887      G   /usr/lib/firefox/firefox            1MiB |
|    0   N/A  N/A      3136      G   /opt/zoom/zoom                     17MiB |
|    0   N/A  N/A      3854      G   ...f_3536.log --shared-files        2MiB |
|    0   N/A  N/A      4423      G   /usr/lib/firefox/firefox            1MiB |
|    0   N/A  N/A      6335      G   /usr/lib/firefox/firefox            1MiB |
|    0   N/A  N/A      6899      G   /usr/lib/firefox/firefox            1MiB |
|    0   N/A  N/A     19939      C   python3                           549MiB |
+-----------------------------------------------------------------------------+