Ivorde Unix/Linux/Database/Web/Mail Forum

View unanswered posts
View active topics
It is currently Wed Feb 08, 2012 8:19 am


System administration, processes administration, jobs, cron, resources, limits, shells, ssh, telnet.

Bookmark this article:

Author Message
mandrei99
  Post  Post subject: FreeBSD - fuser checking processes that are using a filesystem  |  Posted: Thu Mar 18, 2010 1:58 pm

Joined: Tue Aug 04, 2009 4:16 pm
Posts: 20

Offline
Save on Delicious
fuser -- list IDs of all processes that have one or more files open

man fuser:
Quote:
DESCRIPTION
The fuser utility shall write to stdout the process IDs of processes that
have one or more named files open. For block and character special
devices, all processes using files on that device are listed. A file is
considered open by a process if it was explicitly opened, is the working
directory, root directory, jail root directory, active executable text,
kernel trace file for that process or controlling tty of the process. If
-m option is specified, the fuser utility will search through mmapped
files also.

The following options are available:

-c Treat files as mount point and report on any files open in the
file system.

-f The report must be only for named files.

-k Send signal to reported processes (SIGKILL by default).

-m Report on mmapped files too.

-u Write the user name, associated with each process, to stdout.

-C Use given kernel core file instead of default /dev/kmem.

-K Use specified kernel image instead of the default one, which is
the image the system has booted from.

-s Use given signal name instead of default SIGKILL.


FreeBSD fuser utility will output on stderr some symbols for each pid. These symbols can be:
Quote:
The following symbols, written to stderr will indicate how files is used:

r The file is the root directory of the process.

c The file is the current workdir directory of the process.

j The file is the jail-root of the process.

t The file is the kernel tracing file for the process.

x The file is executable text of the process.

y The process use this file as its controlling tty.

m The file is mmapped.

w The file is open for writing.

a The file is open as append only (O_APPEND was specified).

d The process bypasses fs cache while writing to this file (O_DIRECT
was specified).

s Shared lock is hold.

e Exclusive lock is hold.


Finding processes using a filesystem:
Code:
# fuser -c /storage
/storage: 12766c 13275c 13943c 14562c 16067c 32273c 33826c 35474c 35977c 59598c


As you can see fuser -c displays a list of pids using a specified filesystem. But let's say we want to see the full command of those processes:
Code:
# ps alxw | grep -E "`fuser -c /storage 2>/dev/null | sed 's/.\(.*\)/\1/g;s/\ /|/g'`"
    0 12766     1   0  96  0  3664  1784 select Ss    ??    0:04.65 screen
4016 13943 12766  56   8  0  3612     0 wait   IWs   p4    0:00.00 /usr/local/bin/bash --login /usr/local/bin/bash2
4016 33826 13943   0   5  0  3716     0 ttyin  IW+   p4    0:00.00 /usr/local/bin/bash
4016 13275 12766  56   8  0  3612     0 wait   IWs   p3    0:00.00 /usr/local/bin/bash --login /usr/local/bin/bash2
4016 32273 13275   0   8  0  3720     0 wait   IW    p3    0:00.00 /usr/local/bin/bash
4016 59598 32273  64 104  0 115192  5404 -      R+    p3    5:06.18 rtorrent
4016 14562 12766  60   8  0  3612     0 wait   IWs   p5    0:00.00 /usr/local/bin/bash --login /usr/local/bin/bash2
4016 35474 14562   0   5  0  3716     0 ttyin  IW+   p5    0:00.00 /usr/local/bin/bash
4016 16067 12766  60   8  0  3612     0 wait   IWs   p6    0:00.00 /usr/local/bin/bash --login /usr/local/bin/bash2
4016 35977 16067   0   5  0  3716     0 ttyin  IW+   p6    0:00.00 /usr/local/bin/bash


In the above command the symbols are stripped out from the output by sending stderr to /dev/null, leaving pids separated by empty spaces. Next, the spaces are being replaced by pipes: "12766|13275|13943|14562|16067|32273|33826|35474|35977|59598". Then this string is given to grep -E (Interpret PATTERN as an extended regular expression). The output of ps is filtered for the PIDs from the fuser command. The result is the full ps output of the processes using a filesystem.

There are plenty of other methods of finding out the full command of each process from the output of the fuser command, but they are not the scope of this post.


Top
mandrei99
Post  Post subject: Re: FreeBSD - fuser checking processes that are using a filesystem  |  Posted: Thu Mar 18, 2010 2:01 pm

Joined: Tue Aug 04, 2009 4:16 pm
Posts: 20

Offline
Fuser doesn't come by default on FreeBSD. It must be installed from ports (/usr/ports/sysutils/fuser) or from packages (pkg_add -rv fuser).


Top
Display posts from previous:  Sort by  
Print view

Topics related to - "FreeBSD - fuser checking processes that are using a filesystem"
 Topics   Author   Replies   Views   Last post 
There are no new unread posts for this topic. How to check if ssh/http daemon listens on TCP port in FreeBSD using sockstat & lsof & netstat util

mandrei99

0

261

Mon Oct 17, 2011 4:27 pm

mandrei99 View the latest post

 

Who is online
Users browsing this forum: No registered users and 0 guests
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
Jump to:  
News News Site map Site map SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list


Delete all board cookies | The team | All times are UTC + 2 hours [ DST ]

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
DAJ Glass 2 template created by Dustin Baccetti

phpBB SEO