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=1 full=0 empty=3 x=0 echo "A. Producer B. Consumer C. Exit" while(1) do echo "Enter your choice" read n if [ $n -eq 1 ] then if [ {$mutex -eq 1} -a {$empty -ne 0} ] then producer() else echo "Buffer is full!!" fi break; if [ $n -eq 2 ] then if [ {$mutex -eq 1} -a {$full -ne 0} ] then consumer() else echo "Buffer is empty!!" fi break; fi fi done wa() { s=$1 return $((--s)) } signal() { s=$1 return $((++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())) }
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=1
full=0
empty=3
x=0
echo "A. Producer
B. Consumer
C. Exit"
while(1)
do
echo "Enter your choice"
read n
if [ $n -eq 1 ]
then
if [ {$mutex -eq 1} -a {$empty -ne 0} ]
then
producer()
else
echo "Buffer is full!!"
fi
break;
if [ $n -eq 2 ]
then
if [ {$mutex -eq 1} -a {$full -ne 0} ]
then
consumer()
else
echo "Buffer is empty!!"
fi
break;
fi
fi
done
wa()
{
s=$1
return $((--s))
}
signal()
{
s=$1
return $((++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()))
}
Step by step
Solved in 2 steps with 4 images