|Lesson 8||The fuser command|
|Objective|| Mount and unmount a partition.|
The fuser command in Unix is used to identify which processes are using a particular file, directory or socket.
The purpose of the fuser command is to provide information about which processes are accessing a particular resource.
This can be useful for troubleshooting and for identifying which processes may be preventing a resource from being modified or deleted.
When the fuser command is executed with a file or directory name as an argument, it returns a list of (PIDs) process IDs
that are accessing that resource. The command can also be used with various options to display additional information about the processes, such as their user IDs, the names of the processes, and the number of file descriptors in use. Overall, the fuser command is a useful tool for system administrators and users who need to identify which processes are accessing a particular resource in Unix. It can help in troubleshooting issues and can be used to determine which processes may be preventing a resource from being modified or deleted.
command will reveal all processes that have files open on the device and therefore are preventing it from being unmounted.
Here is a Linux example of using the
/usr/sbin/fuser –v –m /mnt
USER PID ACCESS COMMAND
userA 1011 ..c.. bash
In this example, the
option refers to the mount point we are interested in. The
option asks for verbose output. On Solaris, the
option performs the same function as
. The output from
lists all processes (by PID
) that are using the given filesystem, their owners, and an indication of what they are doing:
f means open file.
e means running an executable from that filesystem.
c means have current directory on that filesystem.
In the output above, we see that userA has process 1011 with current directory in the /mnt filesystem. This is why we cannot unmount /mnt.
command can be used to kill all processes accessing a filesystem. For example, on Linux:
/usr/sbin/fuser –k -m /mnt
–k option kills all processes using the specified file or filesystem.
mounting Unmounting using Linux
Mounting and unmounting using Solaris (Simulation transcript)
Here are the steps you followed in this simulation:
In these simulations, you will mount and unmount the floppy disk filesystem you created earlier. The processes are very different across different versions of UNIX. Choose which UNIX version you would like to simulate by clicking either the Linux or the Solaris button.
- You are logged in as a superuser and have inserted the floppy disk into the drive. Type
volcheck -v /dev/diskette0 to verify that the floppy device is mounted.
- You can unmount the floppy using the
eject command. But first, let’s look at what occurs if you attempt to eject a floppy when a directory is active. To test this, change to the /floppy0 directory. Remember that floppy0 is the root directory of the floppy disk.
It is located in the /floppy directory. Solution:
- Try to eject the floppy by typing
- You received a "device is busy" message. Type
/usr/sbin/fuser -u /floppy/floppy0 to learn exactly why you received this message. The
–u option will show any usernames accessing any directories.
- You can see that you (root) are currently accessing the /floppy/floppy0 directory. This is why the
c indicator is listed. Now that you have tested this, use your floppy disk to back up the files in your /etc directory. First, change to the /etc directory.
cp * /floppy/floppy0 to copy all files in the /etc directory to the floppy disk.
- Note that you copied only the files in the /etc directory. This is why you received messages that
cp is omitting directories. Type
ls –l /floppy/floppy0 to list all the files on the floppy disk.
- Normally, this list would be quite lengthy, so for the purposes of this simulation, we’re showing you only a few lines. Remember that you are in the /etc directory. Use the
eject command to unmount the floppy drive.
 process ID (PID):
A process ID (PID) is a unique number associated with each process on the system. PIDs start with number 1, which is the init process.