|
From: QasimMalik.786 on 8 Apr 2008 18:08 I want to Implement a Synchronisation primitive such as a semaphore that will ensure mutual exclusion, prevent deadlock when concurrent request are made from the clients. C scripts in the UNIX environment in the below script I ma just trying to stop two clients accessing the same server file at the same time Any help would greatly help I am willing to do any thing in the return even pay
From: Icarus Sparry on 8 Apr 2008 19:02 On Tue, 08 Apr 2008 15:11:27 -0700, QasimMalik.786 wrote: > I want to Implement a Synchronisation primitive such as a semaphore that > will ensure mutual exclusion, prevent deadlock when concurrent request > are made from the clients. C scripts in the UNIX environment in the > below script Standard advice is not to use 'csh' for writing scripts. If there was a (cheap) primitive that could ensure mutual exclusion and at the same time prevent deadlock, everyone would use it! Typically primatives will ensure mutual exclusion and careful use of them prevents deadlock. The common way to ensure mutual exclusion from the shell is to use file system operations that are atomic. You need to be slightly careful in your choice of operation as some filesystems (and one usually points the finger at NFS here) do not behave in the manner that one expects. Common operations often used are "mkdir", "mv (rename)" "ln (link)" "ln -s (symlink)". With these you can produce functions to get a lock and release it, e.g. getlock(){ echo $$ > /tmp/lock.$$ while ! ln /tmp/lock.$$ /tmp/reallock do sleep 1 done } unlock(){ rm /tmp/reallock /tmp/lock.$$ } Slightly more robust solutions wil check that the echo succeeded (e.g. / tmp is not full) etc. > I ma just trying to stop two clients accessing the same server file at > the same time On my linux system I have a program "dotlockfile" which claims to do everything correctly.
From: www.isp2dial.com on 8 Apr 2008 21:54 On 08 Apr 2008 23:02:52 GMT, Icarus Sparry <usenet(a)icarus.freeuk.com> wrote: >On Tue, 08 Apr 2008 15:11:27 -0700, QasimMalik.786 wrote: > >> I want to Implement a Synchronisation primitive such as a semaphore that >> will ensure mutual exclusion, prevent deadlock when concurrent request >> are made from the clients. C scripts in the UNIX environment in the >> below script >On my linux system I have a program "dotlockfile" which claims to do >everything correctly. I don't have "dotlockfile," but I see "lockfile" from the procmail package. The man page says it's a conditional semaphore-file creator. -- Internet service http://www.isp2dial.com/
|
Pages: 1 Prev: Help with Sed command Next: I Need help in C Script in unix enviroment |