fuser command
๐ง Command: fuser (File/Filesystem/Port User Identifier)
๐ Purpose
The fuser command shows which processes are currently using a specific file, directory, or socket.
It is often used to:
-
Identify which process is using a file, mount point, or device
-
Detect which process is listening on a network port
-
Terminate processes that are using a specific resource
๐งฉ Basic Syntax
Where:
-
name→ can be a file, directory, mount point, or network port
๐ Example 1: Identify Process Using a File
Output:
๐งฉ Explanation
-
3210→ Process ID (PID) of the process using the filetest.txt
You can then check what that process is:
๐ Example 2: Show Processes Using a Directory
Output:
๐งฉ Explanation of Suffixes (Access Types):
| Symbol | Meaning |
|---|---|
c | Current directory |
e | Executable being run |
f | Open file |
r | Root directory |
m | Memory-mapped file or library |
So in the example above:
-
PID
1203→ has/home/useras current directory -
PID
2145→ executing something from/home/user -
PID
3189→ has/home/useras root directory
๐ Example 3: Show Processes Using a Mount Point
If you have an external drive or partition mounted (say /mnt/usb):
Output:
๐งฉ Explanation:
-
The
-voption gives a verbose table showing username, PID, access type, and command name. -
Very useful before unmounting a drive — you can see which process is using it.
๐ Example 4: Show Which Process Uses a TCP Port
Output:
๐งฉ Means process ID 1325 is using TCP port 80 — typically a web server like Apache or Nginx.
Check which process that is:
Output:
๐ Example 5: Show Processes Using a UDP Port
Output:
๐งฉ This usually corresponds to the DNS server process (named or systemd-resolved).
๐ Example 6: Kill Processes Using a Resource
You can use -k to terminate all processes using a file or port.
Example — free up port 8080:
๐งฉ This will send a SIGKILL signal (kill -9) to processes using that port.
You can specify a different signal using -signal:
๐ Example 7: Display Usernames Along with PIDs
Output:
๐งฉ Useful when multiple users are logged in and you want to see who is accessing a resource.
๐ Example 8: Combine with lsof
While fuser shows process IDs using a resource, you can use lsof for more details.
Example:
This gives both PID and full command details — a good comparative experiment for students.
๐งพ Common Options Summary
| Option | Description |
|---|---|
-v | Verbose output (shows user, PID, access type, and command) |
-u | Show username of process owner |
-k | Kill processes using the resource |
-i | Ask for confirmation before killing |
-n <space> | Specify namespace (file, tcp, udp) |
-a | Show all specified files, even if unused |
-m | Name is a mounted file system |
-s | Silent mode (no messages) |
๐งช Simple Lab Exercise
Aim:
To study and use the fuser command to identify processes using files and ports.
Procedure:
-
Open a terminal and run:
(Keep this terminal open — the file is now being used.)
-
In another terminal, check:
-
Observe the PID.
-
Use:
to see user and access type.
-
Find which process is using a network port:
-
Kill a process using a port (be cautious):
Sample Observation Table
| Command | Description | Sample Output |
|---|---|---|
fuser test.txt | Show PID using file | test.txt: 2145 |
fuser -v test.txt | Verbose info | USER PID ACCESS COMMAND |
sudo fuser 22/tcp | Show PID using port 22 | 22/tcp: 1034 |
sudo fuser -k 8080/tcp | Kill process on port 8080 | (process terminated) |
๐ง Learning Outcomes
Students will:
-
Learn how to identify active processes using a file, directory, or port
-
Understand resource locking and file usage conflicts
-
Gain experience in system administration and process control
-
Understand how to free a busy mount point or port
๐งพ Quick Reference
| Command | Purpose |
|---|---|
fuser filename | Show process IDs using a file |
fuser -v dir/ | Show detailed process info |
sudo fuser 80/tcp | Show process using TCP port 80 |
sudo fuser -k 80/tcp | Kill process using port 80 |
fuser -u file | Show usernames |
fuser -m /mnt/usb | Show processes using a mount point |
Comments
Post a Comment