making use of a Semaphore

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?

Can you give an example of what you are talking about? The only semaphores that I know of are not accessable via csh.

Not knowing if your system have it. On my system I have a lockfile(1) program that implements semaphore for file locking, and it's for use in shell scripts.

This is more convenient than hacking your own method to implement the semaphore mechanism again.

i have a c menu script in csh that has the following functions: sort, grep, append. two of these are my client files. i have a data server file that these client files can perform their functions on. The semaphore must ensure mutual exclusion when both clients attempt to perform a function at the same time.

I happend to need a semaphore implementation in bash. something in csh should be similar. It uses signals and a tight critical section to simulate a semaphore (no polling).
Bash semaphore - Wiki

(i dont know if this will work on SMP machines though).
hope it helps

I managed to grab a semaphore implementation in ksh originally written by Ed Schaefer and John Spurgeon for UNIX Review in 2004. The original has disappeared but commentary and download instructions on my slightly fixed copy is available at:

http://www.cs.umb.edu/~rouilj/#Semaphore

It support multiple per user counting semaphore groups and a queuing mechanism to help prevent starvation.

The only current issue with it is that it works only on a single machine,
I have a plan on how to make it work across multiple machines, but that's not implemented yet.

-- rouilj