0% found this document useful (0 votes)
5 views

Operating System Lab Manual

The document provides a comprehensive guide on installing the Windows operating system, detailing steps such as checking hardware compatibility, using genuine installation media, and configuring BIOS settings. It also covers the installation process, including partition selection and post-installation configuration, as well as long-term maintenance tips for Windows. Additionally, it briefly outlines basic Unix commands for file handling and directory management.

Uploaded by

guru99prasath752
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Operating System Lab Manual

The document provides a comprehensive guide on installing the Windows operating system, detailing steps such as checking hardware compatibility, using genuine installation media, and configuring BIOS settings. It also covers the installation process, including partition selection and post-installation configuration, as well as long-term maintenance tips for Windows. Additionally, it briefly outlines basic Unix commands for file handling and directory management.

Uploaded by

guru99prasath752
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 111

EX NO: 1A

INSTALLATION OF WINDOWS OPERATING SYSTEM


DATE: CASE STUDY

AIM:
To know how to install the windows operating system

INTRODUCTION:
Each version of Microsoft Windows is installed on a computer using similar steps. While
there are steps in the installation process that differ between versions of Windows, the following
general steps and guidelines help you install Windows on your computer. The steps below are for all
recent versions of Windows, including Windows 98, Windows ME, Windows 2000, Windows
XP, Windows Vista, Windows 7, Windows 8, Windows 10, and Windows 11. These steps even
work for earlier versions (e.g., Windows 95) as long as you use the disc version. The floppy diskette
version is similar, but it requires additional steps.

CHECK HARDWARE COMPATIBILITY


Before installing or upgrading Windows on your computer, check the hardware in the
computer to make sure it's compatible with that version of Windows. Microsoft provides a Windows
Compatible Products List for checking if the hardware in your computer is compatible with the
chosen version of Windows.
If one or more pieces of hardware is not compatible with the chosen Windows version, we
recommend replacing that hardware with compatible hardware or purchasing a new computer.
Having compatible hardware in your computer helps ensure the Windows install or upgrade process
is successful.

GENUINE WINDOWS CD, DVD, OR USB THUMB DRIVE


First, you need a genuine copy of the Microsoft Windows operating
system installation CD, DVD, or USB thumb drive. A genuine Windows product key is included
with the installation disc, which is required to activate Windows after installation. If you have
an OEM (original equipment manufacturer) computer, the Windows product key is often on the back
or side of the computer.
If you have an OEM computer (e.g., Acer, Dell, HP, etc.), the computer will not have a
genuine Windows CD, DVD, or USB thumb drive. Instead, you would reinstall Windows and the
software using a hidden partition or a set of restore discs. The steps mentioned on this page would
still work, but you'd need a copy of Windows. You can borrow a friend's Windows disc, as long as
it's the same version of Windows that came with the computer and have a product key.

HOW TO ENTER AND EXIT THE BIOS OR CMOS SETUP


Every computer provides a way to enter the BIOS or CMOS setup, which lets you configure
some basic settings for your computer and its hardware components.
Below is a list of common methods for accessing and exiting your computer's BIOS or CMOS setup
and recommendations if you're having trouble.

ACCESS BIOS OR CMOS ON NEWER COMPUTERS:


Computers manufactured in the last few years allow you to enter the BIOS or CMOS setup by
pressing one of the five keys listed below during the boot process.
 F1
 F2
 F10
 Delete or Del
 Esc

1
* If pressing F2 opens a diagnostics tool, your setup key is likely F10.
* F10 is also used for the boot menu. If pressing F10 opens a boot menu, your setup key is likely F2.
Setup keys are to be pressed as the computer is booting up. Most users see a message similar
to the example below upon startup. Some older computers may also display a flashing block of text
to indicate when to press F1 or F2.
Press F2 to enter BIOS setup.Once you have successfully entered the CMOS setup, a screen
similar to the example below appears. Your CMOS setup may look different, depending on the
manufacturer, but it should still share a lot of the same options and information.

HOW DO I CHANGE AND SAVE CHANGES IN CMOS SETUP


Once in CMOS setup, the method for changing the settings often depends on the BIOS
manufacturer. You may use the arrow keys and the Enter key to select categories and change their
values. Some manufacturers may have you press the Page up and Page down keys to change the
values.
If you're trying to change the clock, speed, or other settings and don't have the option
available, the motherboard doesn't support it. If you believe it should be supported, you may need a
BIOS update.

HOW DO I SAVE THE CHANGES:


If any changes are made, you need to save those changes, which is usually done by pressing
the F10 key on the keyboard. If F10 doesn't work, look at the bottom or top of the screen for the key
that's used to save the settings.

ACCESS BIOS OR CMOS ON OLDER COMPUTERS:


Unlike today's computers, older computers (before 1995) had numerous methods of entering
the BIOS setup. Below is a listing of key sequences to press as the computer boots to enter the BIOS
setup.
 Ctrl+Alt+Esc
 Ctrl+Alt+Insert
 Ctrl+Alt+Enter
 Ctrl+Alt+S
 Page Up
 Page Down

Acer BIOS:
If your Acer computer cannot boot or you want to restore the BIOS to its original settings,
press and hold the F10 as you turn on the computer. While holding F10, two beeps should be heard
to indicate the settings are restored.
AMI BIOS:
Older AMI BIOS could be restored to bootable settings by pressing and holding ,Insert as the
computer is booting.
BIOS or CMOS diskettes:
Early 486, 386, and 286 computers required a floppy disk to enter the BIOS setup. These
diskettes may be called ICU, BBU, or SCU disks. Because these diskettes are unique to your
computer manufacturer, you must obtain the diskettes from them. See the computer manufacturers
list for contact information.
Access BIOS on early IBM computers:
Some early IBM computers require you to press and hold both mouse buttons as the
computer boots to enter the BIOS setup.
Additional suggestions for accessing BIOS or CMOS:
Finally, if none of the above suggestions allow access to the setup, try generating a stuck key
error, which gives an option to enter the BIOS or CMOS setup. To do this, press and hold any key
on the keyboard, and do not let go (you may get several beeps as you are doing this). Keep pressing
the key until the computer stops booting, and you have the option to enter setup. If this does not
work, make sure your keyboard is working. 2
HOW TO EXIT THE BIOS OR CMOS:
There are several ways to exit the BIOS or CMOS setup depending on the computer's type. The
most common methods include the following.
 Press the Esc key to exit without saving any changes.
 Press the F10 or F12 key to save changes and exit.
 Access the Exit or Save & Exit tab in setup and select the Exit or Save and Exit option.
If you have trouble exiting the BIOS or CMOS setup, you can try the following methods to fix the
problem.
 Press the F9 key to load default settings and press F10 to save and exit.
 Access the Exit or Save & Exit tab in setup, select the Load Optimized Defaults option,
select Yes, and press Enter. Any changes made are reverted, and the BIOS or CMOS is set
back to default settings.
 Turn off the computer (use only as a last resort and with caution).

INSTALLING OR UPGRADING WINDOWS:


To start the Windows install or upgrade process, you need to configure your computer to boot
from a CD or DVD before booting to the hard drive. Changing the boot process forces the computer
to look for the Windows installation disc before booting from the hard drive.
1. Open the CMOS setup.
2. Change the computer's boot order. Set the CD, DVD, or disc drive as the first boot device if
you are trying to boot from a disc. Or, set the first boot device to your USB drive if you're
trying to boot from a USB thumb drive. If the drive is not shown, keep the disc is inserted
and reboot the computer. With the disc in the drive, BIOS should recognize and include it in
the list.
3. Save the settings change and exit BIOS.
Note: Once you have updated the boot order, you can begin the Windows installation
process.
4. Place the Windows disc in the CD/DVD drive or USB thumb drive into the back of the
computer.
5. Turn on or restart the computer. As the computer starts up, it should detect the installation
disc or drive and show a message similar to Press any key to boot from CD. Press any key on
the keyboard to have the computer boot from the Windows disc or drive.
6. After the Windows install begins, there are several prompts that you need to answer. Select
either Yes or the appropriate option to install Windows.
7. When asked which partition to install Windows onto, select the main partition, usually the C:
drive or one labeled "Unallocated partition". If upgrading Windows, select the existing
installation of Windows on the hard drive.
8. You may be asked if you want to erase all contents on the hard drive, then install Windows.
We recommend you choose this option, as it also formats the hard drive to allow the
Windows operating system to be installed.
9. The computer may need to restart several times during the Windows install process. The
restarts are normal and if prompted to restart, select the Yes option.
10. When the install process is nearly complete, the Windows configuration option screens are
shown. On these screens, you may be asked to select the time zone you live in, your
preferred language, and the account's name you use to access Windows. Select the
appropriate options and enter the appropriate information on each configuration screen.
11. The Windows install process is completed when the computer prompts you to log in or when
it loads into Windows.

3
FINAL WINDOWS AND COMPUTER CONFIGURATION:
After Windows is installed on the computer, you need to install the drivers and related
software for the hardware in the computer. You can use the installation discs that came with the
hardware or download the drivers from the hardware manufacturer's website.We strongly
recommend you install the latest drivers for each piece of hardware.
To determine which hardware needs drivers to be installed, check the Device Manager and
look for the exclamation mark "!" next to hardware devices. The exclamation point means drivers
are needed for that device.After installing the necessary hardware device drivers, install any software
programs on the computer that you want to use.
Finally, download and install any available Windows updates. Updating Windows improves
the operating system's performance, the hardware in the computer, and the software programs you
use. It can also improve security by fixing potential security holes and flaws in Windows.

LONG-TERM MAINTENANCE OF WINDOWS:


Microsoft frequently releases new updates for Windows, so we recommend you check for
and install available updates. Doing so helps keep Windows running better and keep your computer
protected.
Also, periodically check for updated hardware device drivers from manufacturers' websites.
Keeping hardware drivers updated helps the hardware devices in the computer run at peak
performance and improves compatibility with other computer hardware and software.

RESULT:

Thus the study exercise for installing windows operating system is studied successfully

4
EX NO: 2
BASIC UNIX COMMANDS
DATE:

