Unix & Os Manual

Embed Size (px)

Citation preview

  • 7/29/2019 Unix & Os Manual

    1/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    1

    JYOTHISHMATHI INSTITUTE OFTECHNOLOGY & SCIENCE

    NUSTULAPUR, KARIMNAGAR

  • 7/29/2019 Unix & Os Manual

    2/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    2

    LAB MANUAL OF

    UNIX & OS LAB (IT)(III B.Tech. II SEM)

  • 7/29/2019 Unix & Os Manual

    3/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    3

    INDEX

    SNO PROGRAM NAME PAGE

    NO

    1 Write a shell script to print the multiplicationtable for the given number.

    1

    2 Write a shell script that copies multiple filesinto a directory.

    2

    3 Write a shell script to find no. of words andcharacters in a given file.

    3

    4 Write a shell script to display all files in agiven directory.

    4

    5 Write a shell script to perform simple calculator. 5

    6 Write a C program to count no.of blanks,charactersa) Using standard i/o function. b) Using system

    calls.

    6-7

    7 Write a C program to illustrate the followingCommand using system Calls a) cat b) ls c)

    mv

    8-10

    8 Write a C program to illustrate the stat systemcall.

    11

    9 Write a C program that illustrates the creation ofchild process using fork() system call.

    12

    10 Write a C program that illustrates file locking. 13-14

    11 Write a C program that implements producerconsumer problem using semaphore system calls.

    15-16

    12 Write a C program to illustrate inter processcommunication using shared memory system calls.

    17-18

    13 Write a C program to (a) create message queue(b) write to message queue (c) read from

    message queue

    19-20

  • 7/29/2019 Unix & Os Manual

    4/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    4

    O.S. PROGRAMMES

    S.NO PROGRAM NAME PAGE

    NO

    1 Write a C program for ROUND ROBIN CPU schedulingalgorithm

    20-21

    2 Write a C program for SJF CPU scheduling algorithm 22-23

    3 Write a C program for FCFS CPU schedulingalgorithm

    24

    4 Write a C Program for priority CPU schedulingalgorithm.

    25-26

    5 Write a C Program for sequential file allocation. 27-28

    6 Program for indexed file allocation strategy. 29-30

    7 Program for linked file allocation strategy. 31-32

    8 Write a C Program for MVT first fit. 33

    9 Write a C Program for MFT . 34

    10 Write a C Program for MVT best fit. 35-3611 Program for bankers algorithm 37-39

    12 Write a C program for FIFO page allocationalgorithm.

    40-41

    13 Write a C program for LRU page replacementalgorithm.

    42-44

  • 7/29/2019 Unix & Os Manual

    5/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    5

    Program 1:Program 1:Program 1:Program 1:

    AIM:AIM:AIM:AIM:Write a shell script to print the multiplication table for theWrite a shell script to print the multiplication table for theWrite a shell script to print the multiplication table for theWrite a shell script to print the multiplication table for thegiven number.given number.given number.given number.

    Algorithm:Algorithm:Algorithm:Algorithm:

    1.Start.

    2.Read n.

    3.i=1.

    4.f = n * i.

    5.i = i + 1.

    6.Display f.

    7.Repeat 4,5,6 steps until i = 10.

    8.End.

    Source Code:Source Code:Source Code:Source Code:

    #! /bin/sh

    echo enter the number

    read n

    for i in 1 2 3 4 5 6 7 8 9 10

    do

    x= `expr $n \* $i`

    done

    Input:Input:Input:Input:

    enter the number

    6

    Output:Output:Output:Output:

    6 * 1 = 6

    6 * 2 = 12

  • 7/29/2019 Unix & Os Manual

    6/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    6

    6 * 3 = 18

    6 * 4 = 246 * 5 = 30

    6 * 6 = 366 * 7 = 42

    6 * 8 = 486 * 9 = 54

    6 * 10 = 60

    Program 2:Program 2:Program 2:Program 2:

    AIM:AIM:AIM:AIM:Write a shell script that copies multiple files into a directory.Write a shell script that copies multiple files into a directory.Write a shell script that copies multiple files into a directory.Write a shell script that copies multiple files into a directory.

    Algorithm:Algorithm:Algorithm:Algorithm:

    1.Start.

    2.Read *.c files into i.

    3.Copy $i to the root directory.

    4.Repeat 2,3 steps until all values of $i..

    5.End.

    Source Code:Source Code:Source Code:Source Code:

    #! /bin/sh

    for i in `ls *.c`

    docp $i /root

    done

    echo file are copied into root

    Output:Output:Output:Output:file are copied into root

    Program 3 :Program 3 :Program 3 :Program 3 :

    AIM:AIM:AIM:AIM:Write a shell script to find no. of words and characters in aWrite a shell script to find no. of words and characters in aWrite a shell script to find no. of words and characters in aWrite a shell script to find no. of words and characters in agiven file.given file.given file.given file.

    Algorithm:Algorithm:Algorithm:Algorithm:

    1. Start.

  • 7/29/2019 Unix & Os Manual

    7/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    2. cc = 0,w=0.3. give file name as commandline argument (i.e $1).4. for i in `cat $1`.5. w = w + 1.6. c = expr $i : *.

    7. cc = cc + c.8. Repeat 4,5,6,7 steps until eof.9. End.

    Source Code:Source Code:Source Code:Source Code:

    # /bin/sh

    w=0

    cc=0

    for i in cat $1do

    j= $i

    echo $j

    w=`expr $w + 1`

    c=`expr $j:.*`

    cc = `expr $cc + $c`

    done

    echo no.of characters $cc

    echo no.of words $w

    Input:Input:Input:Input:../a.out sun

    Output:Output:Output:Output:

    no. of characters 56

    no. of words 11

  • 7/29/2019 Unix & Os Manual

    8/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    8

    Program 4:Program 4:Program 4:Program 4:

    AIM:AIM:AIM:AIM:Write a shell script to display all files in a given directory.Write a shell script to display all files in a given directory.Write a shell script to display all files in a given directory.Write a shell script to display all files in a given directory.

    Algorithm:Algorithm:Algorithm:Algorithm:1.Start.

    2.Read i value from ls sss.

    3.Display i value .

    4.Repeat above 2 steps until end of directory.

    5.End.

    Source Code:Source Code:Source Code:Source Code:

    #! /bin/sh

    for i in `ls sss`

    do

    echo $i

    done

    Output:Output:Output:Output:abc.txt

    ss.c

  • 7/29/2019 Unix & Os Manual

    9/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    9

    Program 5:Program 5:Program 5:Program 5:

    AIM:AIM:AIM:AIM:

    Write a shell script to perform simple calculator.Write a shell script to perform simple calculator.Write a shell script to perform simple calculator.Write a shell script to perform simple calculator.

    Algorithm:Algorithm:Algorithm:Algorithm:

    1.Start

    2.Read a and b

    3.Read op

    4.Depending on value of operator perform case

    Operation.

    5.End

    Source Code:Source Code:Source Code:Source Code:

    #! /bin/sh

    echo enter the value for a

    read a

    echo enter the value for b

    read b

  • 7/29/2019 Unix & Os Manual

    10/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    10

    echo enter operator

    read op

    case $op in

    +) c=`expr $a + $b`;;

    -) c = `expr $a -$b`;;

    \*) c = `expr $a \* $b`;;/) c = `expr $a / $b ;;

    esac

    echo $c

    Input:Input:Input:Input:

    enter the value for a

    3

    enter the value for b

    6enter the operator

    *

    Output:Output:Output:Output:

    18

    Program 6a:Program 6a:Program 6a:Program 6a:AIM:AIM:AIM:AIM:Write a C program to count no. of blanks, characters, linesWrite a C program to count no. of blanks, characters, linesWrite a C program to count no. of blanks, characters, linesWrite a C program to count no. of blanks, characters, linesusing standard i/o function.using standard i/o function.using standard i/o function.using standard i/o function.

    Algorithm:Algorithm:Algorithm:Algorithm:1. Start.2. open the file using fopen( ) function in r mode3. ch=fgetc(fp) (to read character by character)4. if ch = or \n

    b=b+1.

    5. if ch = \n

    l=l+1.6. c=c+1.7. Repeat 3,4,5&6 steps until ch = eof8. End

    Source Code:Source Code:Source Code:Source Code:#include

    int main( )

    {

  • 7/29/2019 Unix & Os Manual

    11/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    11

    file *fp:

    int b=0,nl=0,c=0;

    char ch;

    fp=fopen(text.txt,r);

    while(ch!=eof)

    {ch=fgetc(fp);

    if(ch== )

    b++;

    if(ch==\n)

    nl++;

    c++;

    }

    printf(no.of blanks %d,b);

    printf(no.of lines %d,nl);

    printf(no.of characters %d,c);

    }

    Input:Input:Input:Input:./a.out sss.txt

    Output:Output:Output:Output:

    no.of blanks 5

    n.of lines 2

    no.of characters 36

    Program 6b:Program 6b:Program 6b:Program 6b:

    AIM:AIM:AIM:AIM:Write a C program to count no. of blanks, characters, linesWrite a C program to count no. of blanks, characters, linesWrite a C program to count no. of blanks, characters, linesWrite a C program to count no. of blanks, characters, linesusing system calls.using system calls.using system calls.using system calls.

    Algorithm:Algorithm:Algorithm:Algorithm:1. Start.2. open the file using open( ) system call in O_RDONLY3. rc=read(fd,buf,5) (to read characters )

    4. if ch = or \nw=w+1.

    5. if ch = \nl=l+1.

    6. c=c+1.7. Repeat 3,4,5&6 steps until ch = eof8. End

  • 7/29/2019 Unix & Os Manual

    12/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    12

    Source Code:Source Code:Source Code:Source Code:#include

    int main( )

    {

    int fd:

    int b=0,nl=0,c=0;char ch[1];

    fd=open(text.txt,O_RDONLY);

    while((rc=read(fd,ch,1))>0)

    {

    if(ch== )

    b++;

    if(ch==\n)

    nl++;

    c++;

    }

    printf(no.of blanks %d,b);printf(no.of lines %d,nl);

    printf(no.of characters %d,c);

    }

    Input:Input:Input:Input:./a.out sss.txt

    Output:Output:Output:Output:no. of blanks 5

    no. of lines 2no. of characters 36

    Program 7a:Program 7a:Program 7a:Program 7a:

    AIM:AIM:AIM:AIM:Write a C program to illustrate the mv command usingWrite a C program to illustrate the mv command usingWrite a C program to illustrate the mv command usingWrite a C program to illustrate the mv command usingsystem Callssystem Callssystem Callssystem Calls

    Algorithm:Algorithm:Algorithm:Algorithm:1. open one existed file and one new open file using open( )

    system call

    2. read the contents from keyboard using read( )3. write these contents into file using write()4. repeat 2,3 steps until eof5. close 2 file using fclose( ) system call

    6. delete existed file using using unlink( ) system

  • 7/29/2019 Unix & Os Manual

    13/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    13

    Source Code:Source Code:Source Code:Source Code:

    #include

    #include

    #includeint main()

    {

    int fd,fd1,rc;

    char ch[5];

    fd1=open(sss,O_WRONLY | O_CREATE);

    while((rc=read(stdin,ch,5))>0)

    write(fd1,ch,rc);

    close fd1;

    fd1=open(sss,O_RDONLY);

    while((rc=read(fd1,ch,5))>0)

    write(stdout,ch,rc);close fd1;

    }

    Input:Input:Input:Input:hai hello

    A friend in need is a friend in deed

    ^z

    Output:Output:Output:Output:

    hai hello

    A friend in need is a friend in dee

    Program 7b :Program 7b :Program 7b :Program 7b :

    AIM:AIM:AIM:AIM:Write a program to illustrate ls command using system callsWrite a program to illustrate ls command using system callsWrite a program to illustrate ls command using system callsWrite a program to illustrate ls command using system calls

    Algorithm:Algorithm:Algorithm:Algorithm:

    1. Start.2. open directory using opendir( ) system call.3. read the directory using readdir( ) system call.4. print dp.name and dp.inode .5. repeat above step until end of directory.6. End

  • 7/29/2019 Unix & Os Manual

    14/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    14

    Source Code:Source Code:Source Code:Source Code:

    #include

    #include

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

    dir *dp;

    struct dirent *d;

    if(((dp=opendir(sss)))==null)

    printf(cannodt open\n);

    while((d=readdir(dp)!=null))

    {

    printf(%s\t,d->d_name);

    printf(%d\n,d->d_ino);

    }

    closedir(dirp);exit(0);

    }

    output:output:output:output:

    mul.sh 12344

    division.c 12345

    process.c 12346

    Program 7c:Program 7c:Program 7c:Program 7c:

    AIM:AIM:AIM:AIM:Write a C program to illustrate the mv command usingWrite a C program to illustrate the mv command usingWrite a C program to illustrate the mv command usingWrite a C program to illustrate the mv command usingsystem calls.system calls.system calls.system calls.

    Algorithm:Algorithm:Algorithm:Algorithm:

    1. Start2. open an existed file and one new open file using open()

  • 7/29/2019 Unix & Os Manual

    15/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    15

    system call

    3. read the contents from existed file using read( ) systemcall

    4. write these contents into new file using write systemcall using write( ) system call

    5. repeat above 2 steps until eof6. close 2 file using fclose( ) system call

    7. delete existed file using using unlink( ) system8. End.

    Source Code:Source Code:Source Code:Source Code:

    #include

    #include

    #include

    int main()

    {int fd,fd1,rc;

    char ch[5];

    fd=open(sss,O_RDONLY );

    fd1= open(rrr,O_WRONLY | O_CREATE);

    while((rc=read(fd,ch,5))>0)

    write(fd1,ch,rc);

    close fd1;

    close fd;

    unlink(fd);

    printf( file is copied );

    }

    Output:Output:Output:Output:

    file is copied

    Program 8:Program 8:Program 8:Program 8:

    AIM:AIM:AIM:AIM:Write a C program to illustrate the stat system callsWrite a C program to illustrate the stat system callsWrite a C program to illustrate the stat system callsWrite a C program to illustrate the stat system calls

    Algorithm:Algorithm:Algorithm:Algorithm:1. Declare s and st of type struct stat.2. Use stat system call by specifying sss.c file

  • 7/29/2019 Unix & Os Manual

    16/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    16

    3. stat returns s (s may be 0 or -1)4. if s

  • 7/29/2019 Unix & Os Manual

    17/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    17

    Algorithm:Algorithm:Algorithm:Algorithm:

    1. Start2. Declare pid3. create new process using fork( ) system call4. If pid!=0 then5. Display parent process getpid(),getppid().6. Else7. Display child process getpid().getppid().8. End

    Source code:Source code:Source code:Source code:

    #include

    int main( )

    {printf(original process with pid %d ppid %d\n,

    getpid() ,getppid());

    pid=fork();

    if(pid!=0)

    printf(parent process with pid %d ppid %d \n,

    getpid(),getppid());

    else

    {

    sleep(5);

    printf(child process with pid %d ppid %d\n,

    getpid(),getppid());}

    printf( pid %d terminates ,getpid());

    }

    Output:Output:Output:Output:

    original process with pid 3456 and ppid 3525

    child process with pid 3457 and ppid 3456

    pid 3457 terminates

    parent process with pid 3456 and ppid 3525pid 3456 terminates

    Program 10:Program 10:Program 10:Program 10:

    AIM:AIM:AIM:AIM:Write a C program that illustrates file locking.Write a C program that illustrates file locking.Write a C program that illustrates file locking.Write a C program that illustrates file locking.

  • 7/29/2019 Unix & Os Manual

    18/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    18

    AlAlAlAlgorithm:gorithm:gorithm:gorithm:

    1. Start2. Flock is predefined data structure for locking

    techniques.

    3. Opening rr.txt in read and write mode.4. l_type is read lock5. By pressing return it reads that character through

    getchar() function.

    6. It gets the lock.7. Next we are sending unlock type into l_type.8. By pressing return it gets unlocked.

    9. End

    Source Code:Source Code:Source Code:Source Code:

    #include

    #include

    #include

    #include

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

    {

    struct flock f1={f_wrlck,seek_set,0,0,0);

    int fd;

    f1.l_type=f_rdlck;

    if((fd=open(rr.txt,o_rdwr))==-1)

    {

    perror(open);

    exit(1);}

    printf(press to try to get lock:);

    getchar();

    printf(trying to get lock):

    if(fnctl(fd,f_setlkw,&f1)==-1)

    {

    perror(fcntl);

    exit(1);

    }

    printf(got lock \n);

    printf(press to release lock:);getchar( );

    f1.l_type=f_unlck;

    if(fcntl(fd,f_setlk,&f1)==-1)

    {

    perror(fcntl);

    exit(1);

    }

  • 7/29/2019 Unix & Os Manual

    19/52

  • 7/29/2019 Unix & Os Manual

    20/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    20

    Program 11:Program 11:Program 11:Program 11:

    AIM:AIM:AIM:AIM:Write a C program that implements producer consumerWrite a C program that implements producer consumerWrite a C program that implements producer consumerWrite a C program that implements producer consumerproblem using semaphore system callsproblem using semaphore system callsproblem using semaphore system callsproblem using semaphore system calls

    Algorithm:Algorithm:Algorithm:Algorithm:

    1. Start2. create semaphore using semget( ) system call3. if successful it returns positive value4. create two new processes5. first process will produce

    6. until first process produces second process cannotconsume

    7. End.

    Source code:Source code:Source code:Source code:

    #include

    #include

    #include

    #include

    #include

    #include#define num_loops 2

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

    {

    int sem_set_id;

    int child_pid,i,sem_val;

    struct sembuf sem_op;

    int rc;

    struct timespec delay;

    clrscr();

    sem_set_id=semget(ipc_private,2,0600);if(sem_set_id==-1)

    {

    perror(main:semget);

    exit(1);

    }

    printf(semaphore set created,semaphore setid%d\n ,

    sem_set_id);

  • 7/29/2019 Unix & Os Manual

    21/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    21

    child_pid=fork();

    switch(child_pid)

    {

    case -1:

    perror(fork);

    exit(1);

    case 0:

    for(i=0;i

  • 7/29/2019 Unix & Os Manual

    22/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    22

    consumer:1

    Program 12:Program 12:Program 12:Program 12:

    AIM:AIM:AIM:AIM:Write a C program to illustrate inter process communicationWrite a C program to illustrate inter process communicationWrite a C program to illustrate inter process communicationWrite a C program to illustrate inter process communicationusing shared memory system calls.using shared memory system calls.using shared memory system calls.using shared memory system calls.

    Algorithm:Algorithm:Algorithm:Algorithm:

    1. Start2. create shared memory using shmget( ) system call3. if success full it returns positive value4. attach the created shared memory using shmat( ) system

    call

    5. write to shared memory using shmsnd( ) system call6. read the contents from shared memory using shmrcv( )

    system call

    7. End .

    Source Code:Source Code:Source Code:Source Code:

    #include

    #include

    #include

    #include

    #include

    #include

    #define shm_size 1024

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

    {

    key_t key;

    int shmid;

    char *data;

    int mode;

    if(argc>2)

    {fprintf(stderr,usage:stdemo[data_to_writte]\n);

    exit(1);

    }

    if((shmid=shmget(key,shm_size,0644/ipc_creat))==-1)

    {

    perror(shmget);

    exit(1);

  • 7/29/2019 Unix & Os Manual

    23/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    23

    }

    data=shmat(shmid,(void *)0,0);

    if(data==(char *)(-1))

    {

    perror(shmat);

    exit(1);}

    if(argc==2)

    printf(writing to segment:\%s\\n,data);

    if(shmdt(data)==-1)

    {

    perror(shmdt);

    exit(1);

    }

    return 0;

    }

    Input:Input:Input:Input:

    #./a.out swarupa

    Output:Output:Output:Output:

    writing to segment swarupa

  • 7/29/2019 Unix & Os Manual

    24/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    24

    Program 13:Program 13:Program 13:Program 13:

    AIM:AIM:AIM:AIM:Write a C program toWrite a C program toWrite a C program toWrite a C program to

    ( a ) create message queue( a ) create message queue( a ) create message queue( a ) create message queue( b ) write to message queue( b ) write to message queue( b ) write to message queue( b ) write to message queue( c ) read from message queue( c ) read from message queue( c ) read from message queue( c ) read from message queue

    Algorithm:Algorithm:Algorithm:Algorithm:1. Start2. create message queue using msgget( ) system call3. while creating message queue it returns id into file

    descriptor

    4. print the message queue id5. if successful rite into message queue using msgsnd()

    system call

    6. read the contents from message queue using msgrcv( )system call

    7. End.

    Source Code:Source Code:Source Code:Source Code:

    #include

    #include

    #include

    #include

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

    {

    int q_id;

    if(q_id=msgget(ipc_private,0600)==-1)perror(msgget);

    struct msgbuf

    {

    long mtype;

    char mtext[20];

    }

    struct msgbuf* msg;

  • 7/29/2019 Unix & Os Manual

    25/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    25

    struct msgbuf* recv_msg;

    int rc;

    printf(message queue created %d\n,q_id);

    msg=(struct msgbuf*)malloc(sizeof(struct msgbuf) +

    strlen(hello world));

    msg->mtype=1;strcpy(msg->mtext,helloworld);

    free(msg);

    printf(message placed on queue successfully\n);

    recv_msg=(struct msgbuf*)malloc(sizeof(struct msgbuf)+

    strlen(hello world));

    if(rc==-1)

    {

    perror(main:msgrcv);

    exit(1);

    }

    printf(msgrcv:received message:\nmtype%d\n; mtext%s\n,recv_msg->mtype,recv_msg->mtext);

    return 0;

    }

    Output:Output:Output:Output:message queue created 0

    message placed on the queue successfully

    msgrcv:received message:

    mtype: 0

    mtext: hello world

  • 7/29/2019 Unix & Os Manual

    26/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    26

    LAB MANUAL OFLAB MANUAL OFLAB MANUAL OFLAB MANUAL OF

    OPERATING SYSTEM LABOPERATING SYSTEM LABOPERATING SYSTEM LABOPERATING SYSTEM LAB

  • 7/29/2019 Unix & Os Manual

    27/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    27

    Program 1:Program 1:Program 1:Program 1:

    AIM:AIM:AIM:AIM:Write a C program for ROUND ROBIN CPU scheduling algorithm.Write a C program for ROUND ROBIN CPU scheduling algorithm.Write a C program for ROUND ROBIN CPU scheduling algorithm.Write a C program for ROUND ROBIN CPU scheduling algorithm.

    Source Code:Source Code:Source Code:Source Code:

    #include

    main()

    {

    int s[10],p[10],n,i,j,wi=0,w[10],t[10], st[10],tq,tst=0;

    int tt=0,tw=0;

    float aw at;printf("enter no.of process");

    scanf("%d",&n);

    printf("\n enter time quanum");

    scanf("%d",&tq);

    printf("\n enter process&service time");

    for(i=0;i

  • 7/29/2019 Unix & Os Manual

    28/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    28

    for(i=0;i

  • 7/29/2019 Unix & Os Manual

    29/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    29

    2

    Output:Output:Output:Output:process st wt tt

    1 4 4 82 6 6 12

    3 2 4 6

    Awt = 4.000000

    att = 8.000000

    Program 2:Program 2:Program 2:Program 2:

    AIM:AIM:AIM:AIM:Write a C program for SJF CPU scheduling algorithmWrite a C program for SJF CPU scheduling algorithmWrite a C program for SJF CPU scheduling algorithmWrite a C program for SJF CPU scheduling algorithm

    Source Code:Source Code:Source Code:Source Code:

    #include

    main()

    {

    int i,j,bt[10],n,pt[10],wt[10],tt[10],t,k,l,w1=0,t1=0;

    float at,aw;printf(enter no of jobs);

    scanf(%d,&n);

    printf(enter burst time);

    for(i=0;i

  • 7/29/2019 Unix & Os Manual

    30/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    30

    if(bt[i]

  • 7/29/2019 Unix & Os Manual

    31/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    31

    aw=10.75000

    at=22.000000

    Program 3:Program 3:Program 3:Program 3:

    AIM:AIM:AIM:AIM:Write a C program for FCFS CPU scheduling algorithmWrite a C program for FCFS CPU scheduling algorithmWrite a C program for FCFS CPU scheduling algorithmWrite a C program for FCFS CPU scheduling algorithm

    Source Code:Source Code:Source Code:Source Code:include

    main()

    {

    int i,j,bt[10],n,pt[10],wt[10],tt[10],t,k,l,w1=0,t1=0;

    float at,aw;

    printf(enter no of jobs);

    scanf(%d,&n);

    printf(enter burst time);

    for(i=0;i

  • 7/29/2019 Unix & Os Manual

    32/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    32

    for(i=0;i

  • 7/29/2019 Unix & Os Manual

    33/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    33

    scanf(%d,&n);

    printf(enter burst time);

    for(i=0;i

  • 7/29/2019 Unix & Os Manual

    34/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    34

    2

    13

    Output:Output:Output:Output:

    Bt priority wt tt

    4 1 0 4

    2 2 4 67 3 6 13

    10 4 13 23

    aw=5.750000at=12.500000

    Program 5:Program 5:Program 5:Program 5:

    AIM:AIM:AIM:AIM:Write a C Program for sequential file allocation.Write a C Program for sequential file allocation.Write a C Program for sequential file allocation.Write a C Program for sequential file allocation.

    Source Code:Source Code:Source Code:Source Code:

    #include

    #include

    main()

    {

  • 7/29/2019 Unix & Os Manual

    35/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    35

    int f[50],i,st,j,len,c,k,count=0;

    for(i=0;i

  • 7/29/2019 Unix & Os Manual

    36/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    36

    4 1

    5 1

    6 1

    7 1

    8 1

    file is allocated to disk

    if u want to enter more files(y-1/n-0)

    0

    Program 6:Program 6:Program 6:Program 6:

    AIM:AIM:AIM:AIM:Write a C Program for indexed file allocation strategy.Write a C Program for indexed file allocation strategy.Write a C Program for indexed file allocation strategy.Write a C Program for indexed file allocation strategy.

    Source Code:Source Code:Source Code:Source Code:

    #include

    #include

    main()

    {

    int f[50],i,k,j,index[50],n,c,count=0;

  • 7/29/2019 Unix & Os Manual

    37/52

  • 7/29/2019 Unix & Os Manual

    38/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    38

    4

    5

    6

    7

    8

    Output:Output:Output:Output:

    Allocated

    file indexed

    4->5:1

    4->6:1

    4->7:1

    4->8:1

    index is already allocated

    if u enter one more block(1/0)

    0

    Program 7:Program 7:Program 7:Program 7:

    AIM:AIM:AIM:AIM:Write a C Program for linked file allocation strategy.Write a C Program for linked file allocation strategy.Write a C Program for linked file allocation strategy.Write a C Program for linked file allocation strategy.

    Source Code:Source Code:Source Code:Source Code:#include

    #include

    main()

  • 7/29/2019 Unix & Os Manual

    39/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    39

    {

    int f[50],p,i,j,k,a,st,len,n;

    for(i=0;i

  • 7/29/2019 Unix & Os Manual

    40/52

  • 7/29/2019 Unix & Os Manual

    41/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    41

    main()

    {

    int i,j,t1=0,k,n;

    int p[10],h[10];

    static int t[10];

    printf(enter no of blocks);scanf(%d,&n);

    printf(enter block sizes);

    for(j=0;j

  • 7/29/2019 Unix & Os Manual

    42/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    42

    Source Code:Source Code:Source Code:Source Code:

    #include

    #include

    main( )

    {int a[10],b[10],c[10],i,j,p,s,n,t=0;

    printf(enter no of process);

    scanf(%d,&n);

    printf(enter size of each process);

    for(i=0;i

  • 7/29/2019 Unix & Os Manual

    43/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    43

    Source Code:Source Code:Source Code:Source Code:#include

    #include

    main()

    {

    int n,d,p[10],b[10],i,j,ts;printf(enter no of blocks);

    scanf(%d,&d);

    printf(enter size of block);

    for(i=0;i

  • 7/29/2019 Unix & Os Manual

    44/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    44

    enter size of block

    43

    43

    21

    enter no of process

    3enter size of each process

    32

    40

    20

    Output:Output:Output:Output:

    total fragmentation 15

  • 7/29/2019 Unix & Os Manual

    45/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    45

    Program 11:Program 11:Program 11:Program 11:

    AIM:AIM:AIM:AIM:Program for bankers algorithmProgram for bankers algorithmProgram for bankers algorithmProgram for bankers algorithm

    Source Code:Source Code:Source Code:Source Code:

    #include

    #include

    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

  • 7/29/2019 Unix & Os Manual

    46/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    46

    for(j=0;j

  • 7/29/2019 Unix & Os Manual

    47/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    4

    Input:Input:Input:Input:

    enter no.of resources

    3

    enter the max no .of resources for each type

    10 5 7

    enter the no .of process5

    enter allocation of resources

    0 1 0 2 0 0 3 0 2 2 1 1 0 0 2

    Output:Output:Output:Output:

    total available resources after allocation

    3 3 2

    enter the max resources for every process

    7 5 3 3 2 2 9 0 2 2 2 2 4 3 3

    needed resources for every process to start execution

    7 4 31 2 2

    6 0 0

    0 1 1

    4 3 1

    Safe sequence ,the sequence of process to complete their

    execution

    Procee 2 execution started & completed

    Procee 4 execution started & completed

    Procee 5 execution started & completed

    Procee 1 execution started & completed

    Procee 3 execution started & completed

  • 7/29/2019 Unix & Os Manual

    48/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    48

    Program 12:Program 12:Program 12:Program 12:

    AIM:AIM:AIM:AIM:

    Write a C program for FIFO page allocation algorithm.Write a C program for FIFO page allocation algorithm.Write a C program for FIFO page allocation algorithm.Write a C program for FIFO page allocation algorithm.

    Source Code:Source Code:Source Code:Source Code:

    #include

    #include

    main()

    {

    int a[10],b[5],n,t,i,c=0,k=0,j=0,m,x;

    printf("\nenter no of requests");

    scanf("%d",&n);

    printf("\nenter no of frames");

    scanf("%d",&t);

    printf("enter requests one by one");

    for(i=0;i

  • 7/29/2019 Unix & Os Manual

    49/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    49

    c++;

    b[j]=a[i];

    j++;

    if(j==t)

    j=0;

    }}

    printf("no of pagefaults=%d",c);

    getch( );

    }

    Input:Input:Input:Input:

    enter no of requests

    13

    enter no of frames

    3enter requests one by one

    2

    5

    3

    2

    0

    1

    3

    5

    4

    22

    3

    4

    Output:Output:Output:Output:

    no of pagefaults

    6

  • 7/29/2019 Unix & Os Manual

    50/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    50

    Program 13:Program 13:Program 13:Program 13:AIM:AIM:AIM:AIM:

    Write a C program for LRU page replacement algorithm.Write a C program for LRU page replacement algorithm.Write a C program for LRU page replacement algorithm.Write a C program for LRU page replacement algorithm.

    Source Code:Source Code:Source Code:Source Code:

    #include#include

    main()

    {

    int a[50],b[40],c[15],n,f,i,y,s,p=0,k=0,l=0,m,x,g;

    printf("\nenter no of requests");

    scanf("%d",&n);

    printf("\nenter no of frames");

    scanf("%d",&f);

    printf("enter requests one by one");

    for(i=0;i

  • 7/29/2019 Unix & Os Manual

    51/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    51

    printf("%4d",b[x]);

    printf("---------");

    for(x=0;x0;g--)

    for(x=0;x

  • 7/29/2019 Unix & Os Manual

    52/52

    JYOTHISHMATHI INSTITUTE OF TECHNOLOGY & SCIENCE

    Input:Input:Input:Input:enter no of requests

    13

    enter no of frames3

    enter requests one by one

    2 5 3 2 0 1 3 5 4 2 2 3 4

    Output:Output:Output:Output:

    3 2 5 3 ------------ 2 5 3

    2 2 5 3 ------------ 2 5 3

    0 2 5 3 ------------ 2 0 3

    1 2 0 3 ------------ 2 0 13 2 0 1 ------------ 2 0 1

    5 2 0 1 ------------ 2 5 1

    4 2 5 1 ------------ 2 5 4

    2 2 5 4 ------------ 2 5 4

    2 2 5 4 ------------ 2 5 4

    3 2 5 4 ------------ 2 3 4

    4 2 3 4 ------------ 2 3 4

    No of pagefaults=7