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.
Cisco GLC-FE-100FX-RGD 100BASE-FX SFP Transceiver Module
$17.99
Cisco GLC-FE-100LX 100BASE-LX SFP Transceiver Module
$15.59
Cisco Meraki MA-SFP-1GB-SX 1000BASE-SX SFP Transceiver Module
$24.99
Cisco w/ Green Hologram SFP-25G-SR-S 25G SFP28 SR 850nm 100m LC MMF
$68.99
Genuine Cisco SFP-10G-SR V03 10GBASE-SR SFP+ Transceiver Module 10-2415-03
$8.00
SFP-10G-SR Original Cisco 10GBASE-SR SFP+ V02 Multi mode Transceiver 10-2415-02
$5.00
Brand New Cisco GLC-LH-SMD 1000BASE-LX/LH SFP Module 1310nm 10km SMF LC
$13.89
Genuine Cisco GLC-TE 30-1475-01 V01 1000BASE-T SFP COPPER RJ-45 100M TRANSCEIVER
$11.90
10 PCS Cisco GLC-LH-SMD 10-2625-01 1310nm SFP Transceiver Module
$85.00
LOT OF 20 Genuine Cisco SFP-10G-SR V03 10GBASE-SR SFP+ Transceiver Module
$89.00