AIM:
To implement the Basic unix commands.

COMMANDS:
1.1 GENERAL PURPOSE COMMANDS:
1. THE DATE COMMAND:

The date command can also be used with following format.


+ %m To display only month $ date + %m
+ %h To display month name $ date + %h
+ %d To display day of month $ date + %d
+ %y To display last two digits of the year $ date + %y
+ %H To display Hours $ date + %H
+ %M To display Minutes $ date + %M
+ %S To display Seconds $ date + %S

[exam@fosslab ~]$ date


Sat Feb 14 11:48:18 IST 2015

2. THE echo COMMAND:


[exam@fosslab ~]$ echo learning unix is intresting
learning unix is intresting

3. THE Who COMMAND:


[exam@fosslab ~]$ who
exam pts/0 2015-02-14 11:48 (192.168.8.5)
exam20 pts/0 2015-02-14 11:48 (192.168.8.6)

4. THE Who am i COMMAND:


[exam@fosslab ~]$ who am i
exam pts/0 2015-02-14 11:48 (192.168.8.5)

5. THE UNIX CALENDER:


Cal:
[exam@fosslab ~]$ cal 2 2015
February 2015
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
5
6. THE Finger COMMAND:
[exam@fosslab ~]$ finger exam25
Login: exam Name:
Directory: /home/exam Shell: /bin/bash
On since Sat Feb 14 11:48 (IST) on pts/0 from 192.168.8.5
No mail. No Plan.

7. THE id COMMAND:
[exam@fosslab ~]$ id
uid=662(exam) gid=662(exam) groups=662(exam)

8. THE tty COMMAND:


[exam@fosslab ~]$ tty
/dev/pts/0

9. VIEW THE CONTENT:


[exam@fosslab ~]$ cat test
welcome to operating system. it is an interesting subject.

10. CLEARING THE SCREEN


[exam@fosslab student ~]$ tput clear

1.2 DIRECTORY COMMANDS

1.CREATE A DIRECTORY:
[exam@fosslab ~]$ mkdir student
[exam@fosslab ~]$ cd student
[exam@fosslab student]$

2 CURRENT WORKING DIRECTORY:


[exam@fosslab ~]$ pwd
/home/exam
3. REMOVING A DIRECTORY:
[exam@fosslab student]$ rmdir student
[exam@fosslab ~]$

4. LISTING THE FILES AND DIRECTORIES:


ls:
[exam@fosslab student~]$ ls
a.out data program public_html share stud25 student test.c test1

5. CHANGING THE WORKING DIRECTORY:


Cd :Change directory
Pwd: to view the full path of current directory
[exam@fosslab ~]$ pwd
/home/exam/
[exam@fosslab ~]$ mkdir student 6
[exam@fosslab ~]$ cd student
[exam@fosslab student]$ pwd
/home/exam/student/

6. THE PATH

[exam@fosslab student~]$ echo $PATH


/usr/lib/qt-3.3/bin:/usr/lib/mpich2/bin:/usr/lib/ccache:/usr/local/bin:/bin:/usr
/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/lib/alliance/bin:/usr/libexec/sdcc:/op
t/ns2/bin:/opt/ns2/tcl8.4.14/unix:/opt/ns2/tk8.4.14/unix:/opt/ns2/ns-2.34/:/opt/
ns2/nam-1.14/:/home/exam25/bin

7.CHANGE THE PASSWORD:


[exam@fosslab ~]$ passwd
(current) UNIX PASSWORD: ********
New Password: ********
Re-enter Password: ********
$

1.3 FILE HANDLING COMMANDS


1. THE CAT COMMAND:
[exam@fosslab ~]$ cat>test
welcome to operating system. it is an interesting subject.

2. COPYING THE FILE:


Cp:
[exam@fosslab student~]$ cat test
welcome to operating system. it is an interesting subject.
[exam@fosslab student ~]$ cat test1
the basic unix commands are cat, pwd, mkdir, rmdir, cd, path,clear,cp,rm,
mv,ls,wc.
[exam@fosslab student~]$ cp test test1[exam@fosslab student ~]$cat test1
welcome to operating system. it is an interesting subject.
7
3. REMOVING A FILE:
Rm:
[exam@fosslab student ~]$ rm test1
[exam@fosslab student ~]$ cat test1
Cat :test1: No such file or directory

4.MOVING A FILE:
[exam@fosslab student~]$ cat >test1
the basic unix commands are cat,pwd,clear,cp,mv,rm,mv,test..^C
mv:
[exam@fosslab student ~]$ mv test test1
[exam@fosslab student ~]$ cat test 1
the basic unix commands are cat, pwd, mkdir, rmdir, cd, path,clear,cp,rm,
mv,ls,wc.

5. DIRECTING OUTPUT TO A FILE:


[exam@fosslab student~]$ ls>test
[exam@fosslab student ~]$ cat test
a.out
data
mylist
program
public_html
share
stud25
student
test
test1
[exam@fosslab ~]$

6. COUNTING NUMBER OF WORDS IN A FILE:


wc:
[exam@fosslab ~]$ wc test
10 10 70 test

7. THE FILE COMMAND


[exam@fosslab ~]$ file test
test: ASCII Pascal program text
[exam@fosslab ~]$ cat test
a.out
data
mylist
program
public_html
share
stud25
student
test 8
8. CHANGING THE FILE PERMISSION:
Chmod:
[exam@fosslab ~]$ chmod u-wx test
[exam@fosslab ~]$ cat > test
-bash: test: Permission denied

1.4 FILTER COMMANDS


1. SORTING THE CONTENTS: (sort)
[exam@fosslab ~]$ sort test1
a.out
data
mylist
program
public_html
share
stud25
student
test
test1

2. THE uniq COMMAND:


[exam@fosslab ~]$ cat > dept.lst
01 accounts 3977
01 accounts 3977
02 admin 1707
03 marketing 39
03 marketing 39
04 personel 77
05 production 1739
06 sales 1008^C
[exam@fosslab ~]$ uniq dept.lst
01 accounts 3977
02 admin 1707
03 marketing 39
04 personel 77
05 production 1739

3. ADDING LINE NUMBERS:


nl
[exam@fosslab ~]$ nl test1
1 a.out
2 data
3 mylist
4 program
5 public_html

9
4. SELECTING FIELDS FROM A LINE:
cut
[exam@fosslab ~]$ cat >std
Aswini
Bharathi
Charu
Deepa^C
[exam@fosslab ~]$ cut -c1 std
A
B
C
D
5. THE more COMMAND:
[exam@fosslab ~]$ more test1
a.out
data
mylist
program
public_html
stud25
student
test
test1
6. PASTING FILES:
[exam@fosslab ~]$ paste std
Aswini
Bharathi
Charu
Deepa
7. COMPARING FILES:
cmp
[exam@fosslab ~]$ cmp test1 std
test1 std differ: byte 1, line 1
8. THE mesg COMMAND:
mesg
[exam@fosslab ~]$ mesg exam25
Usage: mesg [y|n]
[exam@fosslab ~]$ y
Message from [email protected] on pts/0 at 12:34 ...
hiiiii ... study well for your exams
hiiiii ... study well for your exams

9. THE write COMMAND:


write
[exam@fosslab ~]$ write exam25
Message from [email protected] on pts/0 at 12:30 ...
10
Hiiii
Hiiii
10. SENDING MESSAGE TO ALL THE USERS:
wall:
[exam@fosslab ~]$ wall os laboratory lab records
Broadcast message from [email protected] (pts/0) (Wed Jan 21 13:21:os
laboratory lab records
11. SENDING MAIL TO USERS:
mail:
[exam@fosslab ~]$ mail user2
Subject: about operating systems
THE OPERATING SYSTEMS BOOk is a "practice of some materials to gain knowledge"
EOT
12. THE reply COMMAND:
reply
reply exam25
Thanks For Giving A Mail
13. NO LOGGING OUT:
[exam@fosslab ~]$ std.lst test1.lst &
[1] 4663

14. THE nohup COMMAND:


[exam@fosslab ~]$ nohup test1.lst &
[1] 4685
15. Execution of a Job With Low Priority:
nice
[exam@fosslab ~]$ nice wc -l std &
[2] 4721
[1] Exit 127 nohup test1.lst
[exam@fosslab ~]$ 4 std

16. THE at COMMAND:


[exam@fosslab ~]$ at 12.54pm
at> today at evening 4pm
at> 21.30 tue next at 9.20
at> 2pm apr3 next 3rd

17. THE sleep COMMAND:


[exam@fosslab ~]$ sleep 1
-
18. KILLING PROCESSES WITH SIGNALS
kill
[exam@fosslab ~]$ kill 4921

RESULT:
Thus the basic UNIX commands were executed successfully.

11
EX NO: 3
SHELL PROGRAMMING

DATE:

3.A. AREA OF THE CIRCLE


AIM:
To write a shell program to find the area of circle.

SHELL SCRIPT:
echo "enter radius"read r
val=`expr 3 \* $r \* $r`echo
"$val"

OUTPUT:

RESULT:
Thus the shell program to find the area of circle is written and executed successfully

12
EX NO: 3B
SHELL PROGRAMMING – BIGGEST OF TWO NUMBERS

DATE:

AIM:
To write a shell program to find the biggest of two numbers

SHELL SCRIPT:
echo "enter two numbers"read a
b
if [ $a -gt $b ]then
echo "a is big"else
echo "b is big"fi

OUTPUT:

RESULT:
Thus the shell program to find the biggest of two numbers is written and executed
successfully

13
EX NO: 3C
SHELL PROGRAMMING – BIGGEST OF THREE NUMBERS

DATE:

AIM:
To write a shell program to find the biggest of three numbers

SHELL SCRIPT:
echo "enter three numbers"read a b
c
if [ $a -gt $b ]&&a [ $b -gt $c ]then
echo "a is big" elif [ $b -
gt $c ]then
echo "b is big"else
echo "c is big"fi

OUTPUT:

RESULT:
Thus the shell program to find the biggest of three numbers is written and executedsuccessfully.

14
EX NO: 3D
SHELL PROGRAMMING – NATURAL NUMBERS UPTO ‘N’

DATE:

AIM:
To write a shell program to find n natural numbers

SHELL SCRIPT:
echo "upper limit"read n
$i=0
while [ $i -lt $n ]do
echo $i i=`expr $i+1`
done

OUTPUT:

RESULT:
Thus shell program to find n natural numbers is written and executed successful

15
EX NO: 3E
SHELL PROGRAMMING – NATURAL NUMBERS
USING FORLOOP
DATE:

AIM:
To write a shell program to find n natural numbers using for loop.

SHELL SCRIPT:
for i in 1 2 3 4 5do
echo $idone

OUTPUT:

RESULT:
Thus the shell program to find n natural numbers using for loop is written andexecuted
successfully

16
EX NO: 3F
SHELL PROGRAMMING – ARITHMETIC OPERATIONS

DATE:

AIM:
To write a shell program to perform arithmetic operations on two numbers.

SHELL SCRIPT:
echo "enter two numbers"read a b
echo "1.Add 2.Sub 3.Mul 4.Div 5.Exit"read op
case $op in
1) c=`expr $a + $b` ;;
2) c= `expr $a - $b` ;;
3) c= `expr $a \ * $b` ;;
4) c= `expr $a / $b` ;;
5) exit esac
echo $c

OUTPUT:

RESULT:
Thus the shell program to perform arithmetic operations on two numbers is writtenand
executed successfully.

17
EX NO: 3G
SHELL PROGRAMMING – GROSS SALARY OF AN
EMPLOYEE
DATE:

AIM:
To write a shell program to calculate gross salary of an employee

SHELL SCRIPT:
echo "Basic Salary"read
basic
da=`expr $basic \* 10 / 100` hra=`expr
$basic \* 20 / 100` gross=`expr $basic +
$da + $hra`echo "$gross"

OUTPUT:

RESULT:
Thus the shell program to calculate gross salary of an employee is written andexecuted
successfully.

18
EX NO: 3H
SHELL PROGRAMMING – FACTORIAL OF A NUMBER
DATE:

AIM:
To write a shell program to find factorial of a number.

SHELL SCRIPT:
echo "enter number"read n
i=1f=1
while [ $i -lt $n ]do
f=`expr $f \* $i`i=`expr
$i + 1` done
echo "Factorial is...$f"

OUTPUT:

RESULT:
Thus the shell program to find factorial of a number is written and executedsuccessfully.

19
EX NO: 4
SYSTEM CALLS OF UNIX OPERATING SYSTEM
DATE:

4A . CLOSE()
AIM:
To write the program to implement the system calls close().

ALGORITHM:

Step 1: Start
Step 2: In the main function pass the arguments.
Step 3: Create structure as stat buff and the variables as integer.Step 4:
Use the for loop initialization.
Step 5: Stop.

20
PROGRAM:
#include<stdio.h>

#include<fcntl.h>

int main()

int fd1 = open("foo.txt",O_RDONLY);

if(fd1<0)

perror("c1");

exit(1);

printf("opened the fd =%d\n",fd1);

if(close(fd1)<0)

perror("c1");

exit(1);

printf("closed the fd.\n");

21
OUTPUT:

RESULT:
Thus the program was executed and verified successfully.

22
4B . GETPID()

AIM:

To write the program to implement the system calls getpid()

ALGORITHIM:

Step 1: Start
Step 2: Get the process id integer value by using the system call getpid()
Step 3: It returns the process id of the calling process.
Step 4: After getting the pid value it prints the process id number an exists.
Step 5: Then compile the program either with the gcc or cc command.
Step 6: Run the program.
Step 7: Stop

23
PROGRAM:

Example.c

#include<stdio.h>

#include<unistd.h>

#include<stdlib.h>

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

printf("PID of example.c=%d\n",getpid());

char *args[]={"hello", "c","programming",NULL};

execv("./hello",args);

printf("BACK TO EXAMPLE.C");

Hello.c

#include<stdio.h>

#include<unistd.h>

#include<stdlib.h>

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

printf("We are in hello.c\n");

printf("PID of hello.c=%d\n",getpid());

return 0;

24
OUTPUT:

RESULT:
Thus the program for getpid() system call has been executed and verified
successfully.

25
4C . FORK()

AIM:
To write the program to create a Child Process using system call fork().

ALGORITHM:

Step 1: Declare the variable pid.


Step 2: Get the pid value using system call fork().
Step 3: If pid value is less than zero then print as “Fork failed”.
Step 4: Else if pid value is equal to zero include the new process in the system‟s
file using execlp system call.
Step 5: Else if pid is greater than zero then it is the parent
process and it waits till the child completes using the system call wait()
Step 6: Then print “Child complete”.

26
PROGRAM:

#include <stdio.h>

#include<unistd.h>

int main()

int id;

printf("hello world!\n");

id=fork();

if (id>0)

printf("this is parent section[process id:%d].\n",getpid());

else if(id==0)

printf("fork created [process id:%d].\n",getpid());

printf("fork parent process id:%d.\n",getpid());

else

printf("fork created failed!!\n");

return 0;

27
OUTPUT:

RESULT:
Thus the program for fork() system call has been executed and verified successfully.

28
4D . EXIT()

AIM:
To write the program to implement the system call exit( ).

ALGORITHM:

Step 1 : Declare the necessary header files.


Step 2 : Declare the variables.
Step 3 : Get the pid value using system call fork().
Step 4 : Declare exit system call to terminate the child
Step 5 : Print the parent processor id
Step 6 : Print the child processor id
Step 7 : Stop the program.

29
PROGRAM:

#include<stdio.h>
#include<stdlib.h>
#include<sys/wait.h>
#include<unistd.h>

int main()
{
pid_t cpid;
if (fork()== 0)
exit(0); /* terminate child */
else
cpid = wait(NULL); /* reaping parent */
printf("Parent pid = %d\n", getpid());
printf("Child pid = %d\n", cpid);
return 0;
}

OUTPUT:
Parent pid = 12345678
Child pid = 89546848

RESULT:
Thus the program for exit() system call has been executed and verified successfully.

30
4E .WAIT()

AIM:
To write the program to implement the system call wait( ).

ALGORITHM:

Step 1 : Declare the necessary header files.


Step 2 : Declare the variables
Step 3 : Write the fork system call to create process id
Step 4 : if fork value is zero then print child process
Step 5 : Else print parent process
Step 6 : Declare wait system call to suspend the execution of parent process
while the child executes
Step 7: Print the result
Step 8 : Stop the program.

31
PROGRAM:

#include<stdio.h>
#include<sys/wait.h>
#include<unistd.h>

int main()
{
if (fork()== 0)
printf("HC: hello from child\n");
else
{
printf("HP: hello from parent\n");
wait(NULL);
printf("CT: child has terminated\n");
}

printf("Bye\n");
return 0;
}

OUTPUT:
HP: hello from parent
HC: hello from child
HC: Bye
CT: child has terminated

RESULT:
Thus the program for wait() system call has been executed and verified successfully.
32
EX NO: 5
CPU SCHEDULING ALGORITHMS
DATE:
5A. FIRST COME FIRST SERVE
AIM:
To write the program to implement CPU & scheduling algorithm for first come firstserve
scheduling.

ALGORITHM:

1. Start the program.


2. Get the number of processes and their burst time.
3. Initialize the waiting time for process 1 and 0.
4. Process for(i=2;i<=n;i++),wt.p[i]=p[i-1]+bt.p[i-1].
5. The waiting time of all the processes is summed then average value time is
calculated.
6. The waiting time of each process and average times are displayed
7. Stop the program.

33
PROGRAM:

#include<stdio.h>
void main()
{
int i,n,sum,wt,tat,twt,ttat;
int t[10];
float awt,atat;
printf("enter the of processer:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n enter burst time");
scanf("\n %d",&t[i]);
}
printf("\n FIRST COME FRIST SERVE SCHEDULING");
printf("\n processid\twaittingtime\tturnaroundtime\n");
printf("1\t\t0\t\t%d\n",t[0]);
sum=0;
twt=0;
ttat=t[0];
for(i=1;i<n;i++)
{
sum+=t[i-1];
wt=sum;
tat=sum+t[i];
twt=twt+wt;
ttat=ttat+tat;
printf("\n%d\t\t%d\t\t%d",i+1,wt,tat);
printf("\n");
}
awt=(float)twt/n;
atat=(float)ttat/n;
printf("\n average waiting time%4.2f",awt);
printf("\n average turnaround time %4.2f",atat);
}

34
OUTPUT:

RESULT:

Thus the FCFS process scheduling program was executed and verified successfully.

35
EX NO: 5B
SHORTEST JOB FIRST – SCHEDULING ALGORITHM

DATE:

AIM:
To write a program to implement cpu scheduling algorithm for shortest job firstscheduling.

ALGORITHM:

1. Start the program.


2. Get the number of processes and their burst time
3. Initialize the waiting time for process 1 as 0.
4. The processes are stored according to the burst time.
5. The waiting time for the processes are calculated a follows:
for(i=2;i<=n;i++).wt.p[i]=p[i=1]+bt.p[i-1].
6. The waiting time of all the processes summed and then the average time is calculate
7. The waiting time of each processes and average time are displayed.
8. Stop the program.

36
PROGRAM:

#include<stdio.h>
void main()
{
int i,j,k,n,sum,wt[10],tt[10],twt,ttat;int
t[10],p[10];
float awt,atat;
printf("enter the number of processer");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n enter burst time %d",i);
scanf("\n%d",&t[i]);
}
for(i=0;i<n;i++)
p[i]=i;
for(i=0;i<n;i++)
{
for(k=0;k<i+1;k++)
{
if(t[i]>t[k])
{
int temp;
temp=t[i];
t[i]=t[k];
t[k]=temp;
temp=p[i];
p[i]=p[k];
p[k]=temp;
}}
printf("\n\n SHOREST JOB SSHEDULING\n\n");
printf("\nprocerrid\tburst tim\twaitingtime\tturnaround time\n\n");
wt[0]=0;
for(i=0;i<n;i++)
{
sum=0;
for(k=0;k<i;k++)
{
wt[i]=sum+t[k];
sum=wt[i];
}}
for(i=0;i<n;i++)
{ 37

46
tt[i]=t[i]+wt[i];
}
for(i=0;i<n;i++)
{
wt[i]=sum+t[k];
sum=wt[i];
}
}
for(i=0;i<n;i++)
{
tt[i]=t[i]+wt[i];
}
for(i=0;i<n;i++)
{
printf("%5d\t\t%5d\t\t%5d\t\t%5d\n",p[i],t[i],wt[i],tt[i]);
}
twt=0;
ttat=t[0];
for(i=1;i<n;i++)
{
twt=twt+wt[i];
ttat=ttat+tt[i];
}
awt=(float)twt/n;
atat=(float)ttat/n;
printf("\n AVERAGE WAITING TIME %4.2f",awt);
printf("\n AVERAGE TURN AROUND TIME %4.2f",atat);
}
}

