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 A9M0106 3.5" Floppy Disk Drive
$69.99
Apple IIe A2S2064 Vintage Personal Computer (825-0406-A)
$205.99
Apple Keyboard II Vintage Untested Vintage Apple II Keyboard
$29.95
vintage apple keyboard and mouse M2452
$28.00
Vintage 1987 Apple M0110A Keyboard - UNTESTED
$45.00
Apple Macintosh Classic Vintage Computer M0420 from 1991 For Parts Or Repair
$139.99
Vtg Macintosh Performa 6116CD Desktop COMPUTER UNTESTED MAC APPLE 1994 PowerPC
$149.99
Vintage Apple Disk IIc For Apple IIc Tested Working A2M4050
$50.88
Vintage Apple Logo Calculator. New in original box.
$29.00
Vintage Apple Macintosh Classic Model M0420 *Powers ON
$70.00