file locking problem (houxm.142 followup)

utzoo!decvax!duke!unc!smb utzoo!decvax!duke!unc!smb
Thu Jan 28 08:31:53 AEST 1982


The only way I know of to atomically create a unique file name is to
do so via link.  For your specific situation, try something like this:

	Generate your desired name, but use (say) # instead of '.'.

	Link to /usr/spool/at/LINKTARGET with your new name.

	The link will only succeed if the name doesn't exist already.

	The major causes of failure you have to worry about are the
	LINKTARGET file having been removed, and the name already there;
	in the former case create it; in the latter, try a new name.

	At this point, you've 'locked' your chosen name so that no one
	else will try to create it.  Now you can check to see if the
	real file name exists.

	Remove your lock file.

For this specific case, you may want to create a lock name that doesn't
include the final sequence number, and increment it as need to assure
uniqueness; in that case, what you're doing is locking the time of the
submission request.  For more general case, one can lock creation of any
file in that directory, so long as all programs doing so follow that
convention.  See the lock code in Berkeley mail for an example.

Here's a better one for you about 'at':  how do you prevent 'atrun' from
firing up too many processes at once?  For example, if the system has been
down for a few days, when it's rebooted all hell can break loose, and
processes *will* abort because the proc table is full.  Does anyone have
any sort of "batch monitor", which runs a limited number of requests at
a time?  If so, 'atrun' could "submit" jobs to it.



More information about the Comp.unix.wizards mailing list