[net.lang.c] shared data sets on UNIX in C

atb@ncsu.UUCP (Andrew T Brown) (06/11/84)

I am looking for information about shared data sets on the UNIX system.
We have a problem on a C program we are working on.  This problem is 
a bit confusing so bear with this explanation:

	This program may be executed by many people concurently.
	It uses a data base common to all of the users. This data
	base resides in a file so that it will be available upon
	the next execution of the program.

	First, the program reads a list of items into a linked list.
	Second, the user adds or deletes names to the linked list.
	Finally, the changes are written back to the same file.
	The problem occurs when two people are executing the program at
	the same time.  The users both read the file into their environment.
	If the first user stores his changes and then the second user stores
	his changes then the first user's changes are overwritten. 
	(wordy isn't it . . . never was good at tech writing)

	Question:  How do we keep this from happening other than reading
		   and writing the FILE on every access of the list.
		   (We don't want to be bogged down with alot of I/O)

		   Is it possible to set up a shared data set between the
		   two (or more) processes?  (If I can do that then I
		   could handle the rest of the problem)
		   How does Unix allocate its resources to different process?

Any help would be greatly welcomed. Please reply via mail.

decvax!mcnc!atb@ncsu

gwyn@BRL-VLD.ARPA (06/17/84)

From:      Doug Gwyn (VLD/VMB) <gwyn@BRL-VLD.ARPA>

Your shared data set problem can be solved by a facility known as
"record locking".  This is not in any standard UNIX kernel, but code
to implement it has been published (most recently in the reviewer's
guide for the /usr/group system interface standard).  In the absence of
such a facility, consider "file locking", which can be accomplished on
any UNIX system (if there is not a built-in facility for this, it can
be kludged up using links).  The last resort is to make a separate data
set manager process and route all data set access through this manager
(this works acceptably if you have FIFOs or perhaps sockets).