LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-18-2006, 08:39 AM   #1
naveenk
LQ Newbie
 
Registered: Apr 2006
Posts: 4

Rep: Reputation: 0
Question on 'stat'


1) Can 'stat' be used to get information about directories?
Assuming that directory is a speacial kind of file on Linux, I think yes. Any comments?

2) I used 'stat' on a directory in my program. It doesnt seem to work very well when files are written very fast.
Example:-
here is an output:
Directory Last modified on 1145355520
/home/work/av2/file1.log Last modified on 1145355533
/home/work/av2/file2.log Last modified on 1145355534
/home/work/av2/file2.log Last modified on 1145355535

Here 1145355520 is the directory's "st_mtime" and 1145355533, 1145355534 and 1145355535 are "st_mtime" of the files in that directory.

Any comments/suggestions?

Thanks,
Nav.
 
Old 04-18-2006, 09:07 AM   #2
addy86
Member
 
Registered: Nov 2004
Location: Germany
Distribution: Debian Testing
Posts: 332

Rep: Reputation: 31
Quote:
Originally Posted by naveenk
1) Can 'stat' be used to get information about directories?
Assuming that directory is a speacial kind of file on Linux, I think yes. Any comments?
Why don't you just try? (And yes, it can be used on directories)

Quote:
Originally Posted by naveenk
2) I used 'stat' on a directory in my program. It doesnt seem to work very well when files are written very fast.
What do you mean by "files are written very fast"?

Quote:
Originally Posted by naveenk
Example:-
here is an output:
Directory Last modified on 1145355520
/home/work/av2/file1.log Last modified on 1145355533
/home/work/av2/file2.log Last modified on 1145355534
/home/work/av2/file2.log Last modified on 1145355535

Here 1145355520 is the directory's "st_mtime" and 1145355533, 1145355534 and 1145355535 are "st_mtime" of the files in that directory.
So what's wrong about that? Read the man page of stat(2).
 
Old 04-18-2006, 09:25 AM   #3
naveenk
LQ Newbie
 
Registered: Apr 2006
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by addy86
Why don't you just try? (And yes, it can be used on directories))
Tried.


Quote:
Originally Posted by addy86
What do you mean by "files are written very fast"?).
Means the files were written back to back at a high speed, 3 huge files in about 2-3 seconds.

Quote:
Originally Posted by addy86
So what's wrong about that? Read the man page of stat(2).
Directory last modified at 1145355520 (less than 1145355533, 1145355534 and 1145355535). Directory's last modified time is less than the last modified times of the files in the directory.
Shouldnt directory's timestamp be 1145355535?
If not, is there a way I can find if the contents of directory have changed without doing a "readdir()"?
 
Old 04-18-2006, 02:18 PM   #4
addy86
Member
 
Registered: Nov 2004
Location: Germany
Distribution: Debian Testing
Posts: 332

Rep: Reputation: 31
Quote:
Originally Posted by naveenk
Directory last modified at 1145355520 (less than 1145355533, 1145355534 and 1145355535). Directory's last modified time is less than the last modified times of the files in the directory.
Shouldnt directory's timestamp be 1145355535?
Quote:
Originally Posted by stat(2) man page
The field st_mtime is changed by file modifications, e.g. by mknod(2), truncate(2), utime(2) and write(2) (of more than zero bytes). Moreover, st_mtime of a directory is changed by the creation or deletion of files in that directory. The st_mtime field is not changed for changes in owner, group, hard link count, or mode.
Again, read the man page.
 
Old 04-18-2006, 11:41 PM   #5
naveenk
LQ Newbie
 
Registered: Apr 2006
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks for that info. I can take it from here.
 
Old 04-19-2006, 05:18 AM   #6
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
Quote:
Originally Posted by naveenk
is there a way I can find if the contents of directory have changed without doing a "readdir()"?
See fcntl(2) and seach for F_NOTIFY.

Note that for directories to be updated there must be a change in the directory inode contents. They are the file's name and its inode number. See "man 2 readdir". A cosmetic change to a file doesn't necessarily update the dir's inode. Also, check that no "noatime" option is in /etc/fstab entry of the filesystem that contains the directory. It may be a performance optimization that this metadata is saved later.
 
Old 04-21-2006, 10:23 AM   #7
naveenk
LQ Newbie
 
Registered: Apr 2006
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks. This works better
 
  


Reply



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
Use of stat() in C rblampain Programming 3 06-02-2005 06:41 AM
cannot stat DAChristen29 Linux - Software 1 05-23-2005 05:54 PM
cannot stat scottsteibel Linux - Newbie 2 12-11-2004 03:51 PM
Linux stat to Windows Stat sridurai Programming 3 09-24-2004 04:07 PM
Load average and system stat question WeNdeL Linux - General 3 04-28-2004 11:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:50 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration