Friday, October 28, 2011

du & bdf or df output differs

it is important to explain that the results for bdf and du -sk are going to be different. We cannot expect they will match.

Obviously there is a difference in how du and bdf behave.
This may occur if we touch open files.


"du" shows output in a positive view: it shows the number of currently allocated blocks and counts the blocks you've just deleted as free.
"bdf" has a more negative perspective: it shows the free disk space available.


The difference is here: if a still-active process has allocated blocks (such as
for a logfile that you've just deleted), "bdf" counts these as still occupied.
This won't change until the process closes the file ("deallocates the blocks")
as it usually happens when the process terminates.

If you still want to know which process holds space, this tool can be helpful. Important, this is an open source tool and it is not supported by Hewlett Packard.

Lsof Examples

Below you will find a set of examples using the lsof tool.

Examples
To list all open files, use:

# lsof
To list all open Internet, x.25 (HP-UX), and UNIX domain files, use:

# lsof -i -U
To list all open IPv4 network files in use by the process whose PID is 1234, use:

# lsof -i 4 -a -p 1234
Presuming the UNIX dialect supports IPv6, to list only open IPv6 network files, use:

# lsof -i 6
To list all processes using a particular network port, use:

# lsof -i :


In our case, this will be the best options:

When you need to dismount file systems on an HP-UX based server, you frequently find users 'on' a particular disk or logical volume resulting in 'device busy' errors. You can identify which processes have open files on a given device (instead of using intuition and frantic 'phone calls!) by using the fuser(1M) (10.20, 11.x) command.

fuser will list the process ids and usernames of processes that have a given file open and can even be used to automatically kill the identified processes. For example,

# fuser -u /mydir # All processes with
# /mydir open

# fuser -ku /dev/dsk/c0t6d0 # Kill all processes
# with files open on
# certain disk

Please see the man pages for additional options.

There is also a public domain tool called lsof that can be pulled from the internet and built on HP-UX. It shows all the files open by all the processes on the system, so use it in conjunction with grep if you are looking for a particular directory on a particular disk. For example,

# lsof | grep /mydisk

will show all processes with open files on the /mydisk file system.

To get lsof proceed as follows:

Anon ftp to vic.cc.purdue.edu
cd pub/tools/unix/lsof
Get lsof.tar.Z
uncompress lsof.tar.Z
tar -xvf lsof.tar
Read README.FIRST for instructions on how to build lsof.


If you cannot access to get the lsof script, it is attached anyway

The main situation here is: It is a know and expected situation that bdf and du will display different information.

No comments:

Post a Comment