博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Unix 高级用户命令 lsof 和 fuser (zt)
阅读量:2453 次
发布时间:2019-05-10

本文共 3100 字,大约阅读时间需要 10 分钟。

fuser - identify processes using files or sockets
lsof - list open files

List Open Files: lsof and fuser

The function of these commands is very similar. The goal is to determine what processes have certain files open. lsof is freeware and thus freely compilable under all Unixes. It is available by default under Linux only.

The main difference between lsof and fuser is that lsof takes both files/filesystems and PIDs as arguments whereas fuser only accepts files/filesystems.

lsof:

lsof stands for list open files. It lists information about files that are currently open by processes.

In the absence of any options, lsof lists all open files belonging to all active processes

To list all open files for login name ``abe'', or user ID 1234 you would use the -u option. To list files being used by process 456, process 123, or process 789, you would use the -p flag. Putting these criteria together, we would have a command that looks like this:

lsof -p 456,123,789 -u 1234,abe

The command to list all open files on device /dev/hd4, would look like this:

lsof /dev/hd4

To find the process that has /u/abe/foo open, use:

lsof /u/abe/foo

fuser:

fuser is more widely available (under AIX, HP-UX, IRIX, Linux, Solaris, Tru64 UNIX, and others) and can only be run as root. It displays the process ID numbers of processes using the specified files or file systems. In the default display mode, each file name is followed by a letter denoting the type of access (these codes differ from vendor to vendor):

a if the process is using the file as its trace file in /proc (IRIX)
c if the process is using the file as its current directory
e if the process is using the file as the executable being run
f if the process is using the file as an open file (Linux)
m if the process is using the file as a mmaped or shared lib (Linux)
o if the process is using the file as an open file (IRIX, Solaris, Tru64 UNIX))
p if the process is using the file as the parent of its current directory (Tru64 UNIX)
r if the process is using the file as root directory
s if the process is using the file as a shared lib (AIX)
t if the process is using the file as its text file (Solaris)
y if the process is using the file as its controlling terminal (IRIX)

Here is an example of fuser running under Linux:

linux# /usr/sbin/fuser / /:     1r     1c     2r     2c     3r     3c     4r     4c 252r   252c   275r   275c   286r   286c   300r   314r   328r   328c   342r 342c   356r   356c   374r   374c   385r   385c   396r   396c   411r   411c 412r   412c   413r   413c   414r   414c   415r   415c   416r   416c   417r 417c   418r   418c   419r   419c   420r   420c   455r   470r   470c   485r 485c   500r   500c   538r   538c   539r   539c   540r   540c   541r   541c 542r   542c   543r   543c   544r   544c   546r   546c   548r   548c   551r 551c   556r   569r   591r   597r   610r   612r   614r   614c   618r   626r 628r   636r   646r  7090r  7090c  7092r  7243r  7288r  7288c  7290r  7303r

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/312079/viewspace-245332/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/312079/viewspace-245332/

你可能感兴趣的文章
freecodecamp_我们使用freeCodeCamp课程创建了本地免费编码学校。 这是我们学到的东西。
查看>>
Docker Remove Image:如何删除Docker镜像示例
查看>>
函数式编程 java_学习Java函数式编程-完整课程
查看>>
github 图像ai项目_如何在Github项目存储库中添加社交媒体图像
查看>>
国外开放知识图谱_什么是开放图谱,如何在我的网站上使用它?
查看>>
ntp时间同步会同步时区吗_如何处理时区并使软件与国际客户同步
查看>>
什么是JAMstack?如何开始?
查看>>
firebase使用_如何使用ReactJS和Firebase构建TodoApp
查看>>
nsfw_如何使用机器学习设置NSFW内容检测
查看>>
react中使用构建缓存_如何使用React构建客户支持实时聊天小部件
查看>>
reactjs生命周期_如何在ReactJS中了解组件的生命周期方法
查看>>
graphql和rest_如何使用GraphQL使您的网站整洁和可维护
查看>>
flutter dart_Dart和Flutter的简化介绍
查看>>
hbuilder自述文件_为什么创建自述文件已成为我最喜欢的开发部分
查看>>
从ES5到ESNext-这是自2015年以来添加到JavaScript的所有功能
查看>>
GraphQL中的突变简介:它们是什么以及如何使用它们
查看>>
计算机编程课程顺序_550月份提供免费的在线编程和计算机科学课程
查看>>
哈希编码学习方法_想学习编码吗? 这很容易。 这是解决困难部分的方法。
查看>>
python基础知识教程_通过此深入的视频课程学习Python基础知识
查看>>
idea构建web工程_如何使用系统工程来构建成功的Web应用程序
查看>>