I Need help in C Script in unix enviroment - Unix

This is a discussion on I Need help in C Script in unix enviroment - Unix ; 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 ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: I Need help in C Script in unix enviroment

  1. I Need help in C Script in unix enviroment

    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

  2. Re: I Need help in C Script in unix enviroment

    QasimMalik.786@googlemail.com writes:

    > 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


    http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/

    --
    Måns Rullgård
    mans@mansr.com

  3. Re: I Need help in C Script in unix enviroment

    QasimMalik.786@googlemail.com 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
    >
    > I ma just trying to stop two clients accessing the same server file at
    > the same time


    Well, the shell script cannot accomplish that if the clients are
    running on different machines. If they are running on the same
    machine, then a shell script can prevent concurrent access.

    Personally, I think the easiest way to do that in a shell script
    is to use the mkdir command. I will give a Bourne shell example
    because I prefer not to use the C Shell:

    name=foo
    lockpath=/some/path/"$name".lock
    # attempt to acquire lock
    if mkdir "$lockpath"
    then
    echo "Got the lock named $name"
    do_something

    # release lock
    rmdir "$lockpath"
    else
    echo "Did NOT get the lock named $name"
    fi

    The advantage of using mkdir is that it will fail if the directory
    already exists. If the above code fails to get the lock, it will
    return immediately and not wait for the lock. If the machine
    crashes or the shell otherwise exits unexpectedly (such as if you
    kill it), the lock will not be cleaned up.

    - Logan

  4. Re: I Need help in C Script in unix enviroment

    On 2008-04-08, QasimMalik.786@googlemail.com 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


    I think you mean C-shell (csh) script.


    --


+ Reply to Thread