Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

fuser

Show which processes use a file, a folder, a mounted file system or a network port — and stop them if needed.

Niveau
Dagelijks Linux
Groep
Processen en jobs
Root nodig
Voor wijzigingen
Pakket
psmisc

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

fuser answers "who is using this?". The most common case is umount: target is busy: fuser -vm /mnt/usb lists the processes with files open on that file system. With -k it sends them a signal. It also works for ports: fuser 80/tcp prints the PID that owns TCP port 80.

The letter after each PID tells how the file is used: c = current folder, e = running program, f = open file, F = open for writing, r = root folder, m = memory-mapped.

Zo schrijf je het

fuser [OPTION]... NAME...
fuser -k [-SIGNAL] [-i] NAME...

Opties 17

Meest gebruikt

Options

-v, --verbose
Show user, PID, access type and command.
-m, --mount NAME
All processes that use the file system NAME is on.
-M, --ismountpoint
Work only if NAME is a mount point.
-k, --kill
Kill the processes (default SIGKILL).
-SIGNAL
Use this signal with -k (-TERM, -HUP).
-i, --interactive
Ask before each kill.
-w
With -k: only processes that write.
-u, --user
Show the user of each process.
-n, --namespace SPACE
Name space: file, udp or tcp (fuser -n tcp 80).
-4, --ipv4 / -6, --ipv6
Only IPv4 / IPv6 sockets.
-a, --all
Also show files that nobody uses.
-s, --silent
No output; only the exit status.
-I, --inode
Compare by inode (for network file systems).
-l, --list-signals
List the signal names.
-c
Same as -m (POSIX).
-f
Ignored (POSIX).
-V, --version
Show the version.

Voorbeelden 10

$ als gewone gebruiker# als root (of met sudo)

  1. 1Why does umount say "target is busy"?

    fuser -vm /mnt/usb
                         USER        PID ACCESS COMMAND
    /mnt/usb:            root     kernel mount /mnt/usb
                         student    4321 ..c.. bash

    The shell of student is inside the folder (c = current directory).

  2. 2Stop the processes, then unmount

    fuser -km -TERM /mnt/usb
    umount /mnt/usb
  3. 3Ask before every kill

    fuser -kim /srv/data
  4. 4Which process owns a port?

    fuser 80/tcp
    80/tcp:               1420
    fuser -v -n tcp 22
  5. 5Who has a log file open?

    fuser -v /var/log/messages
  6. 6Check in a script if a file is in use

    fuser -s /srv/import/data.csv && echo "still being written" || echo "free"
  7. 7Only processes that write to a file

    fuser -kw -TERM /srv/app/app.db
  8. 8Find users on an NFS mount before a server reboot

    fuser -vmu /mnt/shared
  9. 9Free a UDP port

    fuser -k 5353/udp
  10. 10Use the device name instead of the folder

    fuser -vm /dev/sdb1

    Same result as with the mount point; useful when you only know the device.

Let op

  • fuser -k uses SIGKILL by default: no clean-up. Prefer -k -TERM first.
  • On / or /home, -km would kill almost everything. Always use -v first to look.

Tips om te onthouden

Exitcodes

0At least one process was found (or killed).
1No process uses the name, or an error.