Re: How to find disk is in use?
- From: "David Schwartz" <davids@xxxxxxxxxxxxx>
- Date: 17 Oct 2006 19:24:46 -0700
adar wrote:
I am looking for a system call or something similar to check whether
given disk (node /dev/sda, /dev/sdh etc) is in use. This will be
implemented in C language on Linux, so please suggest from C language
point.
For example,
#check-disk-in-use /dev/sda
Yes, in use
#check-disk-in-use /dev/sdh
Not in use
Please understand that user can provide only block device node, not a
partition.
Disk is use means:
A running application is born from this disk
A running application is reading/writing to this disk
Disk or disk partition is mounted and used
RAW read/write is happening on this disk
etc.
Basically if disk is used by any means from system/Linux this program
should be able to identifiy it. My system has 16 disks, and Linux OS
would be born from one of this disk and remaining 15 disk may be used
for data storage and for some application program.
The command 'fuser -m <device>' will do this. If you get no output at
all, then the block device is not in use. If you get output, it is a
list of process IDs of processes using that device along with a code
for how they are using it if appropriate.
If you need to write your own code to do it, obtain the source code to
'fuser' and borrow what you need.
DS
.
- Follow-Ups:
- Re: How to find disk is in use?
- From: adar
- Re: How to find disk is in use?
- References:
- How to find disk is in use?
- From: adar
- How to find disk is in use?
- Prev by Date: How to find disk is in use?
- Next by Date: Re: question about linux CPU scheduling
- Previous by thread: How to find disk is in use?
- Next by thread: Re: How to find disk is in use?
- Index(es):
Relevant Pages
|