Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I jus need help with this three questions of Linux class. 1- The options for fus

ID: 3604988 • Letter: I

Question

I jus need help with this three questions of Linux class.

1- The options for fuser are different for Unix and Linux machines. For example, the command on Solaris is:
/usr/sbin/fuser -u -c / (helios or pegasus)
Read the manpages for Solaris (can be found online) and Linux to see how else the command differs. Explain the differences.

2- Give an example (paste in a directory listing) of each of the following file types for at least two of your Virtual Machines:

regular file

directory

character device file

block device file

symbolic link

3- Name one file owned by each of the following users: daemon, bin, sys Look at two or more virtual machines.

Explanation / Answer

Before unmounting a filesystem, Solaris checks to ensure that no files are open to prevent loss of data. The following are steps that can be followed when a filesystem won’t unmount.

The fuser utility lists processes using a file or files in a filesystem. It’s To determine what processes may be preventing a filesystem’s umount, the -c switch must be used as running this command as root:

fuser -c /mnt /mnt: 19504tm 19492tm 19460tm

This command will list the process ids of processes with open files in the filesystem mounted under /mnt. The characters following the pid provide additional information about the file:

fuser -cu /mnt /mnt: 19504tm(root) 19492tm(root) 19460tm(qmchenry)

If you feel comfortable killing the processes reported by fuser, you can do it in one quick blow with the -k option:

fuser -ck /mnt

This sends the SIGKILL signal to each process which is the same as running kill pid to each process.

However, before you go to this extreme, perhaps the most common reason a filesystem won’t unmount is because you (or a previous shell you used) has its current working directory in that filesystem.

The man command can be used to see manual pages for any command, but the best way to learn something new, especially linux commands, is by going through real world examples and never stop typing commands in the terminal. Run the following command in your terminal to get information about the usage options of the fuser utility. We will be experimenting with the fuser utility on a Ubuntu 12.04 VPS. However, as long as you are running a linux distribution it should be okay.

Fuser linux:

root@exampleuser-X55CR:~# fuser

No process specification given

Usage: fuser [-fMuv] [-a|-s] [-4|-6] [-c|-m|-n SPACE] [-k [-i] [-SIGNAL]] NAME...

       fuser -l

       fuser -V

Show which processes use the named files, sockets, or filesystems.

udp/tcp names: [local_port][,[rmt_host][,[rmt_port]]]

How To View Processes Using A Directory

The fuser utility can be used with -v option, which runs the tool in verbose mode. The verbose option is used to produce verbose output on the computer screen so the user can see real-time status of what the utility is doing.

root@exampleuser-X55CR:~# fuser -v .

                     USER        PID ACCESS COMMAND

/root:               root       3378 ..c.. vim

                     root       3398 ..c.. bash

                     root       3449 ..c.. bash

                     root      19370 ..c.. bash

root@exampleuser-X55CR:~# fuser -k 123/tcp

123/tcp:             11543

Use the ‘fuser -k’ command with the -i option to ask the user for confirmation before killing a process. The user can answer with y for yes or N for not confirming the killing.

root@exampleuser-X55CR:~# fuser -i -k 123/tcp

123/tcp:             12216

Kill process 12216 ? (y/N)

Use The -6 Option To Look For IPv6 Sockets.

The following command uses fuser tool in verbose mode and tries to find IPv6 sockets running on port 123.

root@exampleuser-X55CR:~# fuser -v -n tcp -6 123

Since there is no IPv6 socket running on port 123, the command does not produce any output. The -6 option can be replaced with the -4 option in order to search for IPv4 sockets running on a specific port.

Find The Process Accessing A File System

The -m option can be used with the fuser command to find processes accessing files on the filesystem of a file. This option requires a filename as input argument. The -m option is very useful, especially when used to discover processes accessing a file system with the intetion of identifying which process to kill.

The following command displays all processes accessing filesystem on which ‘example.txt’ resides. See carefully how the -m option is used with the fuser utility.

root@exampleuser-X55CR:~# fuser -v -m example.txt

                     USER        PID ACCESS COMMAND

