Space In HIndi

 


Pages

Popular

System programming and operating system

 Experiment-1
#include<stdio.h>
char sym[11]={'+','-','*','/','(',')','{','}','[',']'}//global variable
int main()
{
    FILE *f;  //define file pointer
    char card[10];//define array charators
    int flag=0,i,ln=0,in=0,sn=0;

//initial value assign and declear the variable
    f=fopen("lsource.c","r");//open file for reading purpose
    printf("UNIFORM SYMBOL TABLE\n");//printing statement
    fscanf(f,"%s",card);//get value form user for file scanning
    while(!feof(f))//file is not open condition
    {
        if(card[0]>='0'&&card[0]='9')//cheak the value is between 0-9
        flag=1;//flag become 1
        else
        for(i=0;i<11;i++)
        {
            flag=2;
            break;
        }
        else
        flag=3;
    }
    switch(flag)//cheak value of the flag
    {
    case 1:ln++;
    printf("\n %d %s %s",ln,"LIT",card);
    break;
    case 2:sn++;
    printf("\n %d %s %s",sn,"TRM",card);
    break;
    case 3:in++;
    printf("\n %d %s %s",in,"IDN",card);
    break;
    }fscanf(f,"%s",card);
    }fclose(f);//close the file
}
INPUT:
POS = 1 + (  ANAND  +  KULKARNI)

OUTPUT:
1 IDN      POS
2 IDN     =
1 LIT      1
1 TRM    +
2 TRM      (
3 IDN      ANAND
3 TRM     +
4 IDN       KULKARNI
4 TRM      )


#!/bin/sh -i