38

47
OUTPUT:

RESULT:

Thus the SJF program was executed and verified successfully

39
48
EX NO: 5C
PRIORITY – SCHEDULING ALGORITHM
DATE:

AIM:
To write a ‘C’ program to perform priority scheduling.

ALGORITHM:

1. Start the program.


2. Read burst time, waiting time, turn the around time and priority.
3. Initialize the waiting time for process 1 and 0.
4. Based up on the priority process are arranged
5. The waiting time of all the processes is summed and then the average waiting time
6. The waiting time of each process and average waiting time are displayed basedon the
priority.
7. Stop the program.

40
PROGRAM:
#include<stdio.h>
void main()
{
int i,j,n,tat[10],wt[10],bt[10],pid[10],pr[10],t,twt=0,ttat=0;
float awt,atat;
printf("\n-----------PRIORITY SCHEDULING ---------- \n");
printf("Enter the number of process: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
pid[i]=i;
printf("Enter the Burst time of Pid %d: ",i);
scanf("%d",&bt[i]);
printf("Enter the Priority of Pid %d: ",i);
scanf("%d",&pr[i]);
}
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
{
if(pr[i]>pr[j])
{
t=pr[i];
pr[i]=pr[j];
pr[j]=t;
t=bt[i];
bt[i]=bt[j];
bt[j]=t;
t=pid[i];
pid[i]=pid[j];
pid[j]=t;
}
}
tat[0]=bt[0];
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+bt[i-1];
tat[i]=wt[i]+bt[i];
}
printf("\n \n");
printf("Pid \t Priority \t Burst time \t WaitingTime \tTurnAroundTime \n");
printf("\n \n");
for(i=0;i<n;i++)
{
41
printf("\n %d \t\t %d \t\t %d \t\t %d \t\t %d",pid[i],pr[i],bt[i],bt[i],wt[i],ta
t[i]);
}
for(i=0;i<n;i++)
{
ttat=ttat+tat[i];
twt=twt+wt[i];
}
awt=(float)twt/n;
atat=(float)ttat/n;
printf("\n\n Avg.Waiting Time: %f\n Avg.Turn Around Time: %f\n",awt,atat);
}

OUTPUT:

RESULT:
Thus the priority scheduling program was executed and verified successfully

42
EX NO: 5D
ROUND ROBIN – SCHEDULING ALGORITHM

DATE:

AIM:

To write a program to implement CPU scheduling for Round Robin Scheduling.

ALGORITHM:

1. Get the number of process and their burst time.


2. Initialize the array for Round Robin circular queue as ‘0’.
3. The burst time of each process is divided and the quotients are stored on the roundRobin
array.
4. According to the array value the waiting time for each process and the averagetime
are calculated as line the other scheduling.
5. The waiting time for each process and average times are displayed.
6. According to the array value the waiting time for each process and the averagetime
are calculated as line the other scheduling.

43
PROGRAM:
#include<stdio.h>
void main()
{
int ts,pid[10],need[10],wt[10],tat[10],i,j,n,n1;
int bt[10],flag[10],ttat=0,twt=0;
float awt,atat;
printf("\n ROUND ROBIN SCHEDULING \n");
printf("Enter the number of processors \n");
scanf("%d",&n);
n1=n;
printf("\n Enter the Timeslice \n");
scanf("%d",&ts);
for(i=1;i<=n;i++)
{
printf("\n Enter the process ID %d",i);
scanf("%d",&pid[i]);
printf(" Enter the Burst Time for the process");
scanf("%d",&bt[i]);
need[i]=bt[i];
}
for(i=1;i<=n;i++)
{
flag[i]=1;
wt[i]=0;
}
while(n!=0)
{
for(i=1;i<=n;i++)
{
if(need[i]>=ts)
{
for(j=1;j<=n;j++)
{
if((i!=j)&&(flag[i]==1)&&(need[j]!=0))
wt[j]+=ts;
}
need[i]=0;
n--;
flag[i]=0;
}}
twt=0;
ttat=0;
for(i=1;i<=n1;i++)
{
tat[i]=wt[i]+bt[i];
twt=twt+wt[i];
ttat=ttat+tat[i];
}}
awt=(float)twt/n1;
atat=(float)ttat/n1;
44
printf("\n\n ROUND ROBIN SCHEDULING ALGORITHM \n\n");
printf("\n Process \t Process ID \t BurstTime \t Waiting Time \t Turnaround Time \n");
for(i=1;i<=n1;i++)
{
printf("\n %5d \t %5d \t\t %5d \t\t %5d \t\t %5d \n",i,pid[i],bt[i],wt[i],tat[i]);
}
printf("\n The average Waiting Time=%4.2f",awt);
printf("\n The average Turn around Time=%4.2f",atat);
}

OUTPUT:

RESULT:
Thus the Round Robin scheduling program was executed and verifiedsuccessfully.

45
EX NO: 6
IPC-SHARED MEMORY

DATE:

AIM
To demonstrate communication between process using shared memory.

ALGORITHM:

Server

1. Initialize key to 65(somerandomvalue).


2. Create a sharedmemory segment using shmget with key & IPC_CREAT as parameter.
If shared memory identifier shmidis-1,thenstop.
3. Display shmid.
4. Attach server process to the sharedmemory using shmmat with shmid as parameter.a.If
pointer to the sharedmemory is not obtained,then stop.
5. Clear contents of the shared region us in gmemsetfunction.
6. Write a–z onto the sharedmemory.
7. Wait till client reads the sharedmemory contents
8. Detach process from the sharedmemory using shmdt systemcall.
9. Remove sharedmemory from the system using shmctl with IPC_RMID argument
10. .Stop

Client

1. Initialize key to 65(samevalueasinserver).


2. Obtain access to the same sharedmemory segment using same key.If
obtained then display the shmid else print"Servernotstarted"
3. Attach client process to the sharedmemory using shmmat with shmid as parameter.
If pointer to the sharedmemory is not obtained,then stop.
4. Read contents of sharedmemory and print it.
5. After reading, modify the first character of sharedmemory to '*'
6. Stop

46
PROGRAM:

SHARED MEMORY FOR WRITER PROCESS


#include <iostream>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>
using namespace std;
int main()
{
key_t key = ftok("shmfile",65);
int shmid = shmget(key,1024,0666|IPC_CREAT);
char *str = (char*) shmat(shmid,(void*)0,0);
printf("Write Data : ");
fgets(input,sizeof(str),stdin);
printf("Data written in memory: %s\n",str);
shmdt(str);
return 0;
}

SHARED MEMORY FOR READER PROCESS


#include <iostream>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>
using namespace std;
int main()
{
key_t key = ftok("shmfile",65);
int shmid = shmget(key,1024,0666|IPC_CREAT);
char *str = (char*) shmat(shmid,(void*)0,0);
printf("Data read from memory: %s\n",str);
shmdt(str);
shmctl(shmid,IPC_RMID,NULL);
return 0;
}

47
OUTPUT:

Writer:
gcc write.c –o write
./write
Data written in memory
Hii

Reader:
Gcc read.c –o read
./read
Data read from memory
Hii

RESULT:

Thus the above program for read and write using IPC is executed successfully

48
EX NO: 7
SEMAPHORES
DATE:

AIM:

To write a C program to implement the Producer & consumer Problem (Semaphore).

ALGORITHM:

1: The Semaphore mutex, full & empty are initialized.2: In the


case of producer process
i) Produce an item in to temporary variable.
ii) If there is empty space in the buffer check the mutex value for enter into the critical
section.
iii) If the mutex value is 0, allow the producer to add value in the temporary variable tothe
buffer.
3: In the case of consumer process
i) It should wait if the buffer is empty
ii) If there is any item in the buffer check for mutex value, if the mutex==0, remove itemfrom
buffer
iii) Signal the mutex value and reduce the empty value by 1.
iv) Consume the item.4:
Print the result

49
PROGRAM

#include<stdio.h>
int mutex=1,full=0,empty=3,x=0;
main()
{
int n;
void producer();
void consumer();
int wait(int);
int signal(int);
printf("\n 1.producer\n2.consumer\n3.exit\n");
while(1) {
printf(" \nenter ur choice");
scanf("%d",&n);
switch(n)
{
case 1:if((mutex==1)&&(empty!=0))
producer();
else
printf("buffer is full\n");
break;
case 2:if((mutex==1)&&(full!=0))
consumer();
else
printf("buffer is empty");
break;
case 3:exit(0);
break;
}
}}
int wait(int s)
{
return(--s);
}
int signal(int s)
{
return (++s);
}
void producer()
{
mutex=wait(mutex);
full=signal(full);
empty=wait(empty);

50
x++;
printf("\n producer produces the items %d",x);
mutex=signal(mutex);
}
void consumer()
{
mutex=wait(mutex);
full=wait(full);
empty=signal(empty);
printf("\n consumer consumes the item %d",x);
x--;
mutex=signal(mutex);
}

51
OUTPUT:

RESULT:
Thus the program for Producer & consumer Problem using Semaphore was executed
successfully

52
EX NO: 8A
DEADLOCK AVOIDANCE – BANKER’S ALGORITHM

DATE:

AIM:
To implement deadlock avoidance by using Banker’s Algorithm.

Banker’s Algorithm:

