Linux, FreeBSD, Juniper, Cisco / Network security articles and troubleshooting guides

FAQ
It is currently Thu Dec 07, 2023 9:16 am


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

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

Joined: Tue Aug 04, 2009 9:16 am
Posts: 250

Offline
 

FreeBSD - fuser checking processes that are using a filesystem

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 7:01 am

Joined: Tue Aug 04, 2009 9:16 am
Posts: 250

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
Woolmer
Post  Post subject: Re: FreeBSD - fuser checking processes that are using a filesystem  |  Posted: Tue Mar 24, 2015 1:26 am

Joined: Tue Mar 24, 2015 1:24 am
Posts: 1

Offline
Displayed are the ID of the user that runs sshd & httpd, PID of the process and state (LISTEN).

_________________
kaleem


Top
Display posts from previous:  Sort by  
E-mail friendPrint 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 get UFS filesystem block size in FreeBSD

mandrei99

0

4946

Mon Jul 22, 2013 9:49 am

mandrei99 View the latest post

There are no new unread posts for this topic. How to read UFS filesystem super block information in FreeBSD

mandrei99

0

3794

Mon Jul 22, 2013 9:52 am

mandrei99 View the latest post

There are no new unread posts for this topic. FreeBSD - How to retrieve the newfs command that was used to create an existing UFS filesystem

mandrei99

0

2399

Mon Jul 22, 2013 9:55 am

mandrei99 View the latest post

There are no new unread posts for this topic. Checking Linux virtual memory page size

mandrei99

0

2225

Mon Feb 09, 2015 4:53 pm

mandrei99 View the latest post

There are no new unread posts for this topic. How to print filesystem super block information in Linux

mandrei99

0

14105

Mon Jul 08, 2013 6:56 am

mandrei99 View the latest post

There are no new unread posts for this topic. How to list PCI devices in FreeBSD - pciconf

mandrei99

0

17158

Mon Jul 22, 2013 9:58 am

mandrei99 View the latest post

There are no new unread posts for this topic. Squid clear cache on FreeBSD

mandrei99

0

4061

Mon Mar 03, 2014 7:37 am

mandrei99 View the latest post

There are no new unread posts for this topic. FreeBSD slow booting: Recovering vi editor sessions

mandrei99

0

3218

Wed Feb 19, 2014 4:02 pm

mandrei99 View the latest post

There are no new unread posts for this topic. How to list the largest files in a directory in Linux/FreeBSD

mandrei99

0

2526

Thu Jan 22, 2015 5:14 pm

mandrei99 View the latest post

There are no new unread posts for this topic. FreeBSD - list disks drive in the system with atacontrol and camcontrol

mandrei99

0

11492

Tue Jan 20, 2015 3:08 am

mandrei99 View the latest post

 

Who is online
Users browsing this forum: Bing [Bot] and 0 guests
You can post new topics in this forum
You can 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 - 5 hours [ DST ]



phpBB SEO