Banker's algorithm

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Banker's algorithm
# 1  
Old 04-25-2012
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.

2. Relevant commands, code, scripts, algorithms:
i have source code in c
Code:
#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[b][i]);
  }
  printf(“\nenter no .of process”);
  scanf(“%d”,&p);
  printf(“\nenter allocation resources”);

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

 for(i=0;i<p;i++)
 {
    for(j=0;j<n1;j++)
   {
      if(a1[i][j]<=t[b][j])
      {
         t[b][j]+=a1[i][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[b][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[i][j]);
     n[i][j]=max[i][j]-a1[i][j];
    }
}
printf(“\n needed resources for every process to start execution”);
for(i=0;i<p;i++)
{ 
   printf(“\n%d %d%d”,n[i][j],n[i][j+1],n[i][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[i]==0)
       {
           if(n[i][j] <= a1[b][j] && n[i][j+1] <= a1[b][j+1] && n[i][j+2] <= a1[b][j+2])
             {
                  printf(“\n process %d execution started and completed”,i+1);
                  for(k=0;k<n-1;k++)
                  {
                       a1[b][k]+=a1[i][k];
                   }
                    f[i]=1;
                   c++;
              }
           else
          f[i]=0;
         }
  }
  getch();
}

3. The attempts at a solution (include all code and scripts):
Code:
  #!/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

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

Last edited by syah; 04-25-2012 at 06:51 AM..
# 2  
Old 04-25-2012
Hi syah, could you edit your post and indent the C code please?
# 3  
Old 04-26-2012
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.
# 4  
Old 04-26-2012
i know but how? can u show me some examples??
# 5  
Old 04-26-2012
First thing that comes to mind is emulation using eval*

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

Last edited by Scrutinizer; 04-26-2012 at 06:50 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

banker's algorithm.. help

i'm doing banker's algorithm.. got some error there but i cant fix it.. please help!! #!/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... (1 Reply)
Discussion started by: syah
1 Replies

2. Homework & Coursework Questions

Heuristic Algorithm Example

Give a counter example such that the following heuristic algorithm, for the 2-tape problem, doesn't always produce the best solution: Algorithm: Sort {Xi} in descending order. Place files in tapes one at a time. For a file being considered, assign the file to the smaller tape. Thanks in... (1 Reply)
Discussion started by: sureshcisco
1 Replies

3. Programming

Looking for Your Help on dijkstra algorithm

Can you help to adjust the void dijkstra(int s) function to find a path from source to every node so that the minimum cost on that path is maximum. Ex: From 1 to 2 we have 1 - 3 - 4 - 2 , costs(2+3+4+5) From 1 to 2 we have 1 - 5 - 6 - 2 , costs(3+3+4+5) I need the algorithm to choose path 1... (4 Replies)
Discussion started by: ali2011
4 Replies

4. Programming

Please help me to develop algorithm

Hi guys , in my study book from which I re-learn C is task to generate all possible characters combination from numbers entered by the user. I know this algorithm must use combinatorics to calculate all permutations. Problem is how to implement algortihm. // This program reads the four numbers... (0 Replies)
Discussion started by: solaris_user
0 Replies

5. Shell Programming and Scripting

algorithm

PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP 21444 tomusr 213M 61M sleep 29 10 1:20:46 0.1% java/43 21249 root 93M 44M sleep 29 10 1:07:19 0.2% java/56 is there anyway i can use a command to get the total of the SIZE? 306M (Derive from... (5 Replies)
Discussion started by: filthymonk
5 Replies

6. Programming

Feedback algorithm

Hi I search an exemple of scheduling Feedback algorithm, or help about how to create one. Thanks (0 Replies)
Discussion started by: messier79
0 Replies
Login or Register to Ask a Question