Sunday, November 25, 2012

Paging Program in OS with C language

#include"stdio.h"
#include"conio.h"
void main()
{
    int lmem,psize,pmem,i,j,k,c[10],str;
    int a[20],b[35],ch,page,index,abs,frame;
    clrscr();
    printf("\n enter page size::");
    scanf("%d",&psize);
    printf("\nenter logical memory size::");
    scanf("%d",&lmem);
    printf("\n%d",lmem);
    printf("\nenter phisical memory size::");
    scanf("%d",&pmem);
    printf("\n enter data::");
    for(i=0;i<lmem;i++)
        scanf("%d",&a[i]);
    for(i=0;i<32;i++)
        b[i]=-1;
    for(i=0;i<lmem/psize;i++)
    {
        printf("\nenter starting location for page::%d",i);
        scanf("%d",&str);
        if(str%4==0)
        {

            c[i]=str/psize;
            for(j=str,k=i*4;j<j+psize,k<i*4+psize;j++,k++)
            {
            b[j]=a[k];
            }
        }
        else
            printf("\n wrong entry for page the page address shud be multiples of 4");
    }
    printf("\n the page table is::");
    printf("\n page \t\t frame");

    for(i=0;i<lmem/psize;i++)
        printf("\n %d\t %d",i,c[i]);
    printf("\n enter for which data the mapping address to be found::");
    scanf("%d",&ch);
    for(i=0;i<lmem;i++)
    {
        if(ch==a[i])
        {
            index=i;
            page=index/4;
            frame=c[page];
            abs=(frame*psize)+(index%psize);
        }

    }

    printf("\n the physical address for %d is::%d",ch,abs);
    getch();
}

1 comment:

  1. Please can you help me with solutions to the below questions
    1. In a temple three queues are maintained to make Swami darshan. One is meant for VVIPs, second is for VIPs and the third one is for ordinary people. Only when there is no person waiting in VVIP queue VIP queue is allowed for darshan and only when no people in VIP queue ordinary people queue is allowed. If a person is waiting for more than a particular time he may be allowed to move next hierarchy queue. Develop an algorithm and implement in C to print the schedule for each queue, waiting time of the pilgrims and the average turn around time.

    2. To visit the Vivekananda Rock and Thiruvalluvar statue at Kanyakumari, the visitors are taken through three boats of capacity n. m (less than or equal to one fourth of n) number of seats in each boat is reserved for VIPs. If the number of VIPs visiting is less than the allotted seats, the remaining seats may be used for others. If number of VIPs is more, general seats are converted to VIP seats. The other visitors are selected based on a lottery ticket they hold. The lottery scheduler generates a random number, and those having the random numbers with in the boat capacity are selected. After seeing the Vivekananda rock the empty boat takes the visitors based on First Come First Served policy and drops at Thiruvalluvar Statue, and from there they will be dropped at the shore. For dropping as well as visiting Thiruvalluvar statue VIPs will be given the higher priority than the ordinary people. Write a program in C to simulate the above scenario.

    3. Assume a two-way north-south road contains a one-lane tunnel. A southbound (or northbound) car can use the tunnel only if there are no oncoming cars when the car arrives at the entrances to the tunnel. Because of accidents, a signaling system has been installed at the entrances of the tunnel. When a car approaches the tunnel, a sensor notifies the controller computer by calling a function named arrive and passes it a parameter indicating the car’s direction of travel. When a car exits the tunnel, the sensor again notifies the tunnel controller computer calling a function named depart (again with the direction of travel passed as a parameter). The traffic controller computer sets signal lights. Green means proceed and red means stop, Write a C program to simulate the action of controlling lights so that they operate correctly even when most cars approach the tunnel from one direction. Also, write a detailed algorithm and the OS concepts used for the above problem. (Concept: Semaphores)

    4. Consider a system of three smoker processes and one agent process. Each smoker continuously makes a cigarette and smokes it. To make a cigarette, the smoker needs three ingredients: tobacco, paper and matches. On of the smoker process has paper, another has tobacco and the third has matches. The agent has infinite supply of all the three materials. The agent places the two of the ingredients on the table. The smoker who has the remaining ingredient then makes and smokes a cigarette, signaling the agent on completion. The agent then puts another two of the three ingredients, and the cycle repeats. Write a C program to synchronize the agent and smokers.

    5. A data object (such as a file or record) is to be shared among several concurrent processes. Some of these processes may want only to read (Reader processes) others may want to update (Writer processes) on the shared data object. If more than one readers access the shared data object simultaneously, no adverse effects will result. However, if a writer and some other process access the shared data object simultaneously chaos may takes place Write a C program to coordinate the reader and writer processes.

    ReplyDelete