LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-03-2008, 12:33 PM   #1
hockeyman_102
Member
 
Registered: Apr 2006
Location: Washington
Distribution: Suse, CentOS, Ubuntu
Posts: 124

Rep: Reputation: 15
perl time() vs. filestate question.


Some code written before my time has recently broken and I've traced it down to time vs. filetime. The statement is below:

Code:
open(FOUT, ">$testdir") || die("Could not open $testdir");
print FOUT ".";
close(FOUT);

@filestat = stat $testdir;
$filetime = $time - $filestat[9];
$min = $filetime / 60;
print "Temp Filetime diff: ".$filetime." (".$min.")\n";
The problem is that $min is always around 9.15?? It doesn't take 9 min to run...
Code:
bsd2$ time ./test.pl
Temp Filetime diff: 549 (9.15)

real    0m0.054s
user    0m0.014s
sys     0m0.014s
Also the folder is an NFS mount, and I HAVE checked the date on the machine it's mounted to - and it's only seconds off.

Any ideas would be GREATLY appreciated!! Thanks in advanced.
 
Old 09-03-2008, 01:57 PM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Where does $time come from?
 
Old 09-03-2008, 02:23 PM   #3
hockeyman_102
Member
 
Registered: Apr 2006
Location: Washington
Distribution: Suse, CentOS, Ubuntu
Posts: 124

Original Poster
Rep: Reputation: 15
sorry.
Code:
$time = time();
 
Old 09-03-2008, 02:26 PM   #4
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Ah... I thought so, but wanted to make sure there wasn't anything weird going on there. I assume $testdir is actually a file and not a directory, in order to open and write to it. I wonder if NFS is doing some sort of caching of stat() and getting old data. Have you tested the script against a local file?
 
Old 09-03-2008, 04:00 PM   #5
hockeyman_102
Member
 
Registered: Apr 2006
Location: Washington
Distribution: Suse, CentOS, Ubuntu
Posts: 124

Original Poster
Rep: Reputation: 15
Good idea...

So I moved it locally (/root) and ran it and got a "diff: 0 (0)" - good news, but how can i reset the nfs cache w/o restarting a server? This is BSD if it matters.

Thanks!

Last edited by hockeyman_102; 09-03-2008 at 04:07 PM.
 
Old 09-03-2008, 04:51 PM   #6
hockeyman_102
Member
 
Registered: Apr 2006
Location: Washington
Distribution: Suse, CentOS, Ubuntu
Posts: 124

Original Poster
Rep: Reputation: 15
ps: I logged into the nfs server, and 'date' is right on within seconds...
 
Old 09-03-2008, 08:48 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,802

Rep: Reputation: 2540Reputation: 2540Reputation: 2540Reputation: 2540Reputation: 2540Reputation: 2540Reputation: 2540Reputation: 2540Reputation: 2540Reputation: 2540Reputation: 2540
Dumb qn: have you checked that the clocks on the NFS server and your 'client' box are in fact synced (to within a few seconds)?
The filestat value is being 'set' by the NFS server, as it 'owns' the disk/OS that the file exists under, aka the env.
 
Old 09-04-2008, 12:48 PM   #8
hockeyman_102
Member
 
Registered: Apr 2006
Location: Washington
Distribution: Suse, CentOS, Ubuntu
Posts: 124

Original Poster
Rep: Reputation: 15
when I run 'date' on both machines the time is within seconds of each other. Is there some other type of 'date' that could be effecting this?
 
Old 09-04-2008, 12:58 PM   #9
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Examine the attribute caching section of: http://www.unixcoding.org/NFSCoding

I strongly suspect this is a caching issue.
 
  


Reply

Tags
perl, time


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
Perl Question for perl hackers. linuxlover1 Programming 1 06-27-2006 06:56 PM
reinstall perl question.. (urpme perl) rjcrews Mandriva 2 01-28-2006 06:19 PM
mysql query time into perl cgi tommasopiff Programming 0 03-25-2005 04:25 PM
Perl - Time Travel? SiLiCoN Programming 4 12-17-2004 05:04 AM
Hiding code in PERL, perl gui question randomx Programming 1 06-26-2004 03:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:45 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