Copy or move file into directory with parallel processing from another process

若如初见. 提交于 2021-01-29 09:07:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!