Skip to main content

Determine the safe sequence of Banker's algorithm

process      Allocation   Max   Available
---------    ------------   ------   -----------
p0             3                 6         2
p1            4                 8      
p2            0                 1    
p3            3                 5
p4           1                 6
p5           2                 12


Solution:Banker's algorithm using c

#include<stdio.h>


int executed[6];
int main()
{
    int p = 6, i;
    char process[10];

    int need[6];
    int allocated[6];
    int max[6];
    int avail = 2, k,j;


    printf("Enter current allocation:");
    for (i = 0; i<p; i++)
    scanf("%d", &allocated[i]);

    printf("Enter max claim:");
    for (i = 0; i<p; i++)
        scanf("%d", &max[i]);

    //calculate need
    for (i = 0; i<p; i++)
    {
        need[i] = max[i] - allocated[i];
    }

    k = 0;


    while (1)
    {
        for (i = 0; i<p; i++)
        {

                if (need[i] <= avail)
                {
                    executed[k++] = i;
                    need[i] = 99999999999; //sentinel element
                    if (i < 6)
                    {
                        avail = allocated[i] + avail;
                    }
                }
            }


        if (k == p)
        {
            break;
        }
    }

    printf("Safe sequence:");
    for (i = 0; i<p; i++)
    {
        printf(" P%d ", executed[i]);
    }

    return 0;
}

Comments

Popular posts from this blog

FTP(File Transfer Protocol ) configuration and testing in Windows Server 2008 R2

First of all you have to know  what the FTP is " File Transfer Protocol ( FTP ) is a standard network protocol used to transfer files from one host or to another host over a TCP -based network". FTP Installation & Configuration: Step 1: Install the Web Server role with the IIS Management Console and FTP Server role services: Step 2: Add a new FTP Site Step 3: Setup the site with the default bindings and choose Allow SSL to avoid deploying a certificate:     Step 4: Configure user permissions and basic or anonymous permission. If your server is connected to your domain you can specify domain users, otherwise they must be local user accounts: Note: Finally you’ll have to configure your server’s firewall rules to allow access.Disregard any existing FTP firewall rules; although they should be enabled, they don’t actually allow access! Run Allow a Program Through Windows Firewall and grant access to C:\Windows\System32\svchost.exe T...

update your package-lock.json according to what you have specified in the package.json file

  The objective of the   npm update   command is to update your   package-lock.json   according to what you have specified in the   package.json   file. This is the normal behavior. If you want to update your package.json file, you can use  npm-check-updates :  npm install -g npm-check-updates . You can then use these commands: ncu  Checks for updates from the package.json file ncu -u  Update the package.json file npm update --save  Update your package-lock.json file from the package.json file