问题
I'm running two processes on AIX. Process one is generating several files, process two does backups from all files that are in a backup directory.
Process one will copy or move the files into the backup directory. Since process two is always running in the background there is the risk of it starting a backup of a file that is still in the process of being copied or moved and therefore incomplete. How can I avoid this problem?
回答1:
Process one should create files in another directory (on the same disk); and when a file is created, move it into the final directory. Move is an atomic operation, so process2 will only find complete files.
Edit: on AIX, /usr/bin/istat helps to make sure that two directories (or files) are on the same disk/partition/device, e.g.
for Dir in /home /home/zsiga /tmp;
do /usr/bin/istat "$Dir" | grep device;
done
Result:
Inode 2 on device 10/8 Directory
Inode 33 on device 10/8 Directory
Inode 2 on device 10/7 Directory
The first two are on the same disk/partition/device (10/8); the last one is on another device (10/7)
来源:https://stackoverflow.com/questions/59856442/copy-or-move-file-into-directory-with-parallel-processing-from-another-process