When a new process enters a system, it must declare the maximum number of instances of each
resource type it needed. This number may exceed the total number of resources in the system. When the
user request a set of resources, the system must determine whether the allocation of each resources will
leave the system in safe state. If it will the resources are allocation; otherwise the process must wait until
some other process release the resources.

Data structures
 n-Number of process, m-number of resource types.
 Available: Available[j]=k, k – instance of resource type Rj is available.
 Max: If max[i, j]=k, Pi may request at most k instances resource Rj.
 Allocation: If Allocation [i, j]=k, Pi allocated to k instances of resource Rj
 Need: If Need[I, j]=k, Pi may need k more instances of resource type Rj,Need[I,
j]=Max[I, j]-Allocation[I, j];

Safety Algorithm
1. Work and Finish be the vector of length m and n respectively, Work=Available andFinish[i]
=False.
2. Find an i such that both
 Finish[i] =False
 Need<=Work
If no such I exists go to 4.
3. work=work+Allocation, Finish[i] =True;
4. if Finish[1]=True for all I, then the system is in safe state.

Resource request algorithm


Let Request i be request vector for the process Pi, If request i=[j]=k, then process Piwants k
instances of resource type Rj.
1. if Request<=Need I go to 2. Otherwise raise an error condition.
2. if Request<=Available go to 3. Otherwise Pi must since the resources are available.
3. Have the system pretend to have allocated the requested resources to process Pi bymodifying
the state as follows;
Available=Available-Request I; Allocation I
=Allocation+Request I;Need i=Need i-Request I;
53
If the resulting resource allocation state is safe, the transaction is completed and process Pi is
allocated its resources. However if the state is unsafe, the Pi must wait for Request i and the
old resource-allocation state is restored.

ALGORITHM:
1. Start the program.
2. Get the values of resources and processes.
3. Get the avail value.
4. After allocation find the need value.
5. Check whether its possible to allocate.
6. If it is possible then the system is in safe state.
7. Else system is not in safety state.
8. If the new request comes then check that the system is in safety.
9. Or not we allow the request.
10. Stop the program.

54
PROGRAM:

/* BANKER’S ALGORITHM */
#include<stdio.h>

struct da
{
int max[10],a1[10],need[10],before[10],after[10];
}p[10];
void main()
{ int i,j,k,l,r,n,tot[10],av[10],cn=0,cz=0,temp=0,c=0;
clrscr();
printf("\n ENTER THE NO. OF PROCESSES:");
scanf("%d",&n);
printf("\n ENTER THE NO. OF RESOURCES:");
scanf("%d",&r);
for(i=0;i<n;i++)
{
printf("PROCESS %d \n",i+1);
for(j=0;j<r;j++)
{
printf("MAXIMUM VALUE FOR RESOURCE %d:",j+1);
scanf("%d",&p[i].max[j]);
}
for(j=0;j<r;j++)
{
printf("ALLOCATED FROM RESOURCE %d:",j+1);
scanf("%d",&p[i].a1[j]);
p[i].need[j]=p[i].max[j]-p[i].a1[j];
}
}
for(i=0;i<r;i++)
{
printf("ENTER TOTAL VALUE OF RESOURCE %d:",i+1);
scanf("%d",&tot[i]);
}
for(i=0;i<r;i++)
{
for(j=0;j<n;j++)
temp=temp+p[j].a1[i];
av[i]=tot[i]-temp;
temp=0;
}
printf("\n\t RESOURCES ALLOCATED NEEDED TOTAL AVAIL");
55
for(i=0;i<n;i++)
{
printf("\n P%d \t",i+1);
for(j=0;j<r;j++)
printf("%d",p[i].max[j]);
printf("\t");
for(j=0;j<r;j++)
printf("%d",p[i].a1[j]);
printf("\t");
for(j=0;j<r;j++)
printf("%d",p[i].need[j]);
printf("\t");
for(j=0;j<r;j++)
{
if(i==0)
printf("%d",tot[j]);
}
printf(" ");
for(j=0;j<r;j++)
{
if(i==0)
printf("%d",av[j]);
}
}
printf("\n\n\t AVAIL BEFORE\T AVAIL AFTER ");
for(l=0;l<n;l++)
{
for(i=0;i<n;i++)
{
for(j=0;j<r;j++)
{
if(p[i].need[j] >av[j])
cn++;
if(p[i].max[j]==0)
cz++;
}
if(cn==0 && cz!=r)
{
for(j=0;j<r;j++)
{
p[i].before[j]=av[j]-p[i].need[j];
p[i].after[j]=p[i].before[j]+p[i].max[j];
av[j]=p[i].after[j];
p[i].max[j]=0;
}
56
printf("\n P %d \t",i+1);
for(j=0;j<r;j++)
printf("%d",p[i].before[j]);
printf("\t");
for(j=0;j<r;j++)
printf("%d",p[i].after[j]);
cn=0;
cz=0;
c++;
break;
}
else
{
cn=0;cz=0;
}
}
}
if(c==n)
printf("\n THE ABOVE SEQUENCE IS A SAFE SEQUENCE");
else
printf("\n DEADLOCK OCCURED");

57
OUTPUT:

//RUN: NO deadlock
//RUN2: Deadlock occurs

RESULT
Thus the banker’s algorithm is implemented successfully for Deadlock avoidance &
Dead Lock Prevention. 59
EX NO: 8B
DEADLOCK DETECTION – BANKER’S ALGORITHM

DATE:

AIM
To implement deadlock detection by using Banker’s Algorithm.

ALGORITHM:

1. Mark each process that has a row in the Allocation matrix of all zeros.
2. Initialize a temporary vectorW to equal the Available vector.
3. Find an indexi such that processi is currently unmarked and thei th row ofQ
is less than or equal to W . That is,Q ik … Wk, for 1 … k … m . If no such row isfound,
terminate the algorithm.
4. If such a row is found, mark processi and add the corresponding row of the
allocation matrix to W . That is, setWk = Wk + Aik, for 1 … k … m . Return to
step 3.

60
PROGRAM:

#include<stdio.h>
static int mark[20];
int i,j,np,nr;

int main()
{
int alloc[10][10],request[10][10],avail[10],r[10],w[10];
printf("\nEnter the no of process: ");
scanf("%d",&np);
printf("\nEnter the no of resources: ");
scanf("%d",&nr);
for(i=0;i<nr;i++)
{
printf("\nTotal Amount of the Resource R%d: ",i+1);
scanf("%d",&r[i]);
}
printf("\nEnter the request matrix:");

for(i=0;i<np;i++)
for(j=0;j<nr;j++)
scanf("%d",&request[i][j]);

printf("\nEnter the allocation matrix:");


for(i=0;i<np;i++)
for(j=0;j<nr;j++)
scanf("%d",&alloc[i][j]);
/*Available Resource calculation*/
for(j=0;j<nr;j++)
{
avail[j]=r[j];
for(i=0;i<np;i++)
{
avail[j]-=alloc[i][j];
}
}
//marking processes with zero allocation
for(i=0;i<np;i++)
{
int count=0;
for(j=0;j<nr;j++)
{
if(alloc[i][j]==0)
count++;
61
else
break;
}
if(count==nr)
mark[i]=1;
}
// initialize W with avail
for(j=0;j<nr;j++)
w[j]=avail[j];
//mark processes with request less than or equal to W
for(i=0;i<np;i++)
{
int canbeprocessed=0;
if(mark[i]!=1)
{
for(j=0;j<nr;j++)
{
if(request[i][j]<=w[j])
canbeprocessed=1;
else
{
canbeprocessed=0;
break;
}
}
if(canbeprocessed)
{
mark[i]=1;
for(j=0;j<nr;j++)
w[j]+=alloc[i][j];
}
}
}
//checking for unmarked processes
int deadlock=0;
for(i=0;i<np;i++)
if(mark[i]!=1)
deadlock=1;
if(deadlock)
printf("\n Deadlock detected");
else
printf("\n No Deadlock possible");
}
62
OUTPUT:

Enter the no of process: 4


Enter the no of resources: 5

Total Amount of the Resource R1: 2


Total Amount of the Resource R2: 1
Total Amount of the Resource R3: 1
Total Amount of the Resource R4: 2
Total Amount of the Resource R5: 1

Enter the request matrix:0 1 0 0 1


00101
00001
10101

Enter the allocation matrix:1 0 1 1 0


11000
00010
00000

Deadlock detected

RESULT:
Thus the banker’s algorithm is implemented successfully for Deadlock detection.

63
EX NO: 9
IMPLEMENTATION OF THREADING AND
SYNCHRONIZATION APPLICATIONS
DATE:

AIM:
To implement threading and synchronization techniques using c language.

ALGORITHM:

Step 1: Start the program.


Step 2: Identify the thread by an id called ThreadId.
Step 3: Represent the thread id by the type pthread_t.
Step 4: Include the header file “#include<pthread.h>” to access the thread functions.
Step 5: This function is used to create a thread pthread_create.
Step 6: If the thread is created successfully, return value will be zero, Otherwisepthread_create
will return an error number of type integer.
Step 7: Stop the program.

64
PROGRAM:

#include<stdio.h>
#include <string.h>
#include<pthread.h>
// Global variable:
int i = 2;
void* foo(void* p){
// Print value received as argument:
printf(“Value recevied as argument in starting routine:”);
printf(“%i\n”, * (int*)p);
// Return reference to global variable:
pthread_exit(&i);
}
int main(void){
// Declare variable for thread’s ID:
pthread_t id;
int j = 1;
pthread_create(&id, NULL, foo, &j);
int* ptr;
// Wait for foo() and retrieve value in ptr;
pthread_join(id, (void**)&ptr);
printf(“Value recevied by parent from child: “);
printf(“%i\n”, *ptr);
}

OUTPUT:
Value recevied as argument in starting routine: 1
Value recevied by parent from child: 2

RESULT:
Thus to implement threading and synchronization techniques using c language has
been executed and verified successfully.
65
EX NO: 10
PAGING TECHNIQUE OF MEMORY MANAGEMENT

DATE:

AIM:
To implement the Memory management policy- Paging.

ALGORITHM:

Step 1: Read all the necessary input from the keyboard.


Step 2: Pages - Logical memory is broken into fixed - sized blocks. Step 3:
Frames – Physical memory is broken into fixed – sized blocks.Step 4: Calculate
the physical address using the following
Physical address = ( Frame number * Frame size ) + offsetStep 5:
Display the physical address.
Step 6: Stop the process.

66
PROGRAM:
#include <stdio.h>
#include <conio.h>
struct pstruct
{
int fno;
int pbit;
}ptable[10];

int pmsize,lmsize,psize,frame,page,ftable[20],frameno;

void info()
{
printf("\n\nMEMORY MANAGEMENT USING PAGING\n\n");
printf("\n\nEnter the Size of Physical memory: ");
scanf("%d",&pmsize);
printf("\n\nEnter the size of Logical memory: ");
scanf("%d",&lmsize);
printf("\n\nEnter the partition size: ");
scanf("%d",&psize);
frame = (int) pmsize/psize;
page = (int) lmsize/psize;
printf("\nThe physical memory is divided into %d no.of frames\n",frame);
printf("\nThe Logical memory is divided into %d no.of pages",page);
}
void assign()
{
int i;
for (i=0;i<page;i++)
{
ptable[i].fno = -1;
ptable[i].pbit= -1;
}

for(i=0; i<frame;i++)
ftable[i] = 32555;
for (i=0;i<page;i++)
{
printf("\n\nEnter the Frame number where page %d must be placed: ",i);
scanf("%d",&frameno);
ftable[frameno] = i;
if(ptable[i].pbit == -1)
{
ptable[i].fno = frameno;
ptable[i].pbit = 1;
67
}
}
getch();
printf("\n\nPAGE TABLE\n\n");
printf("PageAddress FrameNo. PresenceBit\n\n");
for (i=0;i<page;i++)
printf("%d\t\t%d\t\t%d\n",i,ptable[i].fno,ptable[i].pbit);
printf("\n\n\n\tFRAME TABLE\n\n");
printf("FrameAddress PageNo\n\n");
for(i=0;i<frame;i++)
printf("%d\t\t%d\n",i,ftable[i]);
}

void cphyaddr()
{
int laddr,paddr,disp,phyaddr,baddr;
getch();
printf("\n\n\n\tProcess to create the Physical Address\n\n");
printf("\nEnter the Base Address: ");
scanf("%d",&baddr);
printf("\nEnter theLogical Address: ");
scanf("%d",&laddr);
paddr = laddr / psize;
disp = laddr % psize;
if(ptable[paddr].pbit == 1 )
phyaddr = baddr + (ptable[paddr].fno*psize) + disp;
printf("\nThe Physical Address where the instruction present: %d",phyaddr);
}
void main()
{
clrscr();
info();
assign();
cphyaddr();
getch();
}

68
OUTPUT:

RESULT:
Thus the Memory management policy- Paging isimplemented successfully

69
EX NO: 11
MEMORY ALLOCATION METHODS FOR FIXED PARTITION

DATE:

11.A. FIRST FIT ALLOCATION


AIM:
To allocate memory requirements for processes using first fit allocation.

ALGORITHM:

1. Declare structures hole and process to hold information about set of holes and processes
respectively.
2. Get number of holes, say nh.
3. Get the size of each hole
4. Get number of processes, say np.
5. Get the memory requirements for each process.
6. Allocate processes to holes, by examining each hole as follows:
a. If hole size>process size then
i. Mark process as allocated to that hole.
ii. Decrement hole size by process size.
b. Otherwise check the next from the set of holes
7. Print the list of process and their allocated holes or unallocated status.
8. Print the list of holes, their actual and current availabilit y.9.Stop
the program.

70
PROGRAM

#include<stdio.h>
struct process
{
int size; int flag; int holeid;
}p[10];
struct hole
{
int size;
int actual;
}h[10];
main()
{
int i,np,nh,j;
printf("EnterthenumberofHoles:");
scanf("%d",&nh);
for(i=0;i<nh;i++){
printf("EntersizeforholeH%d:",i);
scanf("%d",&h[i].size);
h[i].actual=h[i].size;
}
printf("\nEnternumberofprocess:");
scanf("%d",&np);
for(i=0;i<np;i++){
printf("enterthesizeofprocessP%d:",i);
scanf("%d",&p[i].size);
p[i].flag=0;
}
for(i=0;i<np;i++){
for(j=0;j<nh;j++){
if(p[i].flag!=1){
if(p[i].size<=h[j].size){
p[i].flag=1; p[i].holeid=j; h[j].size-=p[i].size;
}}}}

printf("\n\tFirstfit\n");
printf("\nProcess\tPSize\tHole");
for(i=0;i<np;i++){
if(p[i].flag!=1)
printf("\nP%d\t%d\tNotallocated",i,p[i].size);
else
printf("\nP%d\t%d\tH%d",i,p[i].size,p[i].holeid);
}
printf("\n\nHole\tActual\tAvailable");
for(i=0;i<nh;i++)
printf("\nH%d\t%d\t%d",i,h[i].actual,h[i].size);
printf("\n");
}
71
OUTPUT:

RESULT:
Thus processes were allocated memory using first fit method.

72
DATE: 11.B.WORST FIT ALLOCATION

AIM:
To allocate memory requirements for processes using worst fit allocation.

ALGORITHM:

Step 1: Start the program.


Step 2: Input memory blocks and processes with sizes.
Step 3: Initialize all memory blocks as free.
Step 4: Start by picking each process and find the
maximum block size that can be assigned to
current process i.e., find max(bockSize[1],
blockSize[2], .... blockSize[n]) >
processSize[current], if found then assign
it to the current process.
Step 5: If not then leave that process and keep checking
the further processes.
Step 6: Stop the program.

73
PROGRAM:

#include<stdio.h>
#include<conio.h>
#define max 25
void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp;
static int bf[max],ff[max];
clrscr();
printf("\n\tMemory Management Scheme - First Fit");
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of files:");
scanf("%d",&nf);
printf("\nEnter the size of the blocks:-\n");
for(i=1;i<=nb;i++)
{
printf("Block %d:",i);
scanf("%d",&b[i]);
}
printf("Enter the size of the files :-\n");
for(i=1;i<=nf;i++)
{
printf("File %d:",i);
scanf("%d",&f[i]);
}
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
{
if(bf[j]!=1)
{
temp=b[j]-f[i];
if(temp>=0)
{
ff[i]=j;
break;
}
}
}
frag[i]=temp;
bf[ff[i]]=1;
}
printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
for(i=1;i<=nf;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
getch();
}

74
INPUT
Enter the number of blocks: 3
Enter the number of files: 2

Enter the size of the blocks:-


Block 1: 5
Block 2: 2
Block 3: 7

Enter the size of the files:-


File 1: 1
File 2: 4

OUTPUT
File No File Size Block No Block Size Fragment
1 1 1 5 4
2 4 3 7 3

RESULT
Thus processes were allocated memory using worst fit method.

75
DATE: 11.C.BEST FIT ALLOCATION

AIM:
To allocate memory requirements for processes using best fit allocation.

ALGORITHM:
1. Declare structures hole and process to hold information about set of holes and processes
respectively.
2. Get number of holes, say nh.
3. Get the size of each hole
4. Get number of processes, say np.
5. Get the memory requirements for each process.
6. Allocate processes to holes, by examining each hole as follows:
a. Sort the holes according to their sizes in ascending order
b. If hole size>process size then
i. Mark process as allocated to that hole.
ii. Decrement hole size by process size.
c. Otherwise check the next from the set of sorted hole.
7. Print the list of process and their allocated holes or unallocated status.
8. Print the list of holes, their actual and current availabilit y.
9. Stop

76
PROGRAM:
#include<stdio.h>
struct process
{
int size;
int flag;
int holeid;
}p[10];

struct hole
{
int hid;
int size;
int actual;
}h[10];

main()
{
int i,np,nh,j;
void bsort(structhole[],int);
printf("Enter the number of Holes:");
scanf("%d",&nh);
for(i=0;i<nh;i++)
{
printf("Enter size for holeH%d:",i);
scanf("%d",&h[i].size);
h[i].actual=h[i].size;
h[i].hid=i;
}
printf("\nEnter number of process:");
scanf("%d",&np);
for(i=0;i<np;i++)
{
printf("enter the size of processP%d:",i);
scanf("%d",&p[i].size);
p[i].flag=0;
}

for(i=0;i<np;i++)
{
bsort(h,nh);
for(j=0;j<nh;j++)
{
if(p[i].flag!=1)
{
if(p[i].size<=h[j].size)
{
p[i].flag=1;
p[i].holeid=h[j].hid;
h[j].size-=p[i].size;
}}}

77
}

printf("\n\tBestfit\n");
printf("\nProcess\tPSize\tHole");
for(i=0;i<np;i++)
{
if(p[i].flag!=1)
printf("\nP%d\t%d\tNotallocated",i,p[i].size);
else
printf("\nP%d\t%d\tH%d",i,p[i].size,p[i].holeid);
}

printf("\n\nHole\tActual\tAvailable");
for(i=0;i<nh;i++)
printf("\nH%d\t%d\t%d",h[i].hid,h[i].actual, h[i].size);
printf("\n");
}

Void bsort(structholebh[],intn)
{
struct holetemp;
int i,j;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(bh[i].size>bh[j].size)
{
temp=bh[i];
bh[i]=bh[j];
bh[j]=temp;
}
}
}
}

78
OUTPUT:

RESULT:
Thus processes were allocated memory using best fit method.

79
EX NO: 12
PAGE REPLACEMENT ALGORITHMS
DATE:

12.A. FIFO PAGE REPLACEMENT ALGORITHM


AIM:
To implement page replacement algorithms FIFO (First In First Out).

ALGORITHM:

1: Create a queue to hold all pages in memory


2: When the page is required replace the page at the head of the queue

3: Now the new page is inserted at the tail of the queue

