Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

making use of a semaphore

Status
Not open for further replies.

FDavid

Technical User
Jul 24, 2003
2
GB
can any one tell me how to run a semaphore. i understand roughly how they work code wise, but i'm not sure how to make use of them. i have two client programs in csh that perform tasks on a server file (flat file) how the i get the semaphore to lock the file when one has accessed it and how to use it to prevent deadlock. Is it done by accessing the file through the semaphore?
 
I categorize semaphores by content and visibility. There's also location. Is the lock user-specific or group specific?
If the lock is user specific, then the semaphore needs to reside in the user's home directory, or else the username needs to be part of the semaphore filename.

If it's group or project related, the I put the semaphore in the local directory where the job is likely to be invoked. My group isn't very sophisticated so I've ceased making the semaphores hidden. (E.g., I use somehthing like jobname.semaphore instead of .jobname_semaphore)

Technically, semaphores are empty and it's merely their presence that acts as switch to the script or program. I've found that sometimes it's useful to store variables and values in them from time to time.

In Bourne shell scripts (.sh) in testing for the semaphore, the -s in the expression will not detect a completely empty file. Better to use -f instead.

if [ -f jobname.semaphore ] ; then
echo "File/program locked. Try again later."
exit 0
fi

Visit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top