fuser

list process IDs of all processes that have files open

OS X:
fuser [ -cfu ] file
Linux:
fuser [-fMuvw] [-a|-s] [-4|-6] [-c|-m|-n space] [-k [-i] [-signal]] name...

Writes to standard output the process IDs of processes running on the local system with files open.
      For block special devices (like disk partitions, sockets), all processes using any file on that device are listed.

Writes to standard error how the process is using the file :
    c current directory
    r root directory.
    e executable being run.
    f open file. f is omitted in default display mode.
    F open file for writing. F is omitted in default display mode.
    m mmap'ed file or shared library.

OS X:

-c file is treated as a mount point and the utility reports on any files open in the file system.
-f report is only for the named files.

-u user name (or UID), in parentheses, is written to STDERR

Linux:

-a
--all
Show all files specified on the command line.
 > fuser -u /bin/bash /bin/fuser
/bin/bash:            4895
default: only files that are accessed by at least one process are shown. not with -s.
> fuser -a /bin/bash /bin/fuser
/bin/bash:            4895
/bin/fuser:
-s
--silent
Silent . --user and -verbose are ignored .
Check return code: a non-zero return code if none of the specified files is accessed or in case of a fatal error
-m name
--mount name
file on a mounted file system or a block device that is mounted.
All processes accessing files on that file system are listed.

If a directory, it is automatically changed to NAME/. to use any file system mounted on that directory.

-M
--ismountpoint
only if Name specifies a mountpoint. Prevents killing the machine if NAME happens to not be a filesystem.
-c Same as -m
-k
--kill Kill
processes accessing the file. SIGKILL is default
-w Kill only processes which have write access.
-i
--interactive
for confirmation before killing a process.
-SIGNAL Use the specified signal instead of SIGKILL can be specified either by name (e.g. -HUP) or by number (e.g. -1).
-l
--list-signals
List signal names.
-n SPACE
--namespace space
Select a different name space. The name spaces file (file names, the default), udp (local UDP ports), and tcp (local TCP ports) are supported. For ports, either the port number or the symbolic name can be specified. If there is no ambiguity, the shortcut notation name/Ispace (e.g. 80/tcp ) can be used.
-u
--user
display the user name of the process owner . to stderr
-v
--verbose
Processes are shown in a ps-like style. The fields PID, USER and COMMAND are similar to ps. ACCESS shows how the process accesses the file.
show when a particular file is being access as a mount point, knfs export or swap file. In this case kernel is shown instead of the PID.
> fuser -v -m /dev/mmcblk0p5 
                     USER        PID ACCESS COMMAND
/dev/mmcblk0p5:      root     kernel swap  /dev/mmcblk0p3
                     root     kernel mount /dev
                     dgerman    2438 f.... xstartup
                     dgerman    2451 f.... ck-launch-sessi
                     dgerman    2502 f.... lxsession
                     dgerman    2505 F.... dbus-launch
                     dgerman    2506 F.... dbus-daemon
                     dgerman    2512 f.... openbox
                     dgerman    2514 f.... lxpanel
                     dgerman    2516 f.... pcmanfm
                     dgerman    2524 f.... lxpolkit
                     dgerman    2527 F.... gvfsd
                     dgerman    2532 F.... pulseaudio
                     dgerman    2539 F.... gvfs-gdu-volume
                     dgerman    2554 F.... gvfs-afc-volume
                     dgerman    2557 F.... gvfs-gphoto2-vo
                     dgerman    2561 F.... menu-cached
                     dgerman    2564 F.... gvfsd-trash

 > fuser -v .
                     USER        PID ACCESS COMMAND
/home/dgerman:       dgerman    2427 ..c.. Xtightvnc
                     dgerman    2438 ..c.. xstartup
                     dgerman    2451 ..c.. ck-launch-sessi
                     dgerman    2502 ..c.. lxsession
                     dgerman    2512 ..c.. openbox
                     dgerman    2514 ..c.. lxpanel
                     dgerman    2516 ..c.. pcmanfm
                     dgerman    2524 ..c.. lxpolkit
                     dgerman    4895 ..c.. bash

-V
--version
Display version information.
fuser (PSmisc) 22.19
Copyright (C) 1993-2010 Werner Almesberger and Craig Small
-4
--ipv4

-6
--ipv6

Search only for IPv4/6 sockets. and only has an effect with the tcp and udp namespaces.
-f ignored
- Reset all options and set the signal back to SIGKILL.

When standard output and standard error are directed to the same destintion, the output is interleaved so that the filename appears at the start of each line, followed by the process ID and characters indicating the use of the file.

Returns a non-zero return code if none of the specified files is accessed or in case of a fatal error

EXAMPLES

From DaPie (raspberry Pi)

DaPie: > sudo fuser -m /dev/mmcblk0p5
/dev/mmcblk0p5:        157   282   286  1540  1549  1828  1907  1911  1940m  

DaPie:/ > sudo fuser -u -m /dev/mmcblk0p5 
/dev/mmcblk0p5:        157(root)   282(root)   286(root)  1540(root)  1549(root)  1828(root)  1907(root)  1911(root)  1940m(root)  


> fuser -u  2>&1 |sed "s/)/)\n/g"   #make seperate lines