龙空技术网

Linux:查找进程使用的所有文件描述符

追光的Rocky 424

前言:

现在你们对“apache进程查看”大致比较看重,姐妹们都想要分析一些“apache进程查看”的相关知识。那么小编在网摘上网罗了一些对于“apache进程查看””的相关内容,希望同学们能喜欢,小伙伴们一起来了解一下吧!

如何找到httpd(Apache web服务器)或mysqld(MySQL数据库服务器)等进程使用的所有文件描述符?

您可以使用/proc文件系统或lsof命令来查找进程使用的所有文件描述符。

/proc文件系统示例

首先,使用ps命令找出进程ID,输入:

# ps aux | grep processName# ps aux | grep mysqld

示例输出:

root      3632  0.0  0.0  65944  1296 ?        S    Jun05   0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --user=mysqlmysql     3679  9.0  8.9 1393476 733756 ?      Sl   Jun05 3448:12 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --socket=/var/lib/mysql/mysql.sockroot     44723  0.0  0.0  61188   820 pts/0    S+   17:48   0:00 grep mysqld

您还可以按如下方式使用pidof命令来查找进程id(PID):

# pidof processName# pidof mysqld

示例输出:

3679

记下PID # 3679。

/proc/$pid/fd目录示例

输入下的命令:

# ls /proc/3679/fd# ls -l /proc/3679/fd

示例输出:

total 0lr-x------ 1 root root 64 Jul  1 13:09 0 -> /dev/nulll-wx------ 1 root root 64 Jul  1 13:09 1 -> /var/log/mysqld.loglrwx------ 1 root root 64 Jul  1 13:09 10 -> socket:[14667]lrwx------ 1 root root 64 Jul  1 13:09 100 -> /var/lib/mysql/blogdb/wp_term_relationships.MYIlrwx------ 1 root root 64 Jul  1 13:09 101 -> /var/lib/mysql/blogdb/wp_postmeta.MYIlrwx------ 1 root root 64 Jul  1 13:09 102 -> /var/lib/mysql/blogdb/wp_terms.MYIlrwx------ 1 root root 64 Jul  1 13:09 103 -> /var/lib/mysql/orders/discussionread.MYDlrwx------ 1 root root 64 Jul  1 13:09 104 -> /var/lib/mysql/orders/comments.MYIlrwx------ 1 root root 64 Jul  1 13:09 105 -> /var/lib/mysql/orders/useractivation.MYIlrwx------ 1 root root 64 Jul  1 13:09 106 -> /var/lib/mysql/orders/postparsed.MYIlrwx------ 1 root root 64 Jul  1 13:09 107 -> /var/lib/mysql/orders/sigparsed.MYIlrwx------ 1 root root 64 Jul  1 13:09 108 -> /var/lib/mysql/support/forum.MYI................(output truncated)
lsof命令示例

输入以下命令:

# lsof -a -p {PID-HERE}# lsof -a -p 3679

示例输出:

COMMAND  PID  USER   FD      TYPE             DEVICE     SIZE     NODE NAMEmysqld  3679 mysql  cwd       DIR                8,2     4096  7667720 /var/lib/mysqlmysqld  3679 mysql  rtd       DIR                8,2     4096        2 /mysqld  3679 mysql  txt       REG                8,2  7721832 15185707 /usr/libexec/mysqldmysqld  3679 mysql  mem       REG                8,2          13074466 /lib64/ld-2.5.so (path inode=13074445)mysqld  3679 mysql  mem       REG                8,2          13074602 /lib64/libc-2.5.so (path inode=13074454)mysqld  3679 mysql  mem       REG                8,2          13074603 /lib64/libdl-2.5.so (path inode=13074461)mysqld  3679 mysql  mem       REG                8,2          13074608 /lib64/libm-2.5.so (path inode=13074464)mysqld  3679 mysql  mem       REG                8,2          13074612 /lib64/libpthread-2.5.so (path inode=13074491)mysqld  3679 mysql  mem       REG                8,2    85928 15193367 /usr/lib64/libz.so.1.2.3mysqld  3679 mysql  mem       REG                8,2   247496 13074620 /lib64/libsepol.so.1mysqld  3679 mysql  mem       REG                8,2    95464 13074623 /lib64/libselinux.so.1mysqld  3679 mysql  mem       REG                8,2          13074615 /lib64/librt-2.5.so (path inode=13074500)mysqld  3679 mysql  mem       REG                8,2          13074618 /lib64/libnsl-2.5.so (path inode=13074469)mysqld  3679 mysql  mem       REG                8,2          13074633 /lib64/libcrypt-2.5.so (path inode=13074459)mysqld  3679 mysql  mem       REG                8,2  1366272 13074653 /lib64/libcrypto.so.0.9.8emysqld  3679 mysql  mem       REG                8,2          13074655 /lib64/libresolv-2.5.so (path inode=13074496)mysqld  3679 mysql  mem       REG                8,2    58400 13074610 /lib64/libgcc_s-4.1.2-20080825.so.1mysqld  3679 mysql  mem       REG                8,2    10000 13074666 /lib64/libcom_err.so.2.1mysqld  3679 mysql  mem       REG                8,2          15193399 /usr/lib64/libk5crypto.so.3.1 (path inode=15186140)mysqld  3679 mysql  mem       REG                8,2     9728 13074658 /lib64/libkeyutils-1.2.somysqld  3679 mysql  mem       REG                8,2          15193402 /usr/lib64/libgssapi_krb5.so.2.2 (path inode=15186013)mysqld  3679 mysql  mem       REG                8,2          15193397 /usr/lib64/libkrb5support.so.0.1 (path inode=15186147)mysqld  3679 mysql  mem       REG                8,2          15193400 /usr/lib64/libkrb5.so.3.3 (path inode=15184571)mysqld  3679 mysql  mem       REG                8,2   976312 15180443 /usr/lib64/libstdc++.so.6.0.8mysqld  3679 mysql  mem       REG                8,2   315032 13074667 /lib64/libssl.so.0.9.8emysqld  3679 mysql  mem       REG                8,2          13074479 /lib64/libnss_files-2.5.so (path inode=13074476)mysqld  3679 mysql    0r      CHR                1,3              4102 /dev/null..........mysqld  3679 mysql  234u      REG                8,2        0  7700867 /var/lib/mysql/order/subscribediscussion.MYDmysqld  3679 mysql  238u      REG                8,2     2048  7700637 /var/lib/mysql/email/mailqueue.MYImysqld  3679 mysql  239u      REG                8,2    79060  7700593 /var/lib/mysql/email/mailqueue.MYDmysqld  3679 mysql  340u      REG                8,2 17690624  7766217 /var/lib/mysql/blogdb/wp_posts.MYI

要查看所用文件描述符的统计信息,请输入:

# cat /proc/3679/net/sockstat

示例输出:

sockets: used 183TCP: inuse 5 orphan 0 tw 0 alloc 9 mem 2UDP: inuse 9 mem 1UDPLITE: inuse 0RAW: inuse 0FRAG: inuse 0 memory 0

标签: #apache进程查看