Question: Can some change this C language code to Bash/Shell Script Unix Linux or I'm also sharing my changed code can you fix it #include #include

Can some change this C language code to Bash/Shell Script Unix Linux or I'm also sharing my changed code can you fix it

#include #include

int mutex=1,full=0,empty=3,x=0;

int main() { int n; void producer(); void consumer(); int wait(int); int signal(int); printf(" 1.Producer 2.Consumer 3.Exit"); while(1) { printf(" Enter your choice:"); scanf("%d",&n); switch(n) { case 1: if((mutex==1)&&(empty!=0)) producer(); else printf("Buffer is full!!"); break; case 2: if((mutex==1)&&(full!=0)) consumer(); else printf("Buffer is empty!!"); break; case 3: exit(0); break; } } return 0; } int wait(int s) { return (--s); } int signal(int s) { return(++s); } void producer() { mutex=wait(mutex); full=signal(full); empty=wait(empty); x++; printf(" Producer produces the item %d",x); mutex=signal(mutex); } void consumer() { mutex=wait(mutex); full=wait(full); empty=signal(empty); printf(" Consumer consumes item %d",x); x--; mutex=signal(mutex); }

My Changed Code full of errors:

#!/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(mutex); full=signal(full); empty=wat(empty); x++; echo "Producer produces the item $x" mutex=signal(mutex); }

consumer() { mutex=wat(mutex); full=wat(full); empty=signal(empty); echo "Producer produces the item $x" x--; mutex=signal(mutex); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!