I am currently developing a forking server, which gives clients block-level (there is a defined blocksize and the boundary is checked) read- and write-access to a file.
I'm creating a fork for each client-connection. I know that file handles are copied, so both the parent and the child-process can access the file. I also know that seeking in one process will affect the other processes, too.
So here are my questions:
- How to lock seeking in the forks against the other forks? Mutex?
- Can a fork write to some blocks while the other forks are reading different block?
- If 2 is possible, how can I prevent forks from reading blocks that are currently being written?
Thank you for your help :)
lockf()
to lock the section of the file that you're writing to. This provides fine-grained locking. – Barmar