Problem in access time

S

sanjeeb

Hey
I have written a code to know the files read by a tool during
execution so that i can anlyze that files only. The problem is that it
is not showing any file that was read. i checked manually(by renaming
the files and executing the tool, if it gives error means its read the
file) to know the files read during the execution of the tool(rom
tool).

Logic

1. Record the time at the start of the script.
2. Record the time at the end of the tool execution(rom).
3. Check the access time in the specified directory of each file using
stat.
4. If the access time is greater then the $time_start and less then the
$time_end
print the file name.

OS: WinXp, Active perl
Drive used: Virtual.


The tool is calling a batch file and the batch file in turn calls some
perl tool. The perl tool opens some file inside the script which are
present in the specified directory, but unfortunately it didnt show
that files.

1. Is there portability issue in the stat?
2. Is there any unkown bug in the code?
3. If a scipt open a file using "open", will it update the access time?
4. Is there any problem in the resolution, i think access time gives in
seconds(thats why i added a sleep after the "system" command).







Snippet of the code

###########################
use strict;
my $time_start = time;


system("rom -v coral -inst armv5 -build urel -s");
sleep(2);

my $time_end = time;


print "Time taken ($time_start - $time_end)\n";

use File::Find;

my @directories_to_search =
('C:\\J_Laptop\\J_Symbian\\eshell-min\\src\\cedar\\generic\\base\\e32\\rombuild');
print "\n";

find(\&wanted, @directories_to_search);




sub wanted {

if (-f $File::Find::name) {

my $st = stat($File::Find::name);
my $accessTime = $st->atime;
if ($accessTime >= $time_start && $accessTime <= $time_end) {

print "Files accessed #### $File::Find::name \n";
}

}

}


####################


With regards
Sanjeeb
 
D

David Squire

sanjeeb said:
if ($accessTime >= $time_start && $accessTime <= $time_end) {

I reckon you're going to need extra parentheses there. "&&" binds very
tightly. If I am right, your expression is equivalent to:

if ($accessTime >= ($time_start && $accessTime) <= $time_end)

.... probably not what you want.

DS
 
S

sanjeeb

Ya i made a mistake. Thanks for the correction.
################
Changed to
if (($accessTime >= $time_start) && ($accessTime <= $time_end)) {
print "OK\n";
print "##########$File::Find::name \n";
}
####################

Thanks
Sanjeeb
 
A

Ala Qumsieh

David said:
I reckon you're going to need extra parentheses there. "&&" binds very
tightly. If I am right, your expression is equivalent to:

if ($accessTime >= ($time_start && $accessTime) <= $time_end)

... probably not what you want.

That is incorrect. >= and <= bind more tightly than &&. Check perlop for
the precedence order.

--Ala
 
S

sanjeeb

Hey i changed the script and now running but the results are not
consistent. What ever i am debugging that.
Can any one please let me clarify my doubts.

In which circumstances the access time changes
1. If script open a file in read/write/append mode.
2. If script uses system command to execut a file . (Doubt is here)
3. Suppose a module is imported. Is the access time changes when it is
imported(*.pm files)(Doubt is here).

Is there any other method to know the files in a specified directory
which are executed/read/written during the execution of a tool(.exe not
..pl).

With Regards
Sanjeeb
 
L

Lukas Mai

David Squire said:
I reckon you're going to need extra parentheses there. "&&" binds very
tightly. If I am right, your expression is equivalent to:

No, it doesn't.
if ($accessTime >= ($time_start && $accessTime) <= $time_end)

... probably not what you want.

perl -e '$x >= ($foo && $bar) <= $z'
syntax error at -e line 1, near ") <="
Execution of -e aborted due to compilation errors.

That's not even valid Perl.

HTH, Lukas
 
B

Brian McCauley

sanjeeb said:
In which circumstances the access time changes
1. If script open a file in read/write/append mode.
2. If script uses system command to execut a file . (Doubt is here)
3. Suppose a module is imported. Is the access time changes when it is
imported(*.pm files)(Doubt is here).

I cannot see why you think this has anything to do with Perl.

Have you considered a couple of simple experiments? Using XP and NTFS5
I've just found that requiring a *.pm will change the access time.
Other experiments are left as an exercise for the reader.
Is there any other method to know the files in a specified directory
which are executed/read/written during the execution of a tool(.exe not
.pl).

Yes there are tools for most operatng systems that can intercept and
log various interactions between user space processes and the OS
kernel.

For example on Windows you can get good tools from
www.sysinternals.com.

Did I mention, I can't see why you could have thought this had anything
to do with Perl.
 
D

David Squire

Lukas said:
No, it doesn't.


perl -e '$x >= ($foo && $bar) <= $z'
syntax error at -e line 1, near ") <="
Execution of -e aborted due to compilation errors.

That's not even valid Perl.

I didn't really intend it to be. I guess I should have written

($x >= ($foo && $bar)) <= $z

.... but since I was wrong about the operator precedence it does not matter.

Hmmm. For decades I have been wrong about that in C and Perl. I guess
extra parentheses never hurt :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,800
Messages
2,569,657
Members
45,417
Latest member
BonitaNile
Top