clear
echo "PROGRAM TO PERFORM ARITHMETIC OPERATION ON 2 INTEGER NUMBERS"
ch=1
while [ $ch -eq 1 ]; do
echo -n "Enter First Integer number:    "
read a
echo -n "Enter Second integer number:   "
read b
echo -n "+=ADDITION\n-=SUBTRACTION\n*=MULTIPLICATION,\n/=DIVISION \nEnter choice:  "
read ch
case $ch in
+) echo "RESULT OF  $a + $b = $(($a+$b))" ;;
-) echo "RESULT OF  $a - $b = $(($a-$b))";;
/) echo "RESULT OF  $a / $b = $(($a/$b)).$(($a%$b))";;
*) echo "RESULT OF  $a X $b = $(($a*$b))";;
esac
echo "would u like to continue YES=1/NO=0"
read ch
done
exit 0
#include<stdio.h>
#include<string.h>
char sym[11]={'=','+','-','*','/','(',')','{','}','[',']'};
main()
{
  FILE *s;
  char card[10];
  int i=0,j,sr=0;
  s=fopen("lsource.c","r");
   printf("\n\t\tUNIFORM SYMBOL TABLE");
  fscanf(s,"%s",card);
 while(!feof(s))
 {          if(card[0]>='0'&&card[0]<='9')
              i=1;
              else
            for(j=0;j<11;j++)
              {        if(card[0]==sym[j])
                            {      i=2;
                                    break;
                        }
                        else  i=3;
              }
            sr++;
              switch(i)
              { case 1:printf("\n\t%d %s %s",sr,"LIT",card);
                             break;
                case 2:printf("\n\t%d %s %s",sr,"TRM",card);
                          break;
                case 3:printf("\n\t%d %s %s",sr,"IDN",card);
                            break;
              }
              fscanf(s,"%s",card);
 }
  fclose(s);
}
#include<stdio.h>
#include<string.h>
char mot[][6]={"STOP","ADD","SUB","MUL","MOVER","MOVEM"};
char r[][5]={"AREG","BREG","CREG","DREG"};
main()
{          char lname[20],sname[20][20],st[10];
            int lc,nl=0,ns=0,i,j,m,temp,flag=0,ladd[20],sadd[20];
            FILE *fip=fopen("input.asm","r");
            fscanf(fip,"%s",st);
            printf("IR table\n");
            while(!feof(fip))
            {          if(!strcmp(st,"START"))
                        {          fscanf(fip,"%d",&lc);
                                    printf("%s %d %s %d\n","AD",1,"C",lc);
                        }
                        up:fscanf(fip,"%s",st);
                        for(i=0;i<6;i++)
                        {          if(!strcmp(st,mot[i]))
                                    {          printf("%s %d","IS",i+1);
                                                fscanf(fip,"%s",st);
                                                for(j=0;j<4;j++)
                                                            if(!strcmp(st,r[j]))
                                                            {printf(" %d",j+1);break;}
                                                fscanf(fip,"%s",st);
                                                flag=0;
                                       if(!strcmp(st,"="))
                                       {                   fscanf(fip,"%s",st);
                                                            for(j=0;j<nl;j++)
                                                            if(lname[j]==st[1])
                                                                        flag=1;
                                                            if(flag==0)
                                                            {          lname[nl]=st[1];
                                                                        nl++;
                                                            }
                                                            printf(" %s %d\n","L",j);
                                       }
                                       else
                                       {                   for(j=0;j<ns;j++)
                                                            if(!strcmp(sname[j],st))
                                                                        flag=1;
                                                            if(flag==0)
                                                            {          strcpy(sname[ns],st);
                                                                        ns++;
                                                            }
                                                            printf(" %s %d\n","S",j);
                                       }                   lc ++;
                                                            goto up;
                                    }
                                    for(m=0;m<ns;m++)
                                    {          if(!strcmp(st,sname[m]))
                                                {          fscanf(fip,"%s%d",st,&temp);
                                                            sadd[m]=lc;
                                                            if(!strcmp(st,"DS"))
                                                            {          printf("%s %d %d\n","DL",2,temp);
                                                                        lc+=temp;
                                                            }
                                                else{    printf("%s %d %d\n","DL",1,temp);
                                                                        lc++;
                                                            }
                                                            goto up;
                                    }}}
                        if(!strcmp(st,"END"))
                        {          for(i=0;i<nl;i++)
                                    {          printf("%s %d %s %c\n","AD",2,"C",lname[i]);
                                                ladd[i]=lc;
                                                lc++;
                                    }
                                    break;
                        }
                        lc++;
                        printf("\n");
            }
            printf("\nSYMBOL TABLE\nSYMBOL ENTRY\tSYMBOL\tADDRESS\n");
            for(i=0;i<ns;i++)
                        printf("\n%d\t%s\t%d",i,sname[i],sadd[i]);
            printf("\nLITERAL TABLE\nLITERAL ENTRY\tLITERAL\tADDRESS\n");
            for(i=0;i<nl;i++)
                        printf("\n%d\t%c\t%d",i,lname[i],ladd[i]);
printf("\n");
fcloseall();
system("more ir.txt");
}
#include<stdio.h>
main()
{
int j=0,mnno=1,mdno=1;
char word[20];
FILE *fip,*fmnt,*fmdt,*fir;
fip=fopen("input.txt","r");
fmnt=fopen("mnt.txt","w");
fmdt=fopen("mdt.txt","w");
fir=fopen("ir.txt","w");
while(!feof(fip))
{          fscanf(fip,"%s",word);
            while(strcmp(word,"MACRO"))
            {          fprintf(fir," %s",word);
                        fgets(word,20,fip);
                        printf("%s",word);
                        if(!strcmp(word,"END\n"))
                        {          j=1;break;
                        }
            }
            if(j!=1)
            {          fgets(word,20,fip);
                        fprintf(fmnt," %d%s",mnno,word);
                        mnno++;
                        fprintf(fmdt," %d%s",mdno,word);
                        mdno++;
                        do
                        {          fgets(word,20,fip);
                        fprintf(fmdt," %d %s",mdno,word);
                        mdno++;
                        }while(strcmp(word,"MEND\n")&& strcmp(word,"END\n"));
            }
}
fcloseall();
system("more ir.txt mnt.txt mdt.txt");
}
#include<stdio.h>
#include<stdlib.h>
struct
{
            int b,a,turn,wait;
}proc[5],temp;
void interchange (int i)
{          temp=proc[i];
            proc[i]=proc[i+1];
            proc[i+1]=temp;
}
void main()
{          int n,i,j,sum;
            float ta=0,wa=0;
            printf("Enter No. of processes");
            scanf("%d",&n);
            for (i=0;i<n;i++)
            {          printf("\nEnter Burst time & Arrival time for P%d",i+1);
                        scanf("%d%d",&proc[i].b,&proc[i].a);
            }
            for(i=0;i<n;i++)
                        for(j=0;j<n-1;j++)
                                    if(proc[j].a>proc[j+1].a) //change .a to .b for sjf
                                                interchange(j);
            sum=proc[0].a;
            for(i=0;i<n;i++)
            {          proc[i].wait=sum-proc[i].a;
                        sum+=proc[i].b;
                        proc[i].turn=sum-proc[i].a;
                        ta+=proc[i].turn;
                        wa+=proc[i].wait;
            }
            ta=ta/n;
            wa=wa/n;
            printf("\nProcess\tBusttime\tArrival time\tTurnaround\tWaiting");
            for (i=0;i<n;i++)
printf("\np%d\t%8d%13d%17d%13d",i,proc[i].b,proc[i].a,proc[i].turn,proc[i].wait);
                                                printf("\nAverage turn around time is %f\n",ta);
                                                printf("Average waiting time is %f\n",wa);
}
#include<stdio.h>
#include<stdlib.h>
int Pmax[3],Pcurr[3],avl,maxres,running[]={1,1,1},i,j,safe,proc,req;
int checksafe()
{          safe=0;
            for(i=0;i<3;i++)
                        if(running[i])
                                    if(Pmax[i]-Pcurr[i]<=avl)
                                    safe=1;
            return safe;
}
void main()
{
maxres=5;
Pmax[0]=3;Pcurr[0]=1;
Pmax[1]=2;Pcurr[1]=1;
Pmax[2]=2;Pcurr[2]=2;
avl=maxres-(Pcurr[0]+Pcurr[1]+Pcurr[2]);
while(running[0]+running[1]+running[2])
{for(proc=0;proc<3;proc++)
            if(running[proc])
            {          printf("\nTrying with process %d",proc+1);
                        req=Pmax[proc]-Pcurr[proc];
                        if(req>avl)
                        {printf("\nFailed to allote as process required more than available");
                                    continue;
                        }
                        Pcurr[proc]+=req;
                        avl-=req;
                        if(checksafe())
                        {
printf("\nResources successfully allocated,Process %d has completed its execution",proc+1);
                        avl+=Pmax[proc];
                        running[proc]=0;
                        }
                        else
                        {          Pcurr[proc]-=req;
                                    avl+=req;
                         printf("\nResouces cannot be allocated, due to bankers algorithm!");
                        }
            }
            }
printf("\nAll processes completed successfully!\n");
}
#include<stdio.h>
#include<stdlib.h>
int fr[10],cy=1,frsize=3,stsize=10,p[20];
void main()
{
            int i,j,ch=0,fs[10];
            int index=0,k,l,flag1=0,flag2=0,pf=0;
            printf("\n Enter %d elements of string:",stsize);
            for(i=0;i<stsize;i++)
            scanf("%d",&p[i]);
            printf("\nWITH FIFO algorithm");
            for(i=0;i<frsize;i++)
                        fr[i]=-1;
            for(j=0;j<stsize;j++)
            {          flag1=0,flag2=0;
                        for(i=0;i<frsize;i++)
                                    if(fr[i]==p[j])
                                    {          flag1=1;flag2=1;
                                                break;
                                    }
                        if(flag1==0)
                                    for(i=0;i<frsize;i++)
                                                if(fr[i]==-1)
                                                {          fr[i]=p[j];
                                                            flag2=1;
                                                            break;
                                                }
                        if(flag2==0)    
                        {     fr[index]=p[j];
                                    index++;
                                    if(index==frsize)
                                    index=0;
                                    pf++;
                        }
                        printf("\n Cycle: %d \tRequested page: %d\t",cy,p[cy-1]);
                        for(i=0;i<frsize;i++)
                        printf("\t%d",fr[i]);
                        cy++;
                        }
                        printf("\n no of page faults :%d",pf);
                        }
