Hi i made this code myself but there are some errors coming in this code i have attached screenshot of error.
this code is the Producer Consumer using semaphore in Bash shell Script
can you me it workable
#!/bin/sh
mutex=1full=0empty=3x=0
echo "A. ProducerB. ConsumerC. Exit"while(1)doecho "Enter your choice"read n
if [ $n -eq 1 ]thenif [ {$mutex -eq 1} -a {$empty -ne 0} ]thenproducer()elseecho "Buffer is full!!"fibreak;if [ $n -eq 2 ]then
if [ {$mutex -eq 1} -a {$full -ne 0} ]thenconsumer()elseecho "Buffer is empty!!"fibreak;fifi
done
wa(){s=$1return $((--s))
}signal(){s=$1return $((++s))}
producer(){mutex=$((wait()))full=$((signal()))empty=$((wat()))x++;echo "Producer produces the item $x"mutex=$((signal()))}
consumer(){mutex=$((wat()))full=$((wat()))empty=$((signal()))echo "Producer produces the item $x"x--;mutex=$((signal()))}
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here