文件夹锁定和过程同步

发布于 2025-02-01 12:41:42 字数 284 浏览 2 评论 0原文

我有两个过程(我们称它们为P1& p2)。 P1从文件夹中读取数据,P2更新该文件夹。当P2想要更新该文件夹(使用 rsync )时,必须等待P1是否正在阅读,反之亦然(P1必须等待P2是否正在更新该文件夹)。我试图使用静音/信号量等...但是我有一些问题,例如:如果P2在更新时崩溃,那么P1将继续等待Mutex/Semaphore发布。 是否有一种方法或构建的Linux可以使同步这样的同步:文件夹本身允许P1读取数据,而P2等待更新,如果P1崩溃,则没有等待的过程,因此P2可以更新? 还是您还有其他建议?

I have 2 processes (let's call them P1 & P2). P1 reads data from a folder and P2 updates that folder. When P2 wants to update that folder (using rsync), it has to wait if P1 is reading and vice versa (P1 has to wait if P2 is updating the folder). I tried to use mutexes/semaphores and others... but I have a few problems like: if P2 crash while updating, then P1 will keep waiting for mutex/semaphore release.
Is there a way or something build-in linux to make the synchronization like this: the folder itself allow P1 to read data, while P2 wait to update, and if P1 crash, then there's no process to wait for, so P2 can update?
Or you have other suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文