Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: Easy way to check if a file is open needed.

by Apt_Addiction (Novice)
on Apr 08, 2019 at 23:21 UTC ( [id://1232320]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Easy way to check if a file is open needed.
in thread Easy way to check if a file is open needed.

Thank you for that - really helpful. Yes, rsync just updates OneDrive from USB every 10 minutes or so. I'd got so wrapped up in testing this outside of OneDrive, that I hadn't thought of some of the things you mention. Looking at my OneDrive folder with lsof, OD has handles on files that aren't open anywhere else. So, your idea of renaming on the USB stick is best. Plus, she has quite a lot of data.

In terms of the time and things happening whilst the script runs, I have 1,200 files in my OD and this script found and renamed about 40 in 0.12 seconds, which seems OK. The time hog is lsof, which takes about 13 seconds to run. This seems ridiculous compared to linux, but apparently it's a mac thing.

Anyway, I'll create a temp file with the lsof output for the tree, then grep for the current filename before proceeding further. I understand grep will return 0 if it finds something.

  • Comment on Re^3: Easy way to check if a file is open needed.

Replies are listed 'Best First'.
Re^4: Easy way to check if a file is open needed.
by haukex (Archbishop) on Apr 09, 2019 at 08:17 UTC
    The time hog is lsof, which takes about 13 seconds to run. ... I understand grep will return 0 if it finds something.

    Note that it's possible to get lsof to only look in one directory tree with its +D option, although the manpage does note that it can consume a fair amount of memory, so you might want to keep an eye on that in testing.

    As for running external programs from Perl, I've written about that a fair amount, e.g. here - in this case, it seems like capturex from IPC::System::Simple might be a good replacement for qx// (backticks) - if the processes you're running are expected to return either 0 or 1 and that's not an error, then you can specify [0,1] as the first argument.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1232320]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-04-16 23:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found