I've found this little NPM package which does a wonderful job of speeding up lsof for files: https://www.npmjs.com/package/lsof-mac-fast.
I created a wrapper script to use it:
node ~/tools/MacOs/lsof.js db.mv.db 1000
repeating using interval: 1000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 7336 jumar 256u REG 1,4 194465792 53854404
db.mv.db
This is my script:
// https://www.npmjs.com/package/lsof-mac-fast
var fastLsof = require('lsof-mac-fast');
var myArgs = process.argv.slice(2);
var fileToCheck = myArgs[0];
var repeatIntervalMs = myArgs[1];
// console.log('myArgs: ', myArgs);
function lsofFile(file) {
fastLsof.lsof([file], function(err, stdout, stderr) {process.stdout.write(stdout)});
}
if (repeatIntervalMs) {
// repeat until killed
// https://javascript.info/settimeout-setinterval
console.log('repeating using interval: ' + repeatIntervalMs);
var timerId = setInterval(() => lsofFile(fileToCheck), repeatIntervalMs);
} else {
// just one time
lsofFile(fileToCheck);
}
The repeat interval can be really low, e.g. 10 ms seems to work fine.