美文网首页
lsof & pwdx

lsof & pwdx

作者: 黄耀鸿 | 来源:发表于2020-09-14 22:44 被阅读0次

What is lsof?

lsof is a linux command listed current open files.

Open files in the system include disk files, named pipes, network sockets and devices opened by all processes.

$ lsof |head -10
COMMAND     PID   TID              USER   FD      TYPE             DEVICE   SIZE/OFF       NODE NAME
systemd       1                    root  cwd       DIR              253,0       4096        128 /
systemd       1                    root  rtd       DIR              253,0       4096        128 /
systemd       1                    root  txt       REG              253,0    1498184   51139391 /usr/lib/systemd/systemd
systemd       1                    root  mem       REG              253,0      20032   33597713 /usr/lib64/libuuid.so.1.3.0
systemd       1                    root  mem       REG              253,0     252696   33598486 /usr/lib64/libblkid.so.1.1.0

Understanding output of lsof command:

COMMAND: Command using the file.
PID: PID of the file
USER: Owner of the file
FD: File descriptor. Different flags of File descriptor are as below:

#    :  The number in front of flag(s) is the file descriptor number used by the process to associate with the file
u    :  File open with Read and Write permission
r    :  File open with Read permission
w    :  File open with Write permission
W    :  File open with Write permission and with Write Lock on entire file
mem  :   Memory mapped file, usually for shared library

TYPE: File type. Different flags of File type are as below:
REG - Regular file
DIR - Directory

DEVICE: major, minor number of the device where file resides.
SIZE/OFF: File size
NODE: inode number
NAME: File name

When to use lsof?

One use for this command is when a disk can't be unmounted because files are in use.

  • Finding info on particular process

# lsof -p <PID> # you can use ps aux to display process first.

  • Find process opened by users

# lsof -u <user_name> #

  • Find files opened by a process

# lsof -c <command> #

  • show listen address

lsos -i [46][protocol][@hostname|hostaddr][:service|port]

Note that this command only be executed by root user will have output.

@ The @ character, leading the host specification, is always required;

: : leading the port specification.

Example1: lsof -i:80 -nP # show the processes listening the port 80.

Example2: lsof -i -n -P #

-i Lists IP sockets.

-n Do not resolve hostnames (no DNS).

-P Do not resolve port names (list port number instead of its name).

pwdx

查看进程目录(查看线程工作目录)

pwdx: report current working directory of a process

example:

[root@localhost huangyaohong]# pwdx 2611
2611: /var/lib/mysql

组合使用a:

1.ps aux查看进程;

2.pwdx 进程ID;

组合使用b:

1.lsof -i :1521查看哪个进程在使用1521端口;

2.pwdx 进程ID;

组合使用c-查看哪个进行在使用某端口:

1.netstat -ano查看端口情况;

2.lsof -i :<端口号>得到进程ID;

3.pwdx进程ip

相关文章

  • lsof & pwdx

    What is lsof? lsof is a linux command listed current open...

  • linux下根据进程查找文件启动文件

    摘要:linux下程序启动文件查看 lsof pwdx proc 场景:存在老旧服务,在知道服务端口的情况下,如何...

  • MacOS 端口占用情况

    lsof -i lsof 是 list open files 的缩写用法:lsof -i:端口lsof -i tc...

  • 端口占用清除

    查看端口占用lsof -i :80lsof | grep :80 lsof需要sudo netstat -tln ...

  • lsof

    lsof 简介 lsof(list open files)是一个列出当前系统打开文件的工具。在linux环境下,任...

  • lsof

    lsof(list open files)是一个列出当前系统打开文件的工具。在linux环境下,任何事物都以文件的...

  • lsof

    lsof也是Linux中比较常用的命令,是list open files的简写,在Linux系统中,一切皆为文件。...

  • lsof

    ps axf显示process tree,进程服务,以及连接到该进程的客户端 lsof -p $(cat /var...

  • lsof

    lsof输出各列信息的意义如下: COMMAND:进程的名称 PID:进程标识符 USER:进程所有者 FD:文件...

  • lsof

网友评论

      本文标题:lsof & pwdx

      本文链接:https://www.haomeiwen.com/subject/ofgtyktx.html