Skip to content

Instantly share code, notes, and snippets.

@padeoe
Last active July 16, 2025 01:13

Revisions

  1. padeoe revised this gist Aug 20, 2024. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion enhanced-nvidia-smi.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    This script enhances the functionality of `nvidia-smi` and provides the following information:
    For typical use cases, I prefer using `nvitop` to view detailed information. This script offers a dependency-free implementation.

    The script enhances the functionality of `nvidia-smi` and provides the following info:

    - `Username`
    - `full process Command`
  2. padeoe revised this gist Jul 8, 2023. No changes.
  3. padeoe revised this gist Jul 6, 2023. No changes.
  4. padeoe renamed this gist Jul 6, 2023. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. padeoe revised this gist Jul 5, 2023. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion nvidia-smi-process-name.md
    Original file line number Diff line number Diff line change
    @@ -9,8 +9,10 @@ This is useful on multi-user servers and can be used to quickly identify which u


    ```bash
    nvidia-smi && (nvidia-smi |tr -s ' '|grep -Eo "| [0123456789]+ N/A N/A [0-9]{3,} .*"|awk -F' ' '{system("s=$(cat /proc/"$4"/cmdline| tr \"\\0\" \" \");u=$(ps -o uname= -p "$4");echo "$1"sep"$4"sep$u sep"$7"sep$s" ) }'|sed 's/sep/\t/g')```
    nvidia-smi && (nvidia-smi |tr -s ' '|grep -Eo "| [0123456789]+ N/A N/A [0-9]{3,} .*"|awk -F' ' '{system("s=$(cat /proc/"$4"/cmdline| tr \"\\0\" \" \");u=$(ps -o uname= -p "$4");echo "$1"sep"$4"sep$u sep"$7"sep$s" ) }'|sed 's/sep/\t/g')
    ```
    The output is like this

    ```
    +-----------------------------------------------------------------------------+
    | Processes: GPU Memory |
  6. padeoe revised this gist Jul 5, 2023. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions nvidia-smi-process-name.md
    Original file line number Diff line number Diff line change
    @@ -9,8 +9,7 @@ This is useful on multi-user servers and can be used to quickly identify which u


    ```bash
    nvidia-smi |tr -s ' '|grep -Eo "| [0123456789]+ N/A N/A [0-9]{3,} .*"|awk -F' ' '{system("s=$(cat /proc/"$4"/cmdline| tr \"\\0\" \" \");u=$(ps -o uname= -p "$4");echo "$1"sep"$4"sep$u sep"$7"sep$s" ) }'|sed 's/sep/\t/g'
    ```
    nvidia-smi && (nvidia-smi |tr -s ' '|grep -Eo "| [0123456789]+ N/A N/A [0-9]{3,} .*"|awk -F' ' '{system("s=$(cat /proc/"$4"/cmdline| tr \"\\0\" \" \");u=$(ps -o uname= -p "$4");echo "$1"sep"$4"sep$u sep"$7"sep$s" ) }'|sed 's/sep/\t/g')```
    The output is like this
    ```
    +-----------------------------------------------------------------------------+
    @@ -34,4 +33,6 @@ The output is like this
    1 30439 root 199MiB /usr/bin/python -u /sentsim/train.py
    2 3296 root 137MiB python playground2.py
    2 21266 root 4735MiB /opt/conda/bin/python -u /cail/model.py
    ```
    ```

    For convenience, you can alias the command.
  7. padeoe revised this gist Jul 5, 2023. 1 changed file with 19 additions and 14 deletions.
    33 changes: 19 additions & 14 deletions nvidia-smi-process-name.md
    Original file line number Diff line number Diff line change
    @@ -1,21 +1,18 @@
    This script is based one `nvidia-smi`, but it can show complete process names and commands.
    This script enhances the functionality of `nvidia-smi` and provides the following information:

    - `Username`
    - `full process Command`
    - `GPU ID`
    - `PID`

    This is useful on multi-user servers and can be used to quickly identify which user is using the GPU and running what kind of program.


    ```bash
    nvidia-smi |tr -s ' '|grep -Eo "| [0123] [0-9]{3,} .*"|awk -F' ' '{system("s=$(cat /proc/"$2"/cmdline| tr \"\\0\" \" \");u=$(ps -o uname= -p "$2");echo "$1"sep$u sep"$5"sep$s" ) }'|sed -e 's/sep/\t/g'
    nvidia-smi |tr -s ' '|grep -Eo "| [0123456789]+ N/A N/A [0-9]{3,} .*"|awk -F' ' '{system("s=$(cat /proc/"$4"/cmdline| tr \"\\0\" \" \");u=$(ps -o uname= -p "$4");echo "$1"sep"$4"sep$u sep"$7"sep$s" ) }'|sed 's/sep/\t/g'
    ```
    The output is like this
    ```
    0 root 5825MiB python playground2.py
    0 root 6319MiB /opt/conda/bin/python -u /cail/model.py
    1 root 137MiB python playground2.py
    1 root 273MiB /usr/bin/python -u /sentsim/cli_predict.py
    1 root 4735MiB /opt/conda/bin/python -u /cail/model.py
    1 root 199MiB /usr/bin/python -u /sentsim/train.py
    2 root 137MiB python playground2.py
    2 root 4735MiB /opt/conda/bin/python -u /cail/model.py
    ```

    As a compare, the output of `nvidia-smi` is
    ```
    +-----------------------------------------------------------------------------+
    | Processes: GPU Memory |
    | GPU PID Type Process name Usage |
    @@ -29,4 +26,12 @@ As a compare, the output of `nvidia-smi` is
    | 2 3296 C python 137MiB |
    | 2 21266 C /opt/conda/bin/python 4735MiB |
    +-----------------------------------------------------------------------------+
    0 3296 user1 5825MiB python playground2.py
    0 21266 user2 6319MiB /opt/conda/bin/python -u /cail/model.py
    1 3299 root 137MiB python playground2.py
    1 8063 root 273MiB /usr/bin/python -u /sentsim/cli_predict.py
    1 21266 root 4735MiB /opt/conda/bin/python -u /cail/model.py
    1 30439 root 199MiB /usr/bin/python -u /sentsim/train.py
    2 3296 root 137MiB python playground2.py
    2 21266 root 4735MiB /opt/conda/bin/python -u /cail/model.py
    ```
  8. padeoe revised this gist Jan 9, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nvidia-smi-process-name.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    This script is based one `nvidia-smi`, but it can show complete process names and commands.
    ```bash
    nvidia-smi |tr -s ' '|grep -Eo "| [0123] [0-9]{3,} .*"|awk -F' ' '{system("s=$(cat /proc/"$2"/cmdline| tr \"\\0\" \" \");u=$(ps -o uname= -p "$2");echo -e "$1"sep$u sep"$5"sep$s" ) }'|sed -e 's/sep/\t/g'
    nvidia-smi |tr -s ' '|grep -Eo "| [0123] [0-9]{3,} .*"|awk -F' ' '{system("s=$(cat /proc/"$2"/cmdline| tr \"\\0\" \" \");u=$(ps -o uname= -p "$2");echo "$1"sep$u sep"$5"sep$s" ) }'|sed -e 's/sep/\t/g'
    ```
    The output is like this
    ```
  9. padeoe revised this gist Dec 23, 2019. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions nvidia-smi-process-name.md
    Original file line number Diff line number Diff line change
    @@ -4,14 +4,14 @@ nvidia-smi |tr -s ' '|grep -Eo "| [0123] [0-9]{3,} .*"|awk -F' ' '{system("s=$(c
    ```
    The output is like this
    ```
    0 root 5825MiB python playground2.py
    0 root 6319MiB /opt/conda/bin/python -u /cail/model.py
    1 root 137MiB python playground2.py
    1 root 273MiB /usr/bin/python -u /sentsim/cli_predict.py
    1 root 4735MiB /opt/conda/bin/python -u /cail/model.py
    1 root 199MiB /usr/bin/python -u /sentsim/train.py
    2 root 137MiB python playground2.py
    2 root 4735MiB /opt/conda/bin/python -u /cail/model.py
    0 root 5825MiB python playground2.py
    0 root 6319MiB /opt/conda/bin/python -u /cail/model.py
    1 root 137MiB python playground2.py
    1 root 273MiB /usr/bin/python -u /sentsim/cli_predict.py
    1 root 4735MiB /opt/conda/bin/python -u /cail/model.py
    1 root 199MiB /usr/bin/python -u /sentsim/train.py
    2 root 137MiB python playground2.py
    2 root 4735MiB /opt/conda/bin/python -u /cail/model.py
    ```

    As a compare, the output of `nvidia-smi` is
  10. padeoe revised this gist Dec 23, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions nvidia-smi-process-name.md
    Original file line number Diff line number Diff line change
    @@ -4,8 +4,8 @@ nvidia-smi |tr -s ' '|grep -Eo "| [0123] [0-9]{3,} .*"|awk -F' ' '{system("s=$(c
    ```
    The output is like this
    ```
    0 root 5825MiB python playground2.py
    0 root 6319MiB /opt/conda/bin/python -u /cail/model.py
    0 root 5825MiB python playground2.py
    0 root 6319MiB /opt/conda/bin/python -u /cail/model.py
    1 root 137MiB python playground2.py
    1 root 273MiB /usr/bin/python -u /sentsim/cli_predict.py
    1 root 4735MiB /opt/conda/bin/python -u /cail/model.py
  11. padeoe revised this gist Dec 23, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions nvidia-smi-process-name.md
    Original file line number Diff line number Diff line change
    @@ -9,8 +9,8 @@ The output is like this
    1 root 137MiB python playground2.py
    1 root 273MiB /usr/bin/python -u /sentsim/cli_predict.py
    1 root 4735MiB /opt/conda/bin/python -u /cail/model.py
    1 root 199MiB /usr/bin/python -u /sentsim/train.py
    2 root 137MiB python playground2.py
    1 root 199MiB /usr/bin/python -u /sentsim/train.py
    2 root 137MiB python playground2.py
    2 root 4735MiB /opt/conda/bin/python -u /cail/model.py
    ```

  12. padeoe revised this gist Dec 23, 2019. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions nvidia-smi-process-name.md
    Original file line number Diff line number Diff line change
    @@ -4,14 +4,14 @@ nvidia-smi |tr -s ' '|grep -Eo "| [0123] [0-9]{3,} .*"|awk -F' ' '{system("s=$(c
    ```
    The output is like this
    ```
    0 5825MiB pythonplayground2.py
    0 6319MiB /opt/conda/bin/python-u/cail/model.py
    1 137MiB pythonplayground2.py
    1 273MiB /usr/bin/python-u/sentsim/cli_predict.py
    1 4735MiB /opt/conda/bin/python-u/cail/model.py
    1 199MiB /usr/bin/python-u/sentsim/train.py
    2 137MiB pythonplayground2.py
    2 4735MiB /opt/conda/bin/python-u/cail/model.py
    0 root 5825MiB python playground2.py
    0 root 6319MiB /opt/conda/bin/python -u /cail/model.py
    1 root 137MiB python playground2.py
    1 root 273MiB /usr/bin/python -u /sentsim/cli_predict.py
    1 root 4735MiB /opt/conda/bin/python -u /cail/model.py
    1 root 199MiB /usr/bin/python -u /sentsim/train.py
    2 root 137MiB python playground2.py
    2 root 4735MiB /opt/conda/bin/python -u /cail/model.py
    ```

    As a compare, the output of `nvidia-smi` is
  13. padeoe revised this gist Dec 23, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nvidia-smi-process-name.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    This script is based one `nvidia-smi`, but it can show complete process names and commands.
    ```bash
    nvidia-smi |tr -s ' '|grep -Eo "| [0-9]+ [0-9]{3,} .*"|awk -F' ' '{system("s=$(cat /proc/"$2"/cmdline);echo -e "$1"\t"$5"\t$s" ) }'|tr ' ' ' '
    nvidia-smi |tr -s ' '|grep -Eo "| [0123] [0-9]{3,} .*"|awk -F' ' '{system("s=$(cat /proc/"$2"/cmdline| tr \"\\0\" \" \");u=$(ps -o uname= -p "$2");echo -e "$1"sep$u sep"$5"sep$s" ) }'|sed -e 's/sep/\t/g'
    ```
    The output is like this
    ```
  14. padeoe created this gist Jul 9, 2019.
    32 changes: 32 additions & 0 deletions nvidia-smi-process-name.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    This script is based one `nvidia-smi`, but it can show complete process names and commands.
    ```bash
    nvidia-smi |tr -s ' '|grep -Eo "| [0-9]+ [0-9]{3,} .*"|awk -F' ' '{system("s=$(cat /proc/"$2"/cmdline);echo -e "$1"\t"$5"\t$s" ) }'|tr ' ' ' '
    ```
    The output is like this
    ```
    0 5825MiB pythonplayground2.py
    0 6319MiB /opt/conda/bin/python-u/cail/model.py
    1 137MiB pythonplayground2.py
    1 273MiB /usr/bin/python-u/sentsim/cli_predict.py
    1 4735MiB /opt/conda/bin/python-u/cail/model.py
    1 199MiB /usr/bin/python-u/sentsim/train.py
    2 137MiB pythonplayground2.py
    2 4735MiB /opt/conda/bin/python-u/cail/model.py
    ```

    As a compare, the output of `nvidia-smi` is
    ```
    +-----------------------------------------------------------------------------+
    | Processes: GPU Memory |
    | GPU PID Type Process name Usage |
    |=============================================================================|
    | 0 3296 C python 5825MiB |
    | 0 21266 C /opt/conda/bin/python 6319MiB |
    | 1 3296 C python 137MiB |
    | 1 8063 C /usr/bin/python 273MiB |
    | 1 21266 C /opt/conda/bin/python 4735MiB |
    | 1 30439 C /usr/bin/python 199MiB |
    | 2 3296 C python 137MiB |
    | 2 21266 C /opt/conda/bin/python 4735MiB |
    +-----------------------------------------------------------------------------+
    ```