Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can flockfile function be used for process

Hello every one I want to ask a question about flockfile function I was reading the description and came to know that it is used in threads. but I am doing forking which means that there will be different process not threads can I use flockfile with different process does it make any difference?

Thanks

like image 516
mainajaved Avatar asked Jun 22 '26 08:06

mainajaved


1 Answers

The flockfile function doesn't lock a file but the FILE data structure that a process uses to access a file. So this is about the representation in address space that a process has of the file, not necessarily about the file itself.

Even in a process if you have different FILEs open on the same file, you can write simultaneously to that file, even if you have locked each of the FILEs by means of flockfile.

For locking on the file itself have a look into flock and lockf but beware that the rules of their effects for access files through different threads of the same process are complicated.

like image 138
Jens Gustedt Avatar answered Jun 23 '26 22:06

Jens Gustedt