80
PROGRAM:
#include<stdio.h>
int i,j,nof,nor,flag=0,ref[50],frm[50],pf=0,victim=-1;
void main()
{
printf("\n \t\t\t FIFO PAGE REPLACEMENT ALGORITHM");
printf("\n Enter no.of frames ....");
scanf("%d",&nof);
printf("Enter number of reference string..\n");
scanf("%d",&nor);
printf("\n Enter the reference string..");
for(i=0;i<nor;i++)
scanf("%d",&ref[i]);
printf("\nThe given reference string:");
for(i=0;i<nor;i++)
printf("%4d",ref[i]);
for(i=1;i<=nof;i++)
frm[i]=-1;
printf("\n");
for(i=0;i<nor;i++)
{
flag=0;
printf("\n\t Reference np%d->\t",ref[i]);
for(j=0;j<nof;j++)
{
if(frm[j]==ref[i])
{
flag=1;
break;
}}
if(flag==0)
{
pf++;
victim++;
victim=victim%nof;
frm[victim]=ref[i];
for(j=0;j<nof;j++)
printf("%4d",frm[j]);
}}
printf("\n\n\t\t No.of pages faults...%d",pf);
}

81
OUTPUT:

RESULT:
Thus the FIFO page replacement algorithm is implemented successfully.

82
EX NO: 12B
LRU PAGE REPLACEMENT ALGORITHM
DATE:

AIM:
To implement page replacement algorithm LRU (Least Recently Used LRU (Lease
Recently Used). Here we select the page that has not been used for the longest period of time.

ALGORITHM:
1: Create a queue to hold all pages in memory
2: When the page is required replace the page at the head of the queue3: Now
the new page is inserted at the tail of the queue
4: Create a stack
5: When the page fault occurs replace page present at the bottom of the stack

83
PROGRAM:
#include<stdio.h>
int i,j,nof,nor,flag=0,ref[50],frm[50],pf=0,victim=-1;
int recent[10],lrucal[50],count=0;
int lruvictim();
void main()
{
clrscr();
printf("\n\t\t\t LRU PAGE REPLACEMENT
ALGORITHM");printf("\n Enter no.of Frames ");
scanf("%d",&nof);
printf(" Enter no.of reference string..");
scanf("%d",&nor);

printf("\n Enter reference


string..");for(i=0;i<nor;i++)
scanf("%d",&ref[i]);

printf("\n\n\t\t LRU PAGE REPLACEMENT ALGORITHM ");


printf("\n\t The given reference string:");
printf("\n .................................................");

for(i=0;i<nor;i++)
printf("%4d",ref[i]);

for(i=1;i<=nof;i++)
{
frm[i]=-1;
lrucal[i]=0;
}
for(i=0;i<10;i++)
recent[i]=0;
printf("\n");

for(i=0;i<nor;i++)
{
flag=0;

printf("\n\t Reference NO %d->\t",ref[i]);


for(j=0;j<nof;j++)
{
if(frm[j]==ref[i])
{
flag=1;
break;
}
}
if(flag==0)
{
count++;
if(count<=nof)
84
victim++;
else
victim=lruvictim();
pf++;
frm[victim]=ref[i];

for(j=0;j<nof;j++)
printf("%4d",frm[j]);
}
recent[ref[i]]=i;
}
printf("\n\n\t No.of page faults...%d",pf);
getch();
}

int lruvictim()
{
int i,j,temp1,temp2;

for(i=0;i<nof;i++)
{
temp1=frm[i];
lrucal[i]=recent[temp1];
}
temp2=lrucal[0];
for(j=1;j<nof;j++)
{
if(temp2>lrucal[j])
temp2=lrucal[j];
}
for(i=0;i<nof;i++)
if(ref[temp2]==frm[i])

return i;
return 0;
}

85
OUTPUT:

RESULT:
Thus the LRU page replacement algorithm is implemented successfully.
86
EX NO: 12C
OPTIMAL (LFU) PAGE REPLACEMENT ALGORITHM

DATE:

AIM:
To implement page replacement algorithms Optimal (The page which is not used for
longest time)

ALGORITHM:

Optimal algorithm:
Here we select the page that will not be used for the longest period of time.
OPTIMAL:
1: Create an array
2: When the page fault occurs replace page that will not be used for the
longest period of time.

87
PROGRAM:
/*OPTIMAL (LFU) page replacement algorithm*/

#include<stdio.h>
#include<conio.h>
int i,j,nof,nor,flag=0,ref[50],frm[50],pf=0,victim=-1;
int recent[10],optcal[50],count=0;
int optvictim();
void main()
{
clrscr();
printf("\n OPTIMAL PAGE REPLACEMENT ALGORITHN");
printf("\n ................................ ");
printf("\nEnter the no.of frames");
scanf("%d",&nof);
printf("Enter the no.of reference string");
scanf("%d",&nor);
printf("Enter the reference string");
for(i=0;i<nor;i++)
scanf("%d",&ref[i]);
clrscr();
printf("\n OPTIMAL PAGE REPLACEMENT ALGORITHM");
printf("\n ...............................");
printf("\nThe given string");
printf("\n ................... \n");
for(i=0;i<nor;i++)
printf("%4d",ref[i]);
for(i=0;i<nof;i++)
{frm[i]=-1; optcal[i]=0;
}
for(i=0;i<10;i++)
recent[i]=0;
printf("\n");
for(i=0;i<nor;i++)
{
flag=0;
printf("\n\tref no %d ->\t",ref[i]);

for(j=0;j<nof;j++)
{
if(frm[j]==ref[i])
{
flag=1;

88
break;
}
}
if(flag==0) {
count++;
if(count<=nof)
victim++;
else
victim=optvictim(i);
pf++;
frm[victim]=ref[i];

for(j=0;j<nof;j++)
printf("%4d",frm[j]);
}
}
printf("\n Number of page faults: %d",pf);
}
int optvictim(int index)
{
int i,j,temp,notfound;

for(i=0;i<nof;i++) {
notfound=1;

for(j=index;j<nor;j++)
if(frm[i]==ref[j])
{
notfound=0;
optcal[i]=j;
break;
}
if(notfound==1)
return i;
}
temp=optcal[0];
for(i=1;i<nof;i++)
if(temp<optcal[i])
temp=optcal[i];
for(i=0;i<nof;i++)
if(frm[temp]==frm[i])
return i;
return 0;
}

89
OUTPUT:

RESULT:
Thus the LFU page replacement algorithm is implemented successfully.

90
EX NO: 13
VARIOUS FILE ORGANIZATION TECHNIQUES

DATE:
13.A. IMPLEMENTATION OF SINGLE LEVEL DIRECTORY
AIM:
To write a C program to implement Single - Level directory structure in C
ALGORITHM:
1. Start
2. Declare the number, names and size of the directories and file names.
3. Get the values for the declared variables.
4. Display the files that are available in the directories.
5. Stop

91
PROGRAM:
#include<stdio.h>
main()
{
int master,s[20];
char f[20][20][20];
char d[20][20];
int i,j;
printf("enter number of directorios:");
scanf("%d",&master);
printf("enter names of directories:");
for(i=0;i<master;i++)
scanf("%s",&d[i]);
printf("enter size of directories:");
for(i=0;i<master;i++)
scanf("%d",&s[i]);
printf("enter the file names :");
for(i=0;i<master;i++)
for(j=0;j<s[i];j++)
scanf("%s",&f[i][j]);
printf("\n");
printf(" directory\tsize\tfilenames\n");
printf("*************************************************\n");
for(i=0;i<master;i++)
{
printf("%s\t\t%2d\t",d[i],s[i]);
for(j=0;j<s[i];j++)
printf("%s\n\t\t\t",f[i][j]);
printf("\n");
}
printf("\t\n");
}

92
OUTPUT:

RESULT:
Thus the Single level directory structure is written and executed successfully.

93
EX NO: 13B
IMPLEMENTATION OF TWO-LEVEL DIRECTORY
DATE:

AIM:
To write a C program to implement Two-level directory structure in C.

ALGORITHM:
1. Start
2. Declare the number, names and size of the directories and subdirectories and filenames.
3. Get the values for the declared variables.
4. Display the files that are available in the directories and subdirectories.
5. Stop.

94
PROGRAM:

#include<stdio.h>
struct st
{
char dname[10];
char sdname[10][10];
char fname[10][10][10];
int ds,sds[10];
}dir[10];
void main()
{
int i,j,k,n;
clrscr();
printf("enter number of directories:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter directory %d names:",i+1);
scanf("%s",&dir[i].dname);
printf("enter size of directories:");
scanf("%d",&dir[i].ds);
for(j=0;j<dir[i].ds;j++)
{
printf("enter subdirectory name and size:");
scanf("%s",&dir[i].sdname[j]);
scanf("%d",&dir[i].sds[j]);
for(k=0;k<dir[i].sds[j];k++)
{
printf("enter file name:");
scanf("%s",&dir[i].fname[j][k]);
}}}
printf("\ndirname\t\tsize\tsubdirname\tsize\tfiles");
printf("\n******************************************************\n");
for(i=0;i<n;i++){
printf("%s\t\t%d",dir[i].dname,dir[i].ds);
for(j=0;j<dir[i].ds;j++)
{
printf("\t%s\t\t%d\t",dir[i].sdname[j],dir[i].sds[j]);
for(k=0;k<dir[i].sds[j];k++)
printf("%s\t",dir[i].fname[j][k]);
printf("\n\t\t");}
printf("\n"); }
}
95
OUTPUT:

RESULT:
Thus a C program to implement Two-level directory structure is written and executed
successfully.
96
EX NO: 14
FILE ALLOCATION STRATEGIES

DATE:

14.A. SEQUENTIAL FILE ALLOCATION


AIM:
To Write a C Program to implement Sequential File Allocation method.

ALGORITHM:
1: Start the program.
2: Get the number of memory partition and their sizes.
3: Get the number of processes and values of block size for each process. 4: First fit
algorithm searches all entire memory block until a hole which is
big enough is encountered. It allocates that memory block for the requestingprocess.
5: Best-fit algorithm searches the memory blocks for the smallest hole which canbe allocated
to requesting process and allocates if.
6: Worst fit algorithm searches the memory blocks for the largest hole andallocates it
to the process.
7: Analyses all the three memory management techniques and display the bestalgorithm which
utilizes the memory resources effectively and efficiently.
8: Stop the program.

97
PROGRAM:
#include<stdio.h>
main()
{
int n,i,j,b[20],sb[20],t[20],x,c[20][20];
clrscr();
printf("Enter no.of files:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter no. of blocks occupied by file%d",i+1);
scanf("%d",&b[i]);
printf("Enter the starting block of file%d",i+1);
scanf("%d",&sb[i]);
t[i]=sb[i];
for(j=0;j<b[i];j++)
c[i][j]=sb[i]++;
}
printf("Filename\tStart block\tlength\n");
for(i=0;i<n;i++)
printf("%d\t %d \t%d\n",i+1,t[i],b[i]);
printf("Enter file name:");
scanf("%d",&x);
printf("File name is:%d",x);
printf("length is:%d",b[x-1]);
printf("blocks occupied:");
for(i=0;i<b[x-1];i++)
printf("%4d",c[x-1][i]);
}

98
OUTPUT:

RESULT:
Thus the SEQUENTIAL file allocation method is implemented successfully.

99
EX NO: 14B
FILE ALLOCATION STRATEGIES – INDEXED FILE
ALLOCATION
DATE:

AIM:
To Write a C Program to implement Indexed File Allocation method.

ALGORITHM:
1: Start.
2: Let n be the size of the buffer 3: check
if there are any producer
4. If yes check whether the buffer is full
5. If no the producer item is stored in the buffer6: If the
buffer is full the producer has to wait
7: Check there is any consumer.If yes check whether the buffer is empty8: If no
the consumer consumes them from the buffer
9: If the buffer is empty, the consumer has to wait.
10: Repeat checking for the producer and consumer till required11:
Terminate the process.

100
PROGRAM:
#include<stdio.h>
main()
{
int n,m[20],i,j,sb[20],s[20],b[20][20],x;
clrscr();
printf("Enter no. of files:");
scanf("%d",&n);
for(i=0;i<n;i++)
{ printf("Enter starting block and size of file%d:",i+1);
scanf("%d%d",&sb[i],&s[i]);
printf("Enter blocks occupied by file%d:",i+1);
scanf("%d",&m[i]);
printf("enter blocks of file%d:",i+1);
for(j=0;j<m[i];j++)
scanf("%d",&b[i][j]);
}
printf("\nFile\t index\tlength\n");
for(i=0;i<n;i++)
{
printf("%d\t%d\t%d\n",i+1,sb[i],m[i]);
}
printf("\nEnter file name:");
scanf("%d",&x);
printf("file name is:%d\n",x);
i=x-1;
printf("Index is:%d",sb[i]);
printf("Block occupied are:");
for(j=0;j<m[i];j++)
printf("%3d",b[i][j]);
}

101
OUTPUT:

RESULT:
Thus the indexed file allocation method is implemented successfully

102
EX NO: 14C
FILE ALLOCATION STRATEGIES – LINKED FILE
ALLOCATION
DATE:

AIM:
To Write a C Program to implement Linked File Allocation method.

ALGORITHM:
1: Create a queue to hold all pages in memory
2: When the page is required replace the page at the head of the queue3: Now
the new page is inserted at the tail of the queue
4: Create a stack
5: When the page fault occurs replace page present at the bottom of the stack6: Stop
the allocation.

103
PROGRAM:

#include<stdio.h>
struct file
{
char fname[10];
int start,size,block[10];
}f[10];
main()
{
int i,j,n;
clrscr();
printf("Enter no. of files:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter file name:");
scanf("%s",&f[i].fname);
printf("Enter starting block:");
scanf("%d",&f[i].start);
f[i].block[0]=f[i].start;
printf("Enter no.of blocks:");
scanf("%d",&f[i].size);
printf("Enter block numbers:");
for(j=1;j<=f[i].size;j++)
{
scanf("%d",&f[i].block[j]);
}
}

printf("File\tstart\tsize\tblock\n");
for(i=0;i<n;i++)
{
printf("%s\t%d\t%d\t",f[i].fname,f[i].start,f[i].size);
for(j=1;j<=f[i].size-1;j++)
printf("%d--->",f[i].block[j]);
printf("%d",f[i].block[j]);
printf("\n");
}
}

