Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I want someone to convert C code to Bash Shell Script down there in description code is given Output Write a bash script to simulate

I want someone to convert C code to Bash Shell Script down there in description code is given Output

Write a bash script to simulate producer-consumer problem using semaphores.

#include

void main()

{

int buffer[10], bufsize, in, out, produce, consume, choice=0; in = 0;

out = 0; bufsize = 10;

while(choice !=3)

{

printf( 1. Produce \t 2. Consume \t3. Exit);

printf( Enter your choice: );

scanf(%d, &choice);

switch(choice) {

case 1: if((in+1)%bufsize==out)

printf( Buffer is Full);

else

{

printf( Enter the value: );

scanf(%d, &produce);

buffer[in] = produce;

in = (in+1)%bufsize;

}

Break; case 2:

if(in == out)

printf( Buffer is Empty);

else

{

consume = buffer[out];

printf( The consumed value is %d, consume);

out = (out+1)%bufsize;

}

break;

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions