SS and OS Lab Manual 2013(VTU)

download SS and OS Lab Manual 2013(VTU)

of 37

description

VTU ( Vishveshwariya Technological University ) LAB MANUAL FOR 5th SEM CSE SS and OS lab manual

Transcript of SS and OS Lab Manual 2013(VTU)

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    1 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    PART - ALEX and YACC Programs:Design, develop, and execute the following programs using LEX:1. a) Program to count the number of characters, words, spaces and lines in a given input file.

    b) Program to count the numbers of comment lines in a given C program. Also eliminate them and copythe resulting program into separate file.

    2. a) Program to recognize a valid arithmetic expression and to recognize the identifiers and operators present.Print them separately.b) Program to recognize whether a given sentence is simple or compound.

    3. Program to recognize and count the number of identifiers in a given input file.

    Design, develop, and execute the following programs using YACC:4. a) Program to recognize a valid arithmetic expression that uses operators +, -, * and /.

    b) Program to recognize a valid variable, which starts with a letter, followed by any number of letters ordigits.

    5. a) Program to evaluate an arithmetic expression involving operators +, -, * and /.b) Program to recognize strings aaab, abbb, ab and a using the grammar (anbn, n>= 0).

    6. Program to recognize the grammar (anb, n>= 10).

    PART BUNIX Programming:Design, develop, and execute the following programs:7. a) Non-recursive shell script that accepts any number of arguments and prints them in the Reverse

    order, ( For example, if the script is named rargs, then executing rargs A B C should produce C B A onthe standard output).

    b) C program that creates a child process to read commands from the standard input and execute them (aminimal implementation of a shell like program). You can assume that no arguments will be passed tothe commands to be executed.

    8. a) Shell script that accepts two file names as arguments, checks if the permissions for these files areidentical and if the permissions are identical, outputs the common permissions, otherwise outputs each filename followed by its permissions.

    b) C program to create a file with 16 bytes of arbitrary data from the beginning and another 16 bytes ofarbitrary data from an offset of 48. Display the file contents to demonstrate how the hole in file is handled.

    9. a) Shell script that accepts file names specified as arguments and creates a shell script that contains this fileas well as the code to recreate these files. Thus if the script generated by your script is executed, it wouldrecreate the original files(This is same as the bundle script described by Brain W. Kernighan and RobPike in The Unix Programming Environment, Prentice Hall India).

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    2 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    b) C program to do the following: Using fork( ) create a child process. The child process prints its ownprocess-id and id of its parent and then exits. The parent process waits for its child to finish (by executingthe wait( )) and prints its own process-id and the id of its child process and then exits.

    Operating Systems:

    10. Design, develop and execute a program in C / C++ to simulate the working of Shortest Remaining Time andRound-Robin Scheduling Algorithms. Experiment with different quantum sizes for the RoundRobin algorithm. Inall cases, determine the average turn-around time. The input can be read from key board or from a file.

    11. Using OpenMP, Design, develop and run a multi-threaded program to generate and print Fibonacci Series. Onethread has to generate the numbers up to the specified limit and another thread has to print them. Ensure propersynchronization.

    12. Design, develop and run a program to implement the Bankers Algorithm. Demonstrate its working withdifferent data values.

    Instructions: In the examination, a combination of one LEX and one YACC problem has to be asked from PartA for a total of 30 marks and one programming exercise from Part B has to be asked for a total of 20 marks.

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    3 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    PART - A

    LEX PROGRAMS:

    1) a. Program to count the number of characters, words, spaces and lines in a given input file. //1a.l

    %{int wc=0,cc=0,lc=0,sc=0;

    %}

    %option noyywrap

    %%

    [^ \t\n]+ {wc++;cc+=yyleng;}

    [ ]+ {sc++;}

    [\n]+ {lc++;}

    %%

    main(int argc,char *argv[]){

    FILE *fp;if(argc==2){

    fp=fopen(argv[1],"r");yyin=fp;

    }yylex();printf("Number of character =%d\n",cc);printf("Number of words =%d\n",wc);printf("Number of spaces =%d\n",sc);printf("Number of lines =%d\n",lc);

    }

    OUTPUT:$ lex 1a.l$ cc lex.yy.c ll$ ./a.outHai dear you thereNumber of character =15

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    4 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    Number of words =4Number of spaces =3Number of lines =1

    1) b.Program to count the numbers of comment lines in a given C program. Also eliminate them andcopy the resulting program into separate file. //1b.l

    %{int c=0;

    %}%option noyywrap%x CMT%x ct%%

    // { BEGIN ct;}.\n {c++;BEGIN INITIAL ;}. ;

    "/*" {BEGIN CMT;}\n {c++;}.\n {c++;}"*/" {c++; BEGIN INITIAL;}. ;

    %%main(int argc,char * argv[]){

    FILE *fp1,*fp2;if(argc==3){

    fp1=fopen(argv[1],"r");fp2=fopen(argv[2],"w");yyin=fp1;yyout=fp2;

    }yylex();printf("Number of comment lines = %d\n",c);

    }OUTPUT:

    $ lex 1b.l$ cc lex.yy.c ll$ gedit 1.c$ ./a.out 1.c 1b.cNumber of comment lines =2

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    5 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    1.c main(){

    int a,b; /* int declaration */float amt,avg; /* float declaration */

    }

    1b.c main(){

    int a,b;float amt,avg;

    }

    2) a. Program to recognize a valid arithmetic expression and to recognize the identifiers and operatorspresent. Print them separately. //2a.l

    %{int pc=0,state=0,i=0,j=0;enum{FIRST=0,OP,CP,OPRND,OPRT};char a[20];

    %}

    %option noyywrap

    %%

    [a-zA-Z][a-zA-Z0-9]*{if(state==FIRST||state==OP||state==OPRT)

    {state=OPRND;printf("operand %d=%s\n",++i,yytext);

    }else return 0;

    }

    [+\-*/] {if(state==OPRND||state==CP)

    {state=OPRT;a[j++]=yytext[0];

    }else return 0;

    }

    \( {if(state==FIRST||state==OPRT||state==OP)

    {state=OP;pc++;

    }else return 0;

    }

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    6 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    \) {if(pc

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    7 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    operand 3=cValid ExpressionValid Operators are:+-

    Invalid Expression

    2) a. Program to recognize a valid arithmetic expression and to recognize the identifiers and operatorspresent. Print them separately. //2aa.l

    OR%{

    int a=0,s=0,m=0,d=0,ob=0,cb=0,va=0 ,ident=0;int flaga=0, flags=0, flagm=0, flagd=0;

    %}ID [a-zA-Z][a-zA-Z 0-9]*NOTID [0-9a-zA-Z]+%%{ID} {ident++;printf("\n %s is an identifier\n",yytext);}{NOTID} {va++;}[+] {a++;flaga=1;}[-] {s++;flags=1;}[*] {m++;flagm=1;}[/] {d++;flagd=1;}[(] {ob++;}[)] {cb++;}return;%%int main(){

    printf("Enter the expression:\n");yylex();if(ob-cb!=0 | va>0 |ident==0|a+s+m+d>=ident){

    printf("Invalid expression\n");}else{

    printf("valid expression");printf("\nAdd=%d\nSub=%d\nMul=%d\nDiv=%d\n",a,s,m,d);printf("Operators are: \n");if(flaga)printf("+\n");if(flags)printf("-\n");if(flagm)printf("*\n");if(flagd)

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    8 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    printf("\\ \n");}

    return 0;}

    OUTPUT:Enter the expression:A+BA is an identifierB is an identifierCtrl+dvalid expressionAdd=1Sub=0Mul=0Div=0Operators are:+

    2) b. Program to recognize whether a given sentence is simple or compound. //2b.l

    %{int flag=0;

    %}%option noyywrap%%

    "and" |"AND" |"or" |"OR" |"if" |"IF" |"else" |"ELSE" |"not" |"NOT" |"but" |"BUT" {flag=1;}. ;\n {return;}

    %%main(){

    yylex();

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    9 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    if(flag==0)printf("Sentence is Simple\n ");elseprintf("Sentence is Compound\n");

    }OUTPUT:$ lex 2b.l$ cc lex.yy.c ll$./a.outHai dear you thereSentence is Simple

    $ lex 2b.l$ cc lex.yy.c ll$./a.outHai dear I am not cumgSentence is Compound

    3.Program to recognize and count the number of identifiers in the given input file. //3.l

    %{int idc=0;

    %}

    %option noyywrap%x IDENTID [a-zA-Z][a-zA-Z0-9]*DTYPE "int "|"float "|"char "%%

    {DTYPE} { BEGIN IDENT; }[^ ,]{ID} ;{ID}"," { idc++; }{ID}";" { idc++;BEGIN INITIAL; }

    %%main(int argc,char*argv[]){

    FILE *fp;if(argc==2){

    fp=fopen(argv[1],"r");yyin=fp;yylex();printf(" Number of identifiers is = %d\n",idc);

    }

    else printf("input file is missing");}

    OUTPUT:$ lex 3.l 3.c

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    10 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    $ cc lex.yy.c ll$./a.out 3.cNumber of identifiers is = 5

    main(){

    int abc,sum,a;float avg,amt;

    }YACC PROGRAMS:

    4.a) Program to recognize a valid arithmetic expression that uses operators +,-,*,/. // 4a.y

    %{#include#include

    %}%token DIG LET

    %left '+''-'

    %left '*''/'

    %%line: line exp '\n' { printf("valid Expression\n"); }

    || line '\n'| error '\n' { yyerror("invalid Expression\n");yyerrok; };

    exp: exp '+' exp| exp '-' exp|exp '*' exp|exp '/' exp|'(' exp ')'| num| lts;

    num: DIG| num DIG;

    lts: LET| lts LET| lts DIG;

    %%main(){

    yyparse();}yyerror(char*s)

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    11 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    {printf("%s\n",s);

    }

    yylex(){

    int c;while((c=getchar())==' ');if(isdigit(c)) return DIG;if(isalpha(c)) return LET;return c;

    }OUTPUT:$ yacc 4a.y$ cc y.tab.c$ ./a.out

    (a+b)*cvalid Expression

    a+(b+csyntax errorinvalid Expression

    a++bsyntax errorinvalid Expression

    a+b*cvalid Expression

    a+b*c a*b+csyntax errorinvalid Expression

    4.b) Program to recognize a valid variable, which starts with a letter followed by any number of lettersor digits. //4b.y

    %{#include#include

    %}

    %token DIG LET

    %%

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    12 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    line: line var '\n' { printf("\n valid Variable\n"); }|| line '\n'| error '\n' { yyerror("\ninvalid variable\n");yyerrok };

    var: LET| var LET| var DIG;

    %%main(){

    yyparse();}yyerror(char*s){

    printf("%s\n",s);}yylex(){

    char c;while((c=getchar())==' ');if(isdigit(c)) return DIG;if(isalpha(c)) return LET;return c;

    }OUTPUT:$ yacc 4b.y$ cc y.tab.c$ ./a.outabc23valid Variable

    a123valid Variable

    133asdsyntax errorinvalid variable

    5.a) Program to evaluate an arithmetic expression involving operators +,-,*,/. // 5a.y

    %{#include#include

    %}

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    13 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    %token DIG%left '+' '-'%left '*' '/'%left UMINUS%%line : line exp '\n' { printf("Res=%d\n",$2); }

    || line '\n'| error '\n' { yyerror("Invalid Exp:\n");yyerrok; };

    exp : exp '+' exp { $$=$1+$3; }| exp '-' exp { $$=$1-$3; }|exp '*' exp { $$=$1*$3; }|exp '/' exp {

    if($3==0){

    printf("\n Divide by 0 error\n");return 0;

    }else

    $$=$1/$3;}

    | '-'exp %prec UMINUS { $$=-$2; }| num;

    num : DIG { $$=$1; }| num DIG { $$=$1*10+$2;};

    %%main(){

    yyparse();}yyerror(char *s){

    printf("%s\n",s);}yylex(){

    int c;while((c=getchar())==' ');if(isdigit(c)){

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    14 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    yylval=c-'0';return DIG;

    }return c;

    }OUTPUT:

    $ yacc 5a.y$ cc y.tab.c$ ./a.out3+4+5Res=127-4+Invalid Exp:4/0Divide by 0 error

    5.b) Program to recognize a valid string 'aaab','abbb','ab' and 'a' using the grammer {anbn,n>=0}. //5b.y%{

    #include#include

    %}%token A B%%line : line str '\n' { printf("\n valid expression\n"); }

    || error '\n' { yyerror("\ninvalid expression\n"); yyerrok; };

    str :| A str B;

    %%main(){

    yyparse();}yyerror(char *s){

    printf("%s\n",s);}yylex(){

    int c;while((c=getchar())==' ');if(c=='a') return A;

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    15 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    if(c=='b') return B;return c;

    }

    OUTPUT:$ yacc 5b.y$ cc y.tab.c$ ./a.out

    abvalid expressionaaabsyntax errorinvalid expression

    abbbsyntax errorinvalid expression

    asyntax errorinvalid expression

    6. Program to recognize the grammer {anb,n>=10} // 6.y%{

    #include#include

    %}%token A B%%line : line str '\n' { printf("\n valid expression\n"); }

    || line '\n'| error '\n' { yyerror("\ninvalid expression\n"); yyerrok; };

    str : A A A A A A A A A A B| A str;

    %%main(){

    yyparse();}yyerror(char *s)

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    16 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    {printf("%s\n",s);

    }

    yylex(){

    int c;while((c=getchar())==' ');if(c=='a') return A;if(c=='b') return B;return c;

    }OUTPUT:$ yacc 6.y$ cc y.tab.c$ ./a.out

    aaaaaaaaaabvalid expression

    absyntax errorinvalid expression

    aaaaaaaaaaaaaaabvalid expression

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    17 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    PART BUNIX PROGRAMS:7.a) Non-recursive shell script that accepts any number of argument and prints them in the Reverse order,

    (For example, if the script is named rargs, then executing rargs A B C should produce C B A on thestandard output). //7a.sh

    if [ $# -eq 0 ]then echo "No arguments"elsefor i in "$@"dorev=$i' '$revdoneecho "The Reverse string is $rev"fi

    OUTPUT:

    $sh 7a.sh A B C

    The Reverse string is C B AOR

    $ chmod 777 7a.sh

    The Reverse string is C B A

    7.b) C program that creates a child process to read commands from the standard input and executethem(minimal implementation of shell like program). You can assume that no arguments will bepassed to the commands to be executed. //7b.c

    #include#include#include#includeint main(){

    pid_t pid;char cmd[10];pid=fork();if (pid==0){

    printf("Enter a UNIX command\n");scanf("%s",cmd);execlp(cmd,cmd,(char*)0);exit(0);

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    18 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    }waitpid(pid,0,0);return 0;

    }

    OUTPUT:$ cc 7b.c$ ./a.outEnter a UNIX commanddateTue Aug 12 15:06:17 IST 2012

    8.a) Shell script that accepts two file names as arguments, checks if the permissions for these files areidentical and if the permissions are identical, outputs the common permissions, otherwise outputseach file name followed by its permissions. //8a.sh

    if [ $# -ne 2 ]thenecho "no arguments pls enter 2 arguments"elif [ ! -e $1 -o ! -e $2 ]thenecho "File does not exist"elseper1=`ls -l $1 | cut -c 2-10`per2=`ls -l $2 | cut -c 2-10`if [ $per1 = $per2 ]thenecho "Permissions are Identical:permission is $per1"elseecho "Permissions are not Identical"echo "permission of $1 is $per1"echo "permission of $2 is $per2"fifiOUTPUT:$ sh 8a.shno arguments pls enter 2 arguments

    1.cThis is System Software Lab

    $ sh 8a.sh 1.c 2.cPermissions are Identical:permission is rw-rr

    $ sh 8a.sh 1.c 2.c //if 1.c or 2.c doesnt created means

    File does not exist2.cHKBK college of Engineering

    $ chmod 777 1.c

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    19 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    $ chmod 770 2.c$ sh 2a.sh 1.c 2.cPermissions are not Identicalpermission of 1.c is rwxrwxrwxpermission of 2.c is rw-r--r--8.b) C program to create a file with 16 bytes of arbitrary data from the beginning and another 16 bytes of

    arbitrary data from an offset of 48. Display the file contents to demonstrate how the hole in file ishandled. // 8b.c

    #include#include#include#includeint main(){

    char a[]="1111111111111111";char b[]="2222222222222222";int fd;fd=open("hole",O_CREAT|O_WRONLY,0777);write(fd,a,16);lseek(fd,48,SEEK_SET);write(fd,b,16);close(fd);return 0;

    }

    OUTPUT:

    $ cc 2b.c$ ./a.out$ od -bc hole0000000 061 061 061 061 061 061 061 061 061 061 061 061 061 061 061 061

    1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 10000020 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000

    \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0*0000060 062 062 062 062 062 062 062 062 062 062 062 062 062 062 062 062

    2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 20000100

    9.a) Shell script that accepts filenames specified as arguments and creates a shell script that contains this fileas well as the code to recreate these files . thus if the script generated by your script is executed, itwould recreate the original files . //9a.sh

    if [ $# -eq 0 ]then

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    20 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    echo "No Arguments"exitfifor i in "$@"do

    if [ ! -e $i ]thenecho "$i not existing"elseecho "cat >$i

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    21 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    pid=waitpid(pid,0,0);printf("Output from parent process:\n");printf("The id of child process=%d\n",pid());printf("The id of parent process=%d\n",getpid());exit(1);

    }OUTPUT:$ cc 9b.c$ ./a.out

    Output from child process:

    The id of child process=2898

    The id of parent process=2897

    Output from parent process:

    The id of child process=2898

    The id of parent process=2897

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    22 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    Operating Systems Programs: Using OpenMP

    10: Design, develop and execute a program in C/C++ to simulate the working of Shortest Remainingtime and Round Robin Scheduling algorithms. Experiment with different Quantum sizes for theRound Robin algorithm. In all cases, determine the average turn Around time. Input can be readfrom keyboard or from a file.

    #includestruct proc{

    int id;int arrival;int burst;int rem;int wait;int finish;int turnaround;float ratio;

    }process[10]; //structure to hold the process informationstruct proc temp;int no;

    int chkprocess(int);int nextprocess();void roundrobin(int, int, int[], int[]);void srtf(int);

    main(){

    int n,tq,choice;int bt[10],st[10],i,j,k;for(; ;){

    printf("Enter the choice \n");printf(" 1. Round Robin\n 2. SRT\n 3. Exit \n");scanf("%d",&choice);switch(choice){

    case 1:printf("Round Robin scheduling algorithm\n");printf("Enter number of processes:\n");

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    23 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    scanf("%d",&n);printf("Enter burst time for sequences:");for(i=0;i=0){

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    24 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    temp1=st[i]; // temp1 stores the service time of a processst[i]=0; // making service time equals 0

    }sq=sq+temp1; // utilizing temp1 value to calculate turnaround timetat[i]=sq; // turn around time

    } //end of forif(n==count) // it indicates all processes have completed their task because the count valuebreak; // incremented when service time equals 0

    } //end of while

    for(i=0;i

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    25 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    }}return l;

    } // end of nextprocess

    void srtf(int n){int i,j,k,time=0;float tavg,wavg;for(i = 1; i

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    26 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    for(i = 1; i

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    27 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    **********************************Enter number of processes:3Enter burst time for sequences:2433

    Enter time quantum:4Process_no Burst time Wait time Turnaround time

    1 24 6 302 3 4 73 3 7 10

    Avg wait time is 5.666667Avg turnaround time is 15.666667Enter the choice1) Round Robin 2) SRT3) Exit2---SHORTEST REMAINING TIME NEXT---Enter the number of processes: 4Enter the arrival time for process 1: 0Enter the burst time for process 1: 8Enter the arrival time for process 2: 1Enter the burst time for process 2: 4Enter the arrival time for process 3: 2Enter the burst time for process 3: 9Enter the arrival time for process 4: 3Enter the burst time for process 4: 51 24 6 302 3 4 73 3 7 10---SHORTEST REMAINING TIME FIRST---Enter the number of processes: 4Enter the arrival time for process 1: 0Enter the burst time for process 1: 8Enter the arrival time for process 2: 1Enter the burst time for process 2: 4Enter the arrival time for process 3: 2Enter the burst time for process 3: 9Enter the arrival time for process 4: 3Enter the burst time for process 4: 5

    ---SHORTEST REMAINING TIME NEXT---

    Process Arrival Burst Waiting Finishing turnaround Tr/Tbid time time time time time time1 0 8 9 17 17 2.12 1 4 0 5 4 1.0

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    28 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    3 2 9 15 26 24 2.74 3 5 2 10 7 1.4

    tavg=13.000000wavg=6.50000011: Design develop and run a multi-threaded program to generate and print Fibonacci series. Onethread has to generate the numbers up to the specified limit and Another thread has to print them.Ensure proper synchronization.# include# include# include

    int MAX;int Fibonacci(int n){

    int x, y;if (n < 2)return n;else{x = Fibonacci(n - 1);y = Fibonacci(n - 2);return (x + y);}

    }

    int FibonacciTask(int n){

    int x, y;if (n < 2)

    return n;else{

    x = Fibonacci(n - 1);y = Fibonacci(n - 2);return (x + y);

    }}/* random number generation upto 24 */int random_num(){

    int temp;temp = rand();temp = temp%24;MAX = temp;return(MAX);

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    29 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    }

    int main(int argc, char * argv[]){

    int FibNumber[25] = {0};int j, temp,tmp,id,i = 0;int n, tid, nthreads;

    printf("Please Enter the number Range :");scanf("%d",&n);printf("\n");omp_set_num_threads(2);

    //Parallel region# pragma omp parallel{

    printf("The number of threads are %d\n",omp_get_num_threads());# pragma omp for private (tid, tmp, FibNumber)for(j = 1; j

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    30 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    }}

    OUTPUT:lease Enter the number Range : 7The number value is 7:1 1 2 3 5 8 13

    The number value is 22:1 1 2 3 5 8 13 21 34 55 89144 233 377 610 987 1597 2584 4181 6765 10946 17711

    The number value is 9:1 1 2 3 5 8 13 21 34

    The number value is 19:1 1 2 3 5 8 13 21 34 55 89144 233 377 610 987 1597 2584 4181

    The number value is 17:1 1 2 3 5 8 13 21 34 55 89144 233 377 610 987 1597

    The number value is 7:1 1 2 3 5 8 13

    The number value is 10:1 1 2 3 5 8 13 21 34 55

    12: Design, develop and run a program to implement the Bankers Algorithm. Demonstrate itsWorking with different data values.

    #includestruct process

    {int all[6],max[6],need[6],finished,request[6];

    }p[10];int avail[6],sseq[10],ss=0,check1=0,check2=0,n,pid,work[6];int nor,nori;int main(){

    int safeseq(void);int ch,i=0,j=0,k,pid,ch1;int violationcheck=0,waitcheck=0;do{

    printf("\n\n\t 1. Input");printf("\n\n\t 2. New Request");printf("\n\n\t 3. Safe State or Not");printf("\n\n\t 4. print");

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    31 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    printf("\n\n\t 5. Exit");printf("\n\n\t Enter ur choice :");scanf("%d",&ch);switch(ch){

    case 1:printf("\n\n\t Enter number of processes : ");scanf("%d",&n);printf("\n\n\t Enter the Number of Resources : ");scanf("%d",&nor);printf("\n\n\t Enter the Available Resouces : ");for(j=0;j

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    32 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    for(j=0;jp[pid].need[j])violationcheck=1;if(p[pid].request[j]>avail[j])waitcheck=1;

    }if (violationcheck==1)

    printf("\n\n\t The Process Exceeds its Max Need: Terminated");else if(waitcheck==1)

    printf("\n\n\t Lack of Resourcess : Process State Wait");else{

    for(j=0;j

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    33 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    for(j=0;j

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    34 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    printf("P%d,",sseq[tj]);return 1;

    }elseprintf("\n\n\t The system is Not in safe state");return 0;

    }

    OUTPUT:

    1. Input2. New Request3. Safe State or Not4. print5. ExitEnter ur choice :1

    Enter number of processes : 5Enter the Number of Resources : 3Enter the Available Resouces :For Resource type 0 : 10For Resource type 1 : 5For Resource type 2 : 7

    Enter Max and Allocated resources for P 0 :

    Enter the Max of resource 0 : 7

    Allocation of resource 0 :0

    Enter the Max of resource 1 : 5

    Allocation of resource 1 :1

    Enter the Max of resource 2 : 3

    Allocation of resource 2 :0

    Enter Max and Allocated resources for P 1 :

    Enter the Max of resource 0 : 3

    Allocation of resource 0 :2

    Enter the Max of resource 1 : 2

    Allocation of resource 1 :0

    Enter the Max of resource 2 : 2

    Allocation of resource 2 :0

    Enter Max and Allocated resources for P 2 :

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    35 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    Enter the Max of resource 0 : 9

    Allocation of resource 0 :3

    Enter the Max of resource 1 : 0

    Allocation of resource 1 :0

    Enter the Max of resource 2 : 2

    Allocation of resource 2 :2

    Enter Max and Allocated resources for P 3 :

    Enter the Max of resource 0 : 2

    Allocation of resource 0 :2

    Enter the Max of resource 1 : 2

    Allocation of resource 1 :1

    Enter the Max of resource 2 : 2

    Allocation of resource 2 :1

    Enter Max and Allocated resources for P 4 :

    Enter the Max of resource 0 : 4

    Allocation of resource 0 :0

    Enter the Max of resource 1 : 3

    Allocation of resource 1 :0

    Enter the Max of resource 2 : 3

    Allocation of resource 2 :2

    1. Input

    2. New Request

    3. Safe State or Not

    4. print

    5. Exit

    Enter ur choice :3

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    36 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013

    The system is in safe stateP1,P3,P4,P0,P2,

    The System is in safe state

    1. Input

    2. New Request

    3. Safe State or Not

    4. print

    5. Exit

    Enter ur choice :2

    Requesting process id :1

    Number of Request for resource 0 :1

    Number of Request for resource 1 :0

    Number of Request for resource 2 :2

    The system is in safe stateP1,P3,P4,P0,P2,

    Request Committed1. Input2. New Request3. Safe State or Not4. print5. Exit

    Enter ur choice :2

    Requesting process id :2

    Number of Request for resource 0 :2

    Number of Request for resource 1 :2

    Number of Request for resource 2 :3

    The Process Exceeds its Max Need: Terminated

    -------------------------------------------------------- END-----------------------------------------------------

  • 10CSL58 SYSTEM SOFTWARE & OPERATING SYSTEMS LAB MANUAL V SEM CSE

    37 Prepared By: B. Fakruddin , Dept of CSE, HKBKCE 2013