/
index.html
244 lines (244 loc) · 16.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>fuser命令(转)</title>
<meta name="author" content="陈子">
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- Le styles -->
<link href="/assets/themes/twitter/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="/assets/themes/twitter/css/style.css?body=1" rel="stylesheet" type="text/css" media="all">
<link href="/assets/themes/twitter/css/pygments/default.css" rel="stylesheet" type="text/css">
<!-- Le fav and touch icons -->
<!-- Update these with your own images
<link rel="shortcut icon" href="images/favicon.ico">
<link rel="apple-touch-icon" href="images/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png">
-->
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="/">三斗室</a>
<ul class="nav">
<li><a href="/archive.html">归档</a></li>
<li><a href="/categories.html">分类</a></li>
<li><a href="/errata.html">《网站运维技术与实践》勘误</a></li>
<li><a href="/pages.html">Pages</a></li>
<li><a href="/projects.html">学习记录</a></li>
<li><a href="/tags.html">标签</a></li>
<li><a href="http://chenlinux.com/poetry/index.html" />诗文集</a></li>
<li><link title="RSS 2.0" type="application/rss+xml" href="http://chenlinux.com/feed.xml" rel="alternate" /><a href="http://chenlinux.com/feed.xml" target="_blank">RSS订阅</a></li>
</ul>
<ul class="nav pull-right"><li><a href="/about.html">有关我</a></li></ul>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="span7">
<div class="row">
<div class="page-header">
<h1>fuser命令(转) <small></small></h1>
<div class="date"><span>03 November 2009</span></div>
</div>
<div style='background-color: #FFF;'>
<p>fuser:使用文件或者套节字来表示识别进程。我常用的他的两个功能:查看我需要的进程和我要杀死我查到的进程。</p>
<p>比如当你想umount光驱的时候,结果系统提示你设备正在使用或者正忙,可是你又找不到到底谁使用了他。这个时候fuser可派上用场了。</p>
<div class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="o">[</span>root@lancy sbin<span class="o">]</span><span class="c"># umount /media/cdrom</span>
umount: /media/cdrom: device is busy
umount: /media/cdrom: device is busy
eject: unmount of <span class="sb">`</span>/media/cdrom<span class="s1">' failed</span>
<span class="s1">[root@lancy sbin]# fuser /mnt/cdrom</span>
<span class="s1">/mnt/cdrom: 4561c 5382c</span>
<span class="s1">[root@lancy sbin]# ps -ef |egrep '</span><span class="o">(</span>4561<span class="p">|</span>5382<span class="o">)</span><span class="err">'</span> <span class="p">|</span>grep -v grep
root <span class="m">4561</span> <span class="m">4227</span> <span class="m">0</span> 20:13 pts/1 00:00:00 bash
root <span class="m">5382</span> <span class="m">4561</span> <span class="m">0</span> 21:42 pts/1 00:00:00 vim Autorun.inf</code></pre></div>
<p>示例中,我想弹出光驱,系统告诉我设备忙着,于是采用fuser命令,参数是你文件或scoket,fuser将查出那些使用了他。</p>
<p>4561c,5382c表示目前用两个进程在占用着/mnt/cdrom,分别是4561,5382,进程ID后的字母表示占用资源的方式,有下面几种表示:</p>
<pre><code>c 当前路径(current directory.)我的理解是表示这个资源的占用是以文件目录方式,也就是进进入了需要释放的资源的路径,这是最常用的资源占用方式。
e 正在运行可执行文件(executable being run.),比如运行了光盘上的某个程序
f 打开文件( open file),缺省模式下f忽略。所以上面的例子中,虽然是开打了光盘上的Autorun.inf文件,但是给出的标识是c,而不是f。
r root目录(root directory).没有明白什么意思,难道是说进入了/root这个特定目录?
m mmap文件或者共享库( mmap’ed file or shared library).这应该是说某个进程使用了你要释放的资源的某个共享文件。
</code></pre>
<p>在查找的同时,你还可定指定一些参数,比如</p>
<pre><code>-k 杀死这些正在访问这些文件的进程。除非使用-signal修改信号,否则将发送SIGKILL信号。
-i 交互模式
-l 列出所有已知的信号名称。
-n 空间,选择不同的名字空间,可是file,udp,tcp。默认是file,也就是文件。
-signal 指定发送的信号,而不是缺省的SIGKILL
-4 仅查询IPV4套接字
-6 仅查询IPV6套接字
- 重置所有的选项,将信息设回SIGKILL
</code></pre>
<p>再看下面的例子</p>
<div class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="o">[</span>root@lancy sbin<span class="o">]</span><span class="c"># fuser -l</span>
HUP INT QUIT ILL TRAP ABRT IOT BUS FPE KILL USR1 SEGV USR2 PIPE
ALRM TERM
STKFLT CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF
WINCH IO PWR SYS
UNUSED</code></pre></div>
<p>现在我们试试fuser -k的威力:</p>
<div class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="o">[</span>root@lancy sbin<span class="o">]</span><span class="c"># fuser -k /mnt/cdrom</span>
/mnt/cdrom: 4561c 5382c
<span class="nb">kill </span>5382: 没有那个进程
No automatic removal. Please use umount /media/cdrom
<span class="o">[</span>root@lancy sbin<span class="o">]</span><span class="c"># eject</span></code></pre></div>
<p>套节字方式的使用:</p>
<div class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="o">[</span>root@lancy sbin<span class="o">]</span><span class="c"># fuser -4 -n tcp 3306</span>
here: 3306
3306/tcp: 5595
<span class="o">[</span>root@lancy sbin<span class="o">]</span><span class="c"># ps -ef |grep 5595 |grep -v grep</span>
mysql <span class="m">5595</span> <span class="m">5563</span> <span class="m">0</span> 22:24 pts/0 00:00:00 /usr/libexec/mysqld
--defaults-file<span class="o">=</span>/etc/my.cnf --basedir<span class="o">=</span>/usr --datadir<span class="o">=</span>/var/lib/mysql
--user<span class="o">=</span>mysql --pid-file<span class="o">=</span>/var/run/mysqld/mysqld.pid --skip-locking
--socket<span class="o">=</span>/var/lib/mysql/mysql.sock
<span class="o">[</span>root@lancy sbin<span class="o">]</span><span class="c"># fuser -4 -n tcp 80</span>
here: 80
80/tcp: <span class="m">5685</span> <span class="m">5688</span> <span class="m">5689</span> <span class="m">5690</span> <span class="m">5691</span> <span class="m">5692</span> <span class="m">5693</span> <span class="m">5694</span> 5695</code></pre></div>
<hr>
<div class="pagination">
<ul>
<li class="prev"><a href="/2009/11/03/zz-dd-usage" title="dd命令使用详解(转)">← Previous</a></li>
<li><a href="/archive.html">Archive</a></li>
<li class="next"><a href="/2009/11/03/zz-linux-performance-command-tools" title="Linux命令行系统性能检测工具(转)">Next →</a></li>
</ul>
</div>
<hr>
<!-- JiaThis Button BEGIN -->
<div class="jiathis_style">
<span class="jiathis_txt">分享到:</span>
<a class="jiathis_button_tsina">新浪微博</a>
<a class="jiathis_button_weixin">微信</a>
<a class="jiathis_button_renren">人人网</a>
<a class="jiathis_button_ydnote">有道云笔记</a>
<a class="jiathis_button_gmail">Gmail邮箱</a>
<a class="jiathis_button_twitter">Twitter</a>
<a class="jiathis_button_googleplus">Google+</a>
<a class="jiathis_button_hi">百度空间</a>
<a class="jiathis_button_fb">Facebook</a>
<a class="jiathis_button_douban">豆瓣</a>
<a href="http://www.jiathis.com/share?uid=1589850" class="jiathis jiathis_txt jiathis_separator jtico jtico_jiathis" target="_blank">更多</a>
<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" >
var jiathis_config={
data_track_clickback:true,
summary:"",
ralateuid:{
"tsina":"1035836154"
},
shortUrl:false,
hideMore:false
}
</script>
<script type="text/javascript" src="http://v3.jiathis.com/code/jia.js?uid=1589850" charset="utf-8"></script>
<!-- JiaThis Button END -->
<!-- UY BEGIN -->
<div id="uyan_frame"></div>
<script type="text/javascript" id="UYScript" src="http://v1.uyan.cc/js/iframe.js?UYUserId=1589850" async=""></script>
<!-- UY END -->
</div>
</div>
</div>
<div class="span4">
<div class="well sidebar-nav">
<ul id="relate_blog" class="nav nav-list">
<li class="nav-header">最近文章</li>
<li><a href="/2014/12/26/report-of-this-year">2014 年度个人总结</a></li>
<li><a href="/2014/12/19/kibana-4-beta-3-now-more-filtery">【翻译】Kibana 4 beta 3 发布,重新支持过滤器</a></li>
<li><a href="/2014/12/08/difference-filterings-kibana">Kibana 中几个不同的 filtering</a></li>
<li><a href="/2014/11/27/elasticsearch-scripts-aggregations">利用脚本灵活定制 Elasticsearch 中的聚合效果</a></li>
<li><a href="/2014/11/23/kibana-panel-only-dashboard">利用动态仪表板实现kibana单图表导出功能</a></li>
<li><a href="/2014/11/20/phantomjs-snapshot">用 phantomjs 截图</a></li>
<li><a href="/2014/11/19/uniq-count-kibana">在 kibana 里实现去重计数</a></li>
<li><a href="/2014/11/18/kibana4-beta-2-get-now">【翻译】Kibana 4 beta 2 发布</a></li>
<li><a href="/2014/10/28/perl6-bench">用 perl6-bench 做 perl6 性能对比</a></li>
</ul>
</div>
<div class="well sidebar-nav">
<iframe width="100%" height="550" class="share_self" frameborder="0" scrolling="no" src="http://widget.weibo.com/weiboshow/index.php?language=&width=0&height=550&fansRow=1&ptype=1&speed=0&skin=2&isTitle=1&noborder=1&isWeibo=1&isFans=1&uid=1035836154&verifier=a26926d5&dpc=1"></iframe>
</div>
<div class="well sidebar-nav">
<div id="uyan_list_time_frame"></div>
<script type="text/javascript" id="UYScriptTime" src="http://v1.uyan.cc/js/iframe_time_list.js?UYUserId=1589850&rankType=time" async=""></script>
</div>
<div class="well sidebar-nav">
<ul id="linklists" class="nav nav-list">
<li class="nav-header">友情链接(英文)</li>
<li><a href="http://codeascraft.com/" title="Etsy 运维团队博客">Code as Craft</a></li>
<li><a href="http://devopsanywhere.blogspot.jp/" title="">devopsanywhere</a></li>
<li><a href="http://www.jedi.be/blog/" title="">Jong En Dynamische Informatica</a></li>
<li><a href="http://www.planetdevops.net/" title="">planetdevops</a></li>
<li><a href="http://www.kitchensoap.com/" title="《网站运维》作者,Etsy 运维">Kitchen Soap</a></li>
<li><a href="http://blog.johngoulah.com" title="Musings of linux, open source, cloud computing and systems">John Goulah</a></li>
<li><a href="http://serverfault.com/" title="stackexchange下属的系统工程师问答网站">serverfault</a></li>
<li><a href="http://www.thegeekstuff.com/" title="各种超酷Linux命令用法">TheGeekStuff</a></li>
<li><a href="http://neilb.org/" title="The good,the bad,and the beautiful">neilb</a></li>
<li><a href="http://www.reddit.com/r/perl/" title="">reddit perl 频道</a></li>
<li><a href="http://jpetazzo.github.io/" title="">~jpetazzo</a></li>
<li><a href="http://www.perfplanet.com/" title="News and views from the web performance blogosphere">Performance Planet</a></li>
<li><a href="http://cuddletech.com/blog/" title="Use UNIX or die">Cuddle Tech</a></li>
<li><a href="http://showmetheco.de/" title="Viacheslav Tykhanovskyi(PocketIO/Text::Haml)">No time to wait</a></li>
<li><a href="http://blog.dataloop.io/" title="A new SaaS monitoring tool for DevOps & Operations">Dataloop.IO</a></li>
<li><a href="http://www.ducea.com/" title="">MDLog:/sysadmin</a></li>
<li><a href="http://planeteria.org/perl6/" title="Perl6 文集">Planet Perl 6</a></li>
<li><a href="http://www.metaforsoftware.com/blog/" title="">metafor</a></li>
<li><a href="http://blog.kablamo.org/" title="Eric Johnson,一个游走在伦敦和北京的 Perler">kablamo</a></li>
<li><a href="http://aphyr.com/posts" title="call me maybe 吐槽系列">Aphyr</a></li>
</ul>
</div>
<div class="well sidebar-nav">
<ul id="linklists" class="nav nav-list">
<li class="nav-header">友情链接(中文)</li>
<li><a href="http://www.nginxs.com/" title="">eric</a></li>
<li><a href="http://www.hellodb.net/" title="Ali DBA 张瑞">Hello DBA</a></li>
<li><a href="http://blog.nosqlfan.com/" title="not only sql信息集散地">NoSQLfan</a></li>
<li><a href="http://ourmysql.com/" title="">OurMySQL</a></li>
<li><a href="http://timo.piqiu.me/" title="TIMO IS MY OASIS">Timo</a></li>
<li><a href="http://www.liurongxing.com/" title="">刘荣星</a></li>
<li><a href="http://www.cnadn.net/" title="F5工程师">应用交付学习之路</a></li>
<li><a href="http://scmbob.org/" title="杭州NSN工程师,shell高人~">扛一肩记忆</a></li>
<li><a href="http://www.php-oa.com/" title="音悦台技术经理">扶凯</a></li>
<li><a href="http://www.lark.net.cn/" title="王剑">lark's cloud</a></li>
<li><a href="http://log.heartoutside.com/" title="HeartOutSide">HeartOutside</a></li>
<li><a href="http://blog.liulantao.com/" title="刘兰涛">Lax</a></li>
<li><a href="http://niubie.me/" title="莫言">莫言</a></li>
<li><a href="http://noops.me/" title="小米运维部">NoOps</a></li>
<li><a href="http://www.searchtech.pro/" title="">云端分布式搜索技术</a></li>
<li><a href="http://www.usefulshare.com" title="当当网安全运维">UsefulShare</a></li>
<li><a href="http://junqili.com/" title="深入研究puppet">纸飞机</a></li>
<li><a href="http://www.chinaxing.org/" title="">ChinaXing</a></li>
<li><a href="http://bubbyroom.com/" title="守住每一天">Liuyu's blog</a></li>
<li><a href="http://blog.aka-cool.net/" title="">Aka.Why</a></li>
<li><a href="http://blog.l8ii.com/" title="刘侨">LairdNote</a></li>
<li><a href="http://flw.tools/" title="">flw的工具箱</a></li>
<li><a href="http://blog.mcshell.org/" title="">mcshell</a></li>
<li><a href="http://novoland.github.io/" title="">克鲁斯卡尔的博客</a></li>
</ul>
</div>
<div class="well sidebar-nav">
<ul id="booklists" class="nav nav-list">
<li class="nav-header">我写的第一本技术书籍</li>
<li><a href='http://product.china-pub.com/3769604'><img src='http://images.china-pub.com/ebook3765001-3770000/3769604/shupi.jpg' border='0' alt='网站运维技术与实践'/></a></li>
<li class="nav-header">我写的两本电子书籍</li>
<li><a href='http://chenryn.gitbooks.io/logstash-best-practice/'><img src='https://sm3lir.cloudimage.io/s/cdn/x/https://www.gitbook.io/cover/book/chenryn/logstash-best-practice?build=1416299695472' border='0' alt='LogStash 最佳实践'/></a></li>
<li><a href='http://kibana.logstash.es/'><img src='https://sm3lir.cloudimage.io/s/cdn/x/https://www.gitbook.io/cover/book/chenryn/kibana-guide-cn?build=1415872457562' border='0' alt='Kibana 中文指南'/></a></li>
</div>
</div>
</div> <!-- row -->
<footer>
<p>© 陈子 2012
with help from <a href="http://jekyllbootstrap.com" target="_blank" title="The Definitive Jekyll Blogging Framework">Jekyll Bootstrap</a>
and <a href="http://twitter.github.com/bootstrap/" target="_blank">Twitter Bootstrap</a>
</p>
</footer>
</div> <!-- /container -->
</body>
</html>