104
OUTPUT:

RESULT:
Thus the linked file allocation method is implemented successfully.

105
15.A.FIRST COME FIRST SERVE ALGORITHM:

AIM:
To implement FCFS the simplest of all the Disk Scheduling Algorithms. In FCFS, the
requests are addressed in the order they arrive in the disk queue.

ALGORITHM:
1. Start the program
2. Declare the necessary header files
3. Declare the variables which is needed to execute FIFO
4. Get the no of variables RQ[i], using for loop
5. Assign the logic of the FIFO disk scheduling
6. Execute till the process get completed
7. Set the initial head position
8. Print the results TotalHeadMoment
9. Stop the execution

PROGRAM:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int RQ[100],i,n,TotalHeadMoment=0,initial;
printf("Enter the number of Requests\n");
scanf("%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
printf("Enter initial head position\n");
scanf("%d",&initial);
for(i=0;i<n;i++)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
printf("Total head moment is %d",TotalHeadMoment);
return 0;

106
OUTPUT:
Enter the number of Request
8
Enter the Requests Sequence
95 180 34 119 11 123 62 64
Enter initial head position
50
Total head movement is 644
Example: Given the following queue -- 95, 180, 34, 119, 11, 123, 62, 64 with the
Read-write head initially at the track 50 and the tail track being at 199.

RESULT:
Thus the above Disk scheduling FIFS is implemented successfully.

107
15.B.SHORTEST SEEK TIME FIRST (SSTF) ALGORITHM
AIM:

To implement Shortest seek time first (SSTF) algorithm, selects the disk I/O request
which requires the least disk arm movement from its current position regardless of the
direction. It reduces the total seek time as compared to FCFS

ALGORITHM:

10. Start the program


11. Declare the necessary header files
12. Declare the variables which is needed to execute SSTF
13. Get the no of variables RQ[i], using for loop
14. Assign the logic of the SSTF disk scheduling
15. Execute till the process get completed
16. Set the initial head position
17. Print the results TotalHeadMoment
18. Stop the execution

PROGRAM:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int RQ[100],i,n,TotalHeadMoment=0,initial,count=0;
printf("Enter the number of Requests\n");
scanf("%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
printf("Enter initial head position\n");
scanf("%d",&initial);
while(count!=n)
{
int min=1000,d,index;
for(i=0;i<n;i++)
{
d=abs(RQ[i]-initial);
if(min>d)
{min=d;
index=i;
}
}
TotalHeadMoment=TotalHeadMoment+min;
initial=RQ[index];
// 1000 is for max
// you can use any number
RQ[index]=1000; 108
count++;
}
printf("Total head movement is %d",TotalHeadMoment);
return 0;
}

OUTPUT:

Enter the number of Request


8
Enter Request Sequence
95 180 34 119 11 123 62 64
Enter initial head Position
50
Total head movement is 236
Example:-: Given the following queue -- 95, 180, 34, 119, 11, 123, 62, 64 with the Read-
write head initially at the track 50 and the tail track being at 199.

RESULT:
Thus the above Disk scheduling SSTF is implemented successfully.

109
EX.NO.16

DATE: LINUX INSTALLATION USING VMWARE

AIM:
To install the Linux OS using VMware

Note: If your Linux distribution is not RPM-based, has a custom kernel, or is unsupported,
use the steps below to compile VMware Tools.
To install VMware Tools in a Linux guest operating system using Compiler:

1. Ensure that your Linux virtual machine is powered on.

2. If you are running a GUI interface, open a command shell.

Note: Log in as a root user, or use the sudo command to complete each of these steps.

3. Right Click VM in the virtual machine menu, then click Guest > Install/Upgrade
VMware Tools.
4. Click OK.

Note: In some cases, verify that the CDROM device is Connected from within the Edit
Settings option of the virtual machine.

5. To create a mount point, run:

mkdir /mnt/cdrom

6. To mount the CDROM, run:

mount /dev/cdrom /mnt/cdrom

7. To copy the Compiler gzip tar file to a temporary local directory, run:

cp /mnt/cdrom/VMwareTools-version.tar.gz /tmp/

Where version is the VMware Tools package version.

8. To determine the version of VMware tools, run:

ls /mnt/cdrom

You see output similar to:

# VMwareTools-5.0.0-12124.tar.gz

9. To change to the tmp directory and extract the contents of the tar file into a new directory
called vmware-tools-distrib, run:

cd /tmp 110
tar -zxvf VMwareTools-version.tar.gz

10. To change directory to vmware-tools-distrib and run the vmware-install.pl PERL script to
install VMware Tools, run:

cd vmware-tools-distrib
./vmware-install.pl

Notes:
 Complete the screen prompts to install the VMware Tools. Options in square brackets
are default choices and can be selected by pressing Enter.
 To compile VMware Tools successfully, you need gcc Compiler and Linux Kernel
sources provided by your Linux distribution. Consult your Linux distribution
documentation for details on methods to install these packages.
 It is normal for the console screen to go blank for a short time during the installation
when the display size changes.
 Some warnings or errors are normal, like when a files does not exist.
 Depending on the Linux distribution, your network service might restart after
installation. VMware recommends that you invoke this command from the console and
not remotely.

11. If you are running a GUI interface, restart your X Window session for any mouse or
graphics changes to take effect.

12. To start VMware Tools running in the background during an X Window session, using
terminal session run the command

/usr/bin/vmware-toolbox &

13. Depending on your environment, you may need to unmount the CD-ROM. To unmount
the CD-ROM, run:

umount /mnt/cdrom

14. Depending on your environment, you may need to manually end the VMware Tools
installation. To end the VMware Tools install, click VM in the virtual machine menu, then
click Guest > End VMware Tools Install.

15. To remove VMware Tools installation packages, run: cd


rm /tmp/VMwareTools-version.tar.gz
rm -rf /tmp/vmware-tools-distrib

RESULT:

Thus the study exercise for Linux installation using VMware studied successfully.

111

You might also like