Operating System - HP-UX
1833748 Members
2773 Online
110063 Solutions
New Discussion

Is there an enqueue-type command in HPUX?

 
SOLVED
Go to solution
Scott Lindstrom_2
Regular Advisor

Is there an enqueue-type command in HPUX?

I have some code in a middle of a script that I want to make sure does not get interrupted by another instance of the script running.

Back in my old IBM mainframe days, we use the ENQ and DEQ commands. You would ENQ(ueue) on whatever you decided was the 'lock', all programs would then use this 'lock', and therefore the code between the ENQ and the DEQ would run single threaded. I wonder if there is a similar concept for shell scripts.

I need to do something like:

bunch of commands...
ENQ "some-string"
bunch of commands...
DEQ "some-string"
rest of the commands...

There could be multiple instances of the script running, but the system would insure the code between the ENQ and DEQ would be single-theaded.

Does anything like this exist without using a disk file as a lock?

Scott
3 REPLIES 3
James R. Ferguson
Acclaimed Contributor

Re: Is there an enqueue-type command in HPUX?

Hi Scott:

For a shell script, you are going to have to use a disk file as your semaphore and hope you "win-the-race".

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Is there an enqueue-type command in HPUX?

There is no out-of-the-box equivalent. The "standard" UNIX method is a lock file (or even better a lock directory) and generally all that is required is for the script to test for the existence of this file and exit immediately if found OR create the lock file, start executing, and remove the file upon exit. It wouldn't be too difficult to craft an equivalent so that
ENQ "foo" would create a file "foo" in some standard directory or would loop until "foo" no longer existed and then create a the file. Conversely DEQ "foo" would remove the file.
If it ain't broke, I can fix that.
OldSchool
Honored Contributor

Re: Is there an enqueue-type command in HPUX?

so you could...in theory...write a couple of shell functions that do the "grunt work" of coping w/ the lock file, and stick them in a file. all scripts could "source" or "." the file defining the functions.

then you could code as per your example....