I Need help in C Script in unix enviroment

I Need help in C Script in unix enviroment

am 09.04.2008 00:11:27 von QasimMalik.786

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


echo " select any option to execute:"
echo " c or C: To connect Client to Server"
echo " r or R: To make a read request"
echo " s or S: I want to sort data"
echo " g or G: Look for a certain word in a file"
echo " e or E: quit"
echo -n "Enter your option and press :"
set selection = `head -1`

switch ("$selection")
case [cC]:
echo -n "enter server name"
set servername = `head -1`
find $servername
breaksw

case [rR]:

cp
echo -n "enter server file to read content"
set serverfile = `head -1`
breaksw

case [sS]:

sort
echo -n "enter server file to sort"
set serverfile1 = `head -1`
breaksw

case [qQ]:

exit 0

breaksw

default:

case [qQ]:

exit 0

breaksw

default:
echo " wrong option."
exit 1
breaksw
endsw
exit 0


Any help would greatly help

I am willing to do any thing in the return even pay

Re: I Need help in C Script in unix enviroment

am 09.04.2008 01:02:52 von Icarus Sparry

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.

Re: I Need help in C Script in unix enviroment

am 09.04.2008 03:54:37 von jak

On 08 Apr 2008 23:02:52 GMT, Icarus Sparry
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/