You can use 'lsof' to do it and probably that's the same scheme which is used by Puppy.
But you have to know that it is still not 100% safe. Because a file system allows concurrent access, at one moment your check says the file is not opened, but as soon as you start the copying and deleting the copy on the ramdisk, another process starts opening it for modification or deletion. You can imagine it will result in various confusion to your file system.
VINTAGE "LATE-VERSION" APPLE IIC KEYCAPS: $1.13 OR $3.40 EACH + S/H
$3.40
Vintage Apple Macintosh PowerBook 165c and power supply
$95.00
Vintage IBM Thinkpad R52 Laptop Windows XP pro 15" 1.86 GHz 512MB 60GB Retro
$140.00
Amiga "Get Boinged" Vintage Plastic Travel Mug
$26.95
Assorted Vintage Processors INTEL AND AMD
$25.00
Vintage SRW Floppy Disk Storage Tower 5 Cases for 3.5in Floppy Disks & Crafting
$39.00
Vintage PC Software Lot CD ROM Office Home Programming Tools
$30.00
Vintage Radio Shack TRS-80 Pocket Computer W/Case UNTESTED. For Parts Only.
$40.00
Vintage IBM 42H1292 1997 Mechanical Keyboard *Missing/Replaced Keycap,Untested*
$119.99
MACINTOSH SE/30 VINTAGE MAC APPLE COMPUTER M5119 Tested Working BUT SOLD AS-IS.
$798.88