/root/example.txt:   root     kernel mount /

                     root          1 Frce. init

                     root          2 .rc.. kthreadd

                     root          3 .rc.. ksoftirqd/0

                     root          6 .rc.. migration/0

                     root          7 .rc.. watchdog/0

                    [...]

                    exampleuser   23347 .r.e. gcalctool

                    exampleuser   24527 f..e. chrome

                    exampleuser   25388 f..e. chrome

                    exampleuser   25628 .r.e. evince

                    exampleuser   25634 .rce. evinced

                    exampleuser   25706 .rce. gm-notify

                    exampleuser   25769 .rce. at-spi-bus-laun

                    exampleuser   28191 .rce. mate-settings-d

                    exampleuser   28193 .rce. mate-screensave

                    exampleuser   29942 f..e. chrome

                    exampleuser   30044 .r.e. evince

                    exampleuser   32721 f..e. chrome

The fuser utility can also be used to send specific signals to a process. When used with the -k option, the fuser command sends the KILL signal to a process. There are many signals which can be sent to a specific running process; the -l option helps to find the list of signals that can be used with the fuser tool.

2)

Regular files:

Special files(This category is having 5 sub types in it.)

So in practical we have total 7 types(1+1+5) of files in Linux/Unix. And in Solaris we have 8 types. And you can see the file type indication at leftmost part of “ls -l” command.

Here are those files type.

Regular file(-)

Example listing of regular files :

                -rw-r--r-- 1 krishna krishna 20986522 2010-01-31 13:48 test.wmv

                -rw-r--r-- 1 krishna krishna 173448 2010-01-30 21:20 Transformers-Teaser-Wallpaper-310.jpg

                -r-xr-xr-x 1 root root 135168 2009-12-12 19:14 VIDEO_TS.VOB

                -rw-r--r-- 1 krishna krishna 2113536 2009-12-01 13:32 Aditya 365 – Janavule.mp3

                -rwxrwxrwx 1 root root 168 2010-02-14 14:12 xyz.sh

Directory file:

These type of files contains regular files/folders/special files stored on a physical device. And this type of files will be in blue in color with link greater than or equal 2.

How can we list them in my present working directory?

ls -l | grep ^d

Example listing of directories.

                drwxr-xr-x 2 surendra surendra 4096 2010-01-19 18:37 bin

                drwxr-xr-x 5 surendra surendra 4096 2010-02-15 18:46 Desktop

                drwxr-xr-x 2 surendra surendra 4096 2010-01-18 14:36 Documents

                drwxr-xr-x 2 surendra surendra 4096 2010-02-13 17:45 Downloads

Character Device File:

Provides a serial stream of input or output.Your terminals are classic example for this type of files.

How can we list character files in my present working directory?

ls -l | grep ^c

Example listing of character files(located in /dev)

                crw-rw-rw- 1 root tty 5, 0 2010-02-15 16:52 tty

                crw--w---- 1 root root 4, 0 2010-02-15 09:35 tty0

                crw------- 1 root root 4, 1 2010-02-15 09:35 tty1

Block Device File:

These files are hardware files most of them are present in /dev.

How to create them?

Ans : Use fdisk command or create virtual partition.

How can we list them in my present working directory?

ls -l | grep ^b

Example listing of Block files(for you to see these file, they are located in /dev).

                brw-rw---- 1 root disk 8, 1 2010-02-15 09:35 sda1

                brw-rw---- 1 root disk 8, 2 2010-02-15 09:35 sda2

brw-rw---- 1 root disk 8, 5 2010-02-15 09:35 sda5

Link files:

These are linked files to other files. They are either Directory/Regular File. The inode number for this file and its parent files are same. There are two types of link files available in Linux/Unix ie soft and hard link.

How to create them?

Ans : use ln command

How can we list linked files in my present working directory?

ls -l | grep ^

                Example listing of linked files

                lrwxrwxrwx 1 root root 24 2010-02-15 09:35 sndstat -> /proc/asound/oss/sndstat

                lrwxrwxrwx 1 root root 15 2010-02-15 09:35 stderr -> /proc/self/fd/2

                lrwxrwxrwx 1 root root 15 2010-02-15 09:35 stdin -> /proc/self/fd/0

                lrwxrwxrwx 1 root root 15 2010-02-15 09:35 stdout -> /proc/self/fd/1