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 Apple Macintosh 512K / Mouse, Keyboard & Extras + Carry Case / Turns On
$260.00
Vintage Apple A2M2010 Monitor II, Green Phosper CRT
$99.99
Vintage Apple IIe Computer A2S2128 (825-1351-A)
$174.99
Vintage Apple Macintosh SE - Works Tested Working Keyboard And Mouse Included
$299.63
Vintage Apple Macintosh IIGS A2S6000 needs power supply recapped
$150.00
Vintage Apple Wrench Tool - Black
$8.99
Vintage Apple Macintosh M2740 Powerbook 150 with AC Adapter - For Parts
$39.95
VINTAGE APPLE MACINTOSH CENTRIS 650 DESKTOP COMPUTER M1205 Tested To Power Clean
$209.95
Vintage Apple Power Macintosh 7200/75 M3979 Boots to BIOS
$119.99
Vtg Apple IIGS Computer Only A2S6000
$215.00