LSOF

In [1]:
lsof | tail -3
kworker/0 31880 root  rtd   unknown                      /proc/31880/root (readlink: Permission denied)
kworker/0 31880 root  txt   unknown                      /proc/31880/exe (readlink: Permission denied)
kworker/0 31880 root NOFD                                /proc/31880/fd (opendir: Permission denied)
In [2]:
# for a user
lsof -u milad | tail
thunar    32445 milad    6u  netlink                           0t0     158717 KOBJECT_UEVENT
thunar    32445 milad    7u     unix 0x0000000000000000        0t0     158718 type=STREAM
thunar    32445 milad    8u  a_inode               0,11          0       7041 [eventfd]
thunar    32445 milad    9u  a_inode               0,11          0       7041 [eventfd]
thunar    32445 milad   10r      REG              252,3     131688   27534374 /home/milad/.local/share/gvfs-metadata/home
thunar    32445 milad   11r      REG              252,3      32768   27535220 /home/milad/.local/share/gvfs-metadata/home-f272ac5c.log
thunar    32445 milad   12r      REG              252,3       8628   27525517 /home/milad/.local/share/gvfs-metadata/root
thunar    32445 milad   13r      REG              252,3      32768   27525721 /home/milad/.local/share/gvfs-metadata/root-54549598.log
thunar    32445 milad   14r  a_inode               0,11          0       7041 inotify
thunar    32445 milad   15u     unix 0x0000000000000000        0t0     163277 type=STREAM
In [5]:
# within a directory
lsof +D ~/Documents
COMMAND    PID  USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME
bash      2343 milad  cwd    DIR  252,3     4096 442384 /home/milad/Documents/University/Linux/Notes
xdg-open  4739 milad  cwd    DIR  252,3     4096 442384 /home/milad/Documents/University/Linux/Notes
firefox   4819 milad  cwd    DIR  252,3     4096 442384 /home/milad/Documents/University/Linux/Notes
jupyter-n 6050 milad  cwd    DIR  252,3     4096 442384 /home/milad/Documents/University/Linux/Notes
python3   7783 milad  cwd    DIR  252,3     4096 442384 /home/milad/Documents/University/Linux/Notes
bash      7792 milad  cwd    DIR  252,3     4096 442384 /home/milad/Documents/University/Linux/Notes
lsof      7990 milad  cwd    DIR  252,3     4096 442384 /home/milad/Documents/University/Linux/Notes
lsof      7991 milad  cwd    DIR  252,3     4096 442384 /home/milad/Documents/University/Linux/Notes

In [6]:
pgrep jupyter -a
6050 /usr/bin/python3 /home/milad/.local/bin/jupyter-notebook
In [7]:
ps -f 6050
UID        PID  PPID  C STIME TTY      STAT   TIME CMD
milad     6050  2343  0 19:54 pts/0    Sl+    0:02 /usr/bin/python3 /home/milad/
In [9]:
# process
lsof -p 6050 | tail
jupyter-n 6050 milad   21u  a_inode               0,11        0     7041 [eventpoll]
jupyter-n 6050 milad   22u     unix 0x0000000000000000      0t0   266223 type=STREAM
jupyter-n 6050 milad   23u     unix 0x0000000000000000      0t0   266224 type=STREAM
jupyter-n 6050 milad   24u  a_inode               0,11        0     7041 [eventpoll]
jupyter-n 6050 milad   25u     unix 0x0000000000000000      0t0   276566 type=STREAM
jupyter-n 6050 milad   26u     unix 0x0000000000000000      0t0   276567 type=STREAM
jupyter-n 6050 milad   27u     IPv4             272226      0t0      TCP localhost:42944->localhost:35919 (ESTABLISHED)
jupyter-n 6050 milad   28u     unix 0x0000000000000000      0t0   276568 type=STREAM
jupyter-n 6050 milad   29u     unix 0x0000000000000000      0t0   276569 type=STREAM
jupyter-n 6050 milad   30u     IPv4             272227      0t0      TCP localhost:54734->localhost:36981 (ESTABLISHED)
In [11]:
# only shows process ids so we can pass it to something like kill
lsof -u milad -t | tail -4
15367
15370
21957
32445
In [2]:
lsof -u^root -c clem | tail -5 # reverse user
clementin 3736 milad    2w      CHR                1,3      0t0        6 /dev/null
clementin 3736 milad    3u  a_inode               0,11        0     7041 [eventfd]
clementin 3736 milad    4r     FIFO               0,10      0t0    32416 pipe
clementin 3736 milad    5w     FIFO               0,10      0t0    32416 pipe
clementin 3736 milad    6u     unix 0x0000000000000000      0t0    32417 type=STREAM
In [13]:
lsof / | tail -5
thunar    32445 milad  mem    REG  252,1     3608  932764 /var/cache/fontconfig/8f35bb09461d20ae1ed6ebc3cc6cf97e-le64.cache-6
thunar    32445 milad  mem    REG  252,1   111644  795938 /usr/share/icons/gnome/icon-theme.cache
thunar    32445 milad  mem    REG  252,1   536520 1179314 /lib/x86_64-linux-gnu/libsystemd.so.0.14.0
thunar    32445 milad  mem    REG  252,1   126840 1178493 /lib/x86_64-linux-gnu/libudev.so.1.6.4
thunar    32445 milad  mem    REG  252,1    25012  791265 /usr/share/icons/hicolor/icon-theme.cache
In [19]:
lsof -a -u milad -c clem | tail -2 # a makes an and
clementin 3736 milad    5w     FIFO               0,10      0t0    32416 pipe
clementin 3736 milad    6u     unix 0x0000000000000000      0t0    32417 type=STREAM
In [6]:
python2 -m SimpleHttpServer

In [7]:
lsof -i TCP:8000
COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
python  8851 milad    3u  IPv4 299940      0t0  TCP *:8000 (LISTEN)

Lecture notes

License

Creative Commons License

Linux Notes by Milad As (Ravexina) is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.


ravexina's gitlab

ravexina's github