Bash Lockfile Command

Hi,

I am new to this forum, could any one please help me to understand the LOCKFILE command with an example and what exactly it is used for and how it is used.

Thanks
Reshu289

Not bash, part of the system: Man Page for lockfile (all Section 1) - The UNIX and Linux Forums

Thanks for the reply, if you can give a small example how to use it ,that will help me a lot.

I never, but it is for IPC, for multiple processes, one probably a script, to communicate for a rendezvous -- If you get there first, wait for me. Suppose you have 5 tables in files that others can modify, that you need to read while they are stable to get an output or modify a table, like an input staging table and a target table, with supporting tables. If everyone knows they need a lockfile for any table they read or modify, it can ensure only one process uses the tables, and if modifying them, returns them to a useful state, perhaps sorted with deletions removed, before letting others use them.

It's an ugly flow! A more modern approach is to send get or modify messages in a queue to a server for each table. That server can fulfill requests for that table with no lost time.

You can find online tutorials on UNIX IPC, which is based in shared memory, which can be configured into semaphors or queues.

Many of these mechanisms can be recreated without UNIX IPC or root support using mmap(). All programs can mmap() the same file(s) and communicate through the mapped file space as shared memory, with the bonus that you can inspect the file during or after the run.

Not that lockfile does not have any halfway measures, like read only, allow read, etc. When you make the lockfile, the associated resource is yours alone until you release it by removing the lockfile. If 70 processes just want to read it, they must stand in line when they could all read at once.

Thanks a lot for the update , this really helps.