82.5. 监控进程

简介:

列出某个程序进程所打开的文件信息,显示httpd进程现在打开的文件

lsof -c httpd
		

显示多个进程命令用法

[root@netkiller ~]# lsof -c smbd
COMMAND  PID USER   FD   TYPE             DEVICE SIZE/OFF    NODE NAME
smbd    2506 root  cwd    DIR                8,2     4096       2 /
smbd    2506 root  rtd    DIR                8,2     4096       2 /
smbd    2506 root  txt    REG                8,2 10112200 3935771 /usr/sbin/smbd

[root@netkiller ~]# lsof -c smbd -c httpd		
		

-p 进程ID, 显示该进程打开了那些文件

pgrep httpd
lsof -p 1782
		

显示进程ID

# lsof -t -u apache
4374
4375
4376
4377
4378
4379
4380

列出某个程序号打开的文件

[root@netkiller ~]# lsof -p 2374
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF    NODE NAME
httpd   2374 root  cwd    DIR    8,2     4096       2 /
httpd   2374 root  rtd    DIR    8,2     4096       2 /
httpd   2374 root  txt    REG    8,2  1772950 4985314 /usr/local/apache/bin/httpd
httpd   2374 root  DEL    REG    0,4            12653 /dev/zero
httpd   2374 root  mem    REG    8,2    90784 5636110 /lib64/libgcc_s-4.4.7-20120601.so.1	
		

监控多个进程ID

[root@netkiller neo]# lsof -p 20535,26359,31462 | more
COMMAND   PID    USER   FD   TYPE             DEVICE   SIZE/OFF      NODE NAME
nginx   20535    root  cwd    DIR              253,1       4096         2 /
nginx   20535    root  rtd    DIR              253,1       4096         2 /
nginx   20535    root  txt    REG              253,1    1066704    142069 /usr/sbin/nginx
nginx   20535    root  DEL    REG                0,4            686393039 /dev/zero
nginx   20535    root  mem    REG              253,1      61928    162109 /usr/lib64/libnss_files-2.17.so
nginx   20535    root  mem    REG              253,1     153192    151546 /usr/lib64/liblzma.so.5.0.99
nginx   20535    root  mem    REG              253,1     147120    133015 /usr/lib64/libselinux.so.1
nginx   20535    root  mem    REG              253,1     110808    162113 /usr/lib64/libresolv-2.17.so
nginx   20535    root  mem    REG              253,1      15688    134676 /usr/lib64/libkeyutils.so.1.5
nginx   20535    root  mem    REG              253,1      62720    158030 /usr/lib64/libkrb5support.so.0.1
nginx   20535    root  mem    REG              253,1     202576    137049 /usr/lib64/libk5crypto.so.3.1
nginx   20535    root  mem    REG              253,1      15840    133029 /usr/lib64/libcom_err.so.2.1
nginx   20535    root  mem    REG              253,1     950496    137059 /usr/lib64/libkrb5.so.3.3
nginx   20535    root  mem    REG              253,1     316528    151679 /usr/lib64/libgssapi_krb5.so.2.2
nginx   20535    root  mem    REG              253,1      11376    151527 /usr/lib64/libfreebl3.so
nginx   20535    root  mem    REG              253,1    2112384    132823 /usr/lib64/libc-2.17.so
nginx   20535    root  mem    REG              253,1      90632    133017 /usr/lib64/libz.so.1.2.7
nginx   20535    root  mem    REG              253,1    2016880    132882 /usr/lib64/libcrypto.so.1.0.1e
nginx   20535    root  mem    REG              253,1     449904    137215 /usr/lib64/libssl.so.1.0.1e
nginx   20535    root  mem    REG              253,1     398264    160788 /usr/lib64/libpcre.so.1.2.0
nginx   20535    root  mem    REG              253,1      40816    151198 /usr/lib64/libcrypt-2.17.so
nginx   20535    root  mem    REG              253,1     142304    132849 /usr/lib64/libpthread-2.17.so
nginx   20535    root  mem    REG              253,1      19520    162101 /usr/lib64/libdl-2.17.so
nginx   20535    root  mem    REG              253,1     164440    132816 /usr/lib64/ld-2.17.so
nginx   20535    root  DEL    REG                0,4            686393042 /dev/zero
nginx   20535    root    0u   CHR                1,3        0t0      1028 /dev/null
nginx   20535    root    1u   CHR                1,3        0t0      1028 /dev/null
		
		

