0

I have a small application consisting of two process.

Process A downloads a file. Process B uses the downloaded file.

When Process A downloads a file, it acquires file lock on it. Process B keep checking whether the file being downloaded is locked or not.

Once the downloading is completed, Process A releases file lock and the downloaded file is ready to use by Process B.

In Process B, I have dedicated thread which checks if the lock is released.

I want to avoid the loop of continuous file-lock check. Is there a way similar to select or poll system call using which Process B gets notifies about the file lock getting released ?

I have explored man pages of fcntl, flock but I did not find a way to do it.

Subbu
  • 2,063
  • 4
  • 29
  • 42
  • There is probably a way to do it using inotify. But I'm not completely familiar with inotify. You can also accomplish this with unix sockets: process A can open an AF_UNIX socket listening on abstract name. Any process B (even multiple) can connect to the socket if it knows the abstract name. When Process A is done, it can then close each acquired connection. Process B's file descriptor to the connected socket will become readable; when reading from the socket, an error will be returned indicating EOF. This would be your notification that process A is done. – inetknght Aug 21 '19 at 19:41
  • Can process B just block waiting to acquire the lock or does it have other things it needs to do in the meantime? (If the latter, maybe a thread dedicated to waiting for the lock?) – Shawn Aug 21 '19 at 22:07
  • The latter case. Edited the question. – Subbu Aug 22 '19 at 07:19

1 Answers1

0

It can be achieved using IPC: Inter-process communication Process A after finishing download tells to B it is finished.

Or you can use a network connection to inform B, but I would not suggest it.

Armin Neo
  • 78
  • 1
  • 5