Banker's algorithm

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:

shell scripts to simulate Banker�s algorithm on a collection of processes (process details are entered as inputs at the beginning of the simulation) and a comparison when an allocation is modified.

  1. Relevant commands, code, scripts, algorithms:
    i have source code in c
#include<stdio.h>
#include<conio.h>
main()
{
   int i,j,a=0,b=0,c=0,f[10],t[10][10],al[10][10],ta[10][10];
   int a1[10][10], max[10][10], n[10][10], n1,p,k=0;
   printf(�\n enter no.of resources�);
   scanf(�%d�,n1);
   printf(�\nenter the max no .of resources for each type�);

  for(i=0;i<n1;i++)
 {
    scanf(�%d�,&t);
  }
  printf(�\nenter no .of process�);
  scanf(�%d�,&p);
  printf(�\nenter allocation resources�);

  for(i=0;i<p;i++)
  {
    f=0;
    for(j=0;j<n1;j++)
    {
       scanf(�%d�,&a1[j]);
     }
   }

 for(i=0;i<p;i++)
 {
    for(j=0;j<n1;j++)
   {
      if(a1[j]<=t[j])
      {
         t[j]+=a1[j];
        continue;
       }
     else
    printf(�\n wrong resources allocation�);
 }
    printf(�\n chance of deadlock occurrence after allocation�);
  for(j=0;j<n1;j++)
  {
     printf(�%d�,a1[j]);
   }
  printf(�\n enter the max resources for every process�);
for(i=0;i<p;i++)
{
   for(j=0;j<n1;j++);
   {
     scanf(�%d�,&max[j]);
     n[j]=max[j]-a1[j];
    }
}
printf(�\n needed resources for every process to start execution�);
for(i=0;i<p;i++)
{ 
   printf(�\n%d %d%d�,n[j],n[j+1],n[j+2]);
}
printf(�\n safe sequence the sequence of process to compute their execution�);
for(a=0;a<(p-c);)
{
   for(i=0;i<p;i++)
   {
      j=0;
      b=0;
       if(f==0)
       {
           if(n[j] <= a1[j] && n[j+1] <= a1[j+1] && n[j+2] <= a1[j+2])
             {
                  printf(�\n process %d execution started and completed�,i+1);
                  for(k=0;k<n-1;k++)
                  {
                       a1[k]+=a1[k];
                   }
                    f=1;
                   c++;
              }
           else
          f=0;
         }
  }
  getch();
}


  1. The attempts at a solution (include all code and scripts):
  #!/bin/bash
  echo "enter no.of resources: "
    read n1 
    echo -n "enter the max no .of resources for each type:  " 
    
    for(( i=0; i <$n1; i++ ))
    do 
      read ${t} 
    done
    echo -n "enter no .of process: " 
    read p 
    echo -n "enter allocation resources: " 
    for((i=0;i<p;i++)) 
    do 
     f=0 
     for((j=0;j<$n1;j++)) 
     do
      read ${a1} 
     done
    done

  
  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
    MMU Cyber, Cyberjaya, Malaysia, Mr. Timothy, tos 2111

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Hi syah, could you edit your post and indent the C code please?

You seem to be stuck on the use of multi-dimensional arrays, for which there is no implementation in shell. You would need to devise a way around that.

i know but how? can u show me some examples??

First thing that comes to mind is emulation using eval*

for (( i=1; i<=5 ; i++ ))
do
  for (( j=1; j<=5 ; j++ ))
  do
    eval a_${i}_[$j]=$(( i + j*10 ))
  done
done

echo "${a_3_[4]}"

k=3 l=4
eval echo "\"\${a_${k}_[l]}\""

eval "val=\${a_${k}_[l]}"
echo "$val"

Did you look for alternatives?

--
*In general be extra careful with eval, always look for security risks if variable content comes from a source that you do not control.