排除1,4,显示2,3,5

[root@netkiller neo]# lsof -p ^1,2,3,^4,5
COMMAND   PID USER   FD      TYPE DEVICE SIZE/OFF NODE NAME
kthreadd    2 root  cwd       DIR  253,1     4096    2 /
kthreadd    2 root  rtd       DIR  253,1     4096    2 /
kthreadd    2 root  txt   unknown                      /proc/2/exe
ksoftirqd   3 root  cwd       DIR  253,1     4096    2 /
ksoftirqd   3 root  rtd       DIR  253,1     4096    2 /
ksoftirqd   3 root  txt   unknown                      /proc/3/exe
kworker/0   5 root  cwd       DIR  253,1     4096    2 /
kworker/0   5 root  rtd       DIR  253,1     4096    2 /
kworker/0   5 root  txt   unknown                      /proc/5/exe
			
		




原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

目录
相关文章
|
9天前
|
监控 Linux
linux监控指定进程
请注意,以上步骤提供了一种基本的方式来监控指定进程。根据你的需求,你可以选择使用不同的工具和参数来获取更详细的进程信息。
14 0
|
17天前
|
监控 Java Linux
linux下监控java进程 实现自动重启服务
linux下监控java进程 实现自动重启服务
|
2月前
|
监控 Python Windows
使用python脚本来监控进程
使用python脚本来监控进程
|
2月前
|
监控 Unix Linux
socket监控进程,并对程序执行有关操作。
socket监控进程,并对程序执行有关操作。
|
3月前
|
监控 Shell
Shell脚本进程监控
Shell脚本进程监控
29 2
|
3月前
|
监控 Shell
在Shell脚本中实现进程监控
在Shell脚本中实现进程监控
92 5
|
4月前
|
监控 安全 API
7.1 Windows驱动开发:内核监控进程与线程回调
在前面的文章中`LyShark`一直在重复的实现对系统底层模块的枚举,今天我们将展开一个新的话题,内核监控,我们以`监控进程线程`创建为例,在`Win10`系统中监控进程与线程可以使用微软提供给我们的两个新函数来实现,此类函数的原理是创建一个回调事件,当有进程或线程被创建或者注销时,系统会通过回调机制将该进程相关信息优先返回给我们自己的函数待处理结束后再转向系统层。
59 0
7.1 Windows驱动开发:内核监控进程与线程回调
|
4月前
|
监控 Windows
4.4 Windows驱动开发:内核监控进程与线程创建
当你需要在Windows操作系统中监控进程的启动和退出时,可以使用`PsSetCreateProcessNotifyRoutineEx`函数来创建一个`MyCreateProcessNotifyEx`回调函数,该回调函数将在每个进程的创建和退出时被调用。PsSetCreateProcessNotifyRoutineEx 用于在系统启动后向内核注册一个回调函数,以监视新进程的创建和退出,
40 0
4.4 Windows驱动开发:内核监控进程与线程创建
|
4月前
|
监控 安全 Windows
4.3 Windows驱动开发:监控进程与线程对象操作
在内核中,可以使用`ObRegisterCallbacks`这个内核回调函数来实现监控进程和线程对象操作。通过注册一个`OB_CALLBACK_REGISTRATION`回调结构体,可以指定所需的回调函数和回调的监控类型。这个回调结构体包含了回调函数和监控的对象类型,还有一个`Altitude`字段,用于指定回调函数的优先级。优先级越高的回调函数会先被调用,如果某个回调函数返回了一个非NULL值,后续的回调函数就不会被调用。当有进程或线程对象创建、删除、复制或重命名时,内核会调用注册的回调函数。回调函数可以访问被监控对象的信息,如句柄、进程ID等,并可以采取相应的操作,如打印日志、记录信息等。
28 0
4.3 Windows驱动开发:监控进程与线程对象操作
|
5月前
|
监控 关系型数据库 调度
盘点5个.Net开发的服务器进程监控、性能监控、任务调度的开源项目
盘点5个.Net开发的服务器进程监控、性能监控、任务调度的开源项目
127 0

相关实验场景

更多