#include<stdio.h>
#include<stdlib.h>
int fr[10],cy=1,frsize=3,stsize=10,p[20];
void main()
{          int i,j,ch=0,fs[10];
            int index=0,k,l,flag1=0,flag2=0,pf=0;
            printf("\n Enter %d elements of string:",stsize);
            for(i=0;i<stsize;i++)
            scanf("%d",&p[i]);
            printf("\nWITH FIFO algorithm");
            for(i=0;i<frsize;i++)
                        fr[i]=-1;
            for(j=0;j<stsize;j++)
            {          flag1=0,flag2=0;
                        for(i=0;i<frsize;i++)
                                    if(fr[i]==p[j])
                                    {          flag1=1;flag2=1;
                                                break;
                                    }
                        if(flag1==0)
                                    for(i=0;i<frsize;i++)
                                                if(fr[i]==-1)
                                                {          fr[i]=p[j];
                                                            flag2=1;
                                                            break;
                                                }
                        if(flag2==0)    
                        {    for(i=0;i<frsize;i++)
                                                fs[i]=0;
                                    for(k=j-1,l=1;l<=frsize-1;l++,k--)
                                                for(i=0;i<frsize;i++)
                                                            if(fr[i]==p[k])
                                                                        fs[i]=1;            
                                    for(i=0;i<3;i++)
                                                if(fs[i]==0)
                                                            index=i;
                                    fr[index]=p[j];
                                    pf++;
                        }
                        printf("\n Cycle: %d \tRequested page: %d\t",cy,p[cy-1]);
                        for(i=0;i<frsize;i++)
                        printf("\t%d",fr[i]);
                        cy++;
                        }
                        printf("\n no of page faults :%d",pf);
}
#include <stdio.h>
#include <fcntl.h>
int main()
{
            int i,n,sum=0;
            pid_t pid;
            printf("Enter n value:");
            scanf("%d",&n);
             pid=fork();
            if(pid==0)
            {
                        printf("From child process\n");
                        for(i=1;i<n;i+=2)
                                    printf("%d\n",i);
            }
            else
            {
                        printf("From Parent process\n");
                        for(i=0;i<n;i+=2)
                                    printf("%d\n",i);
            }
}
#include<stdio.h>
#include<dirent.h>
int main(int argc,char *argv[])
{
DIR *dp;
struct dirent *sd;
dp=opendir(argv[1]);
while((sd=readdir(dp))!=NULL)
            printf("%s\t",sd->d_name);
printf("\n");
closedir(dp);
}

No comments: