ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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).
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()"?
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.