LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 11-28-2006, 09:08 PM   #1
mldqj
LQ Newbie
 
Registered: Apr 2004
Location: CT, US
Distribution: Ubuntu
Posts: 24

Rep: Reputation: 15
Question How to track which process is accessing disk?


I'm running Ubuntu Edgy on my laptop. It has 2GB RAM, so swapping should rarely happen. Indeed, my swap partition is almost always unused. However, the HD light is almost constantly on, only turn off from time to time for very short durations. This is not a problem of the HD light, because the HD activity monitor also shows frequent activity.

Could anyone tell me how could I continuously track which process is access the disk?

Thanks.
 
Old 11-29-2006, 10:10 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,449
Blog Entries: 54

Rep: Reputation: 2892Reputation: 2892Reputation: 2892Reputation: 2892Reputation: 2892Reputation: 2892Reputation: 2892Reputation: 2892Reputation: 2892Reputation: 2892Reputation: 2892
First thing I would do is check which processes are the most active (top). Decide if they are necessary for basic system operation or if they are fluff, unnecessary ballast, eye candy and such. Check if they are standalone processes or services, then shut them down appropriately to see if it helps. Chances are these processes are related to DE's or WM's you run or maybe [di]notify/fam/dbus-related. If that still isn't enough you could try finding out which files are opened for reading (r), writing (w) or both (u) using lsof. If handling lsof is a bit too daunting you could save the code below as "/tmp/showprocs.sh". Running it as "sh /tmp/showprocs.sh" shows filenames and "sh /tmp/showprocs.sh --procs" shows process names to investigate for fluff vs function.

Code:
#!/bin/sh
case "$1" in --pids) SEL=2;; --procs) SEL=1;;
--files|*) SEL=9;; # how come I can't use NF?
esac; for tree in home proc dev usr var; do 
echo -n "/$tree: "; lsof -w -n -a -d0-10 -a +D \
/$tree|grep '[0-9][urw]'|awk --assign VAR="$SEL" \
'{print $VAR}'|sort|uniq|xargs; done; exit 0
The only "easy" application I know that could show finegrained and continuous disk access details per application is "atop": needs a kernel patch though. Other ways to track disk access could be tracking syscalls with TrackFS or LTT but the output avalanche is overkill. I'm probably overlooking some alternatives and I don't know any GUI equivelents, hopefully somebody will chip in.
 
Old 11-30-2006, 04:01 PM   #3
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,397

Rep: Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114
Also bear in mind that there are some activities that are scheduled via cron jobs, such as:
  • updatedb (which updates the slocate cache)
  • jobs (on some distros) which try to "prelink" executables
  • various and sundry cleanup and housekeeping tasks.
So, if you see a lot of disk activity, it's possible that it's simply a deferred job that hasn't had a chance to run. Or, it could be a cron job that is scheduled far too often. Does it keep doing it?

The system log, such as /var/log/messages, is a good place to find clues.
 
Old 12-03-2006, 12:41 AM   #4
mldqj
LQ Newbie
 
Registered: Apr 2004
Location: CT, US
Distribution: Ubuntu
Posts: 24

Original Poster
Rep: Reputation: 15
Thanks a lot for your help. I will try your advice later.
 
Old 12-20-2006, 07:09 AM   #5
PingFloyd
Member
 
Registered: Jun 2006
Posts: 94

Rep: Reputation: 16
I've noticed in Debian with Gnome that my HD light will blink on and off continuously, but there is practically no disk activity, and it can happen at times when there is no swap in use at all. I suspect that it's from famd. I've never bothered to investigate because I think it's perfectly normal in this particular case and doesn't use up any noticeable resources. So, if it seems like your situation is similar, you may try killing famd and see if it quits doing it for you (assuming you're using fam in the first place).

Now when I use other distros, or WMs the behavior, that I outline, is not present. So I'm pretty sure that it's some daemon, service, or process that my version of gnome is running in the background to serve some purpose. I just never really cared enough to try to narrow it down.
 
Old 01-05-2007, 01:00 AM   #6
PingFloyd
Member
 
Registered: Jun 2006
Posts: 94

Rep: Reputation: 16
I was never able to come up with a good way to track disk activity to which process (didn't have any luck in finding a program for this. Would be great if someone knows of a good program for this sort of thing.), but I did figure out which process is responsible for the HD LED blinking on consistently at 2 second intervals. It's 'hald' that's the cause of this.

What I can tell you about this is that it's not writing nor reading from any filesystem/hard drives when it's making the LED blink. I verified this through dstat. Also another thing that dstat revealed was that there is a write of exactly 24k every 5 second to the HD. I'm not 100%, but I'm pretty sure that this is nothing more than the journal of my ext3 filesystem(s) being updated.

The way in which I figured it out was just going through and killing off processes until the HD no longer did it's blinking (started with the more trivial and likely suspect of daemons and services). Far from scientific, and also a rather messy approach, but I finally got fed up and decided to take drastic measures like this. Killing off processes like this is probably not the best idea and likely to mess with the stability of the system (though it didn't in my case, but I've read that it's a good possibility). But if in your case, like mine, a reboot isn't a big deal, giving the system nice reboot afterwards, makes it a moot point whether this method is less than ideal.
 
1 members found this post helpful.
Old 02-12-2009, 07:20 AM   #7
pallinger
LQ Newbie
 
Registered: Feb 2009
Posts: 4

Rep: Reputation: 0
Quote:
If handling lsof is a bit too daunting you could save the code below as "/tmp/showprocs.sh". Running it as "sh /tmp/showprocs.sh" shows filenames and "sh /tmp/showprocs.sh --procs" shows process names to investigate for fluff vs function.
The script seems to work OK, but it is really slow if there are many files on the disk.

Quote:
The only "easy" application I know that could show finegrained and continuous disk access details per application is "atop": needs a kernel patch though.
Tried atop, and is really nice, as it can list processes by disk usage, and also shows the amount of bytes read/written. Moreover, it didn't need any kernel patch, at least with Ubuntu 8.10's stock kernel (2.6.27-11-generic x86_64).
 
  


Reply

Tags
harddisk, monitoring


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Keeping track of process CPU % dive Linux - Software 5 03-30-2006 02:45 PM
accessing disk inodes vishalbutte Programming 1 02-26-2006 09:21 PM
accessing task_struct of process shukla_chanchal Linux - General 1 11-04-2005 09:27 PM
accessing process address space linorg Programming 5 04-15-2004 01:13 PM
Accessing a second hard disk martinpanda Linux - General 9 03-11-2002 09:07 PM


All times are GMT -5. The time now is 04:57 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration