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.
IBM CS821 20-Core 2.827GHz 128Gb 1.92Tb SSD 1U Linux Server - 8005-12N Power 8
$479.96
Red Hat Enterprise Linux 5 Server - New and Sealed
$19.99
Red Hat Enterprise Linux 5 Server RHF032US-R1 NEW Sealed
$59.95
Asus ESC4000 G3 Barebones 0GB HDD Linux
$200.00
2 x HP ProLiant BL460c (447707-B21) Blade Servers No RAM No HDD
$30.00
IBM E850 Power8 2x 12C 3.02GHz 512Gb 1.8Tb SAS 10GbE 16Gb Linux Server 8408-E8E
$799.96
1U BareMetal pfsense opnsense Router Firewall DNS Server 6x 10GB Ethernet Ports
$149.00
IBM Power 9 S922 8-Core 3.4-3.9Ghz 128Gb DDR4 2U Linux Server - 9009-22a
$3439.96
IBM System X 3250 M5 Single Xeon Quad Core E3-1220 v3 @3.1GHz,8GB RAM,Linux SUSE
$199.87
POGO Linux WEBWARE 1150 Rack-Mount Server Pentium 4 2.8GHz 512MB - No Drives
$179.99