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...


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()))
}


Q ×<br>> bash main.sh<br>A. Producer<br>B. Consumer<br>C. Exit<br>48 -<br>{<br>s=$1<br>return $((++s))<br>}<br>49<br>50<br>51<br>52<br>main.sh: line 21: syntax error near unexpected token `else'<br>main.sh: line 21:<br>else'<br>producer()<br>{<br>mutex=$((wait()))<br>full=$((signal()))<br>empty=$ ( (wat()))<br>53<br>exit status 2<br>54 -<br>55<br>56<br>57<br>58<br>X++;<br>59<br>echo

Extracted text: Q × > bash main.sh A. Producer B. Consumer C. Exit 48 - { s=$1 return $((++s)) } 49 50 51 52 main.sh: line 21: syntax error near unexpected token `else' main.sh: line 21: else' producer() { mutex=$((wait())) full=$((signal())) empty=$ ( (wat())) 53 exit status 2 54 - 55 56 57 58 X++; 59 echo "Producer produces the item $x" mutex=$ ((signal())) 60 61 62 63 consumer() 64 - mutex=$( (wat())) full=$ ((wat())) empty=$((signal())) 65 66 67
Jun 10, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here