OS Lab Manual Final
OS Lab Manual Final
Laboratory 1:
Basics of Operating Systems
Size of memory
1. Windows 7 Starter
This is the bare-bones, 32-bit only version of Windows 7 intended for users in developing
countries, to serve the most basic computing needs.
Starter is designed for lightweight, portable netbooks, though Microsoft claims any of its
versions will be able to run on netbooks.
Home Basic sits somewhere between Starter and Home Premium. It has all the features of
Windows 7 Starter and will also only be available through OEM partners in developing
countries.
Windows 7 Home Premium has all the features of Starter and Home Basic and then some.
This is the mainstream retail version that nearly all consumers will be using. Windows 7
Home Premium will be available worldwide to Microsoft OEMs and sold in retail stores
loaded on new PCs.
4. Windows 7 Professional
Also available worldwide, to OEMs and in retail, Windows 7 Professional has the features of
Home Premium, but with added networking and data protection features for small businesses
and those who frequently work at home.
5. Windows 7 Enterprise
1
Operating System Laboratory Manual
Windows 7 Enterprise is designed for the corporate world and will only be used by
large businesses.
6. Windows 7 Ultimate
Ultimate, the supersize version of Windows, includes all the features of all the other versions.
Think of it as Windows 7 Enterprise for consumers. Ultimate will be the most expensive
version, so it's doubtful that many people will use it other than the occasional super-user who
wants every possible feature. Microsoft is not likely to heavily promote Windows 7 Ultimate.
Most regular users do not need all the security and networking features and there doesn't
appear to be much in Ultimate for businesses that isn't already in Windows 7 Enterprise.
2
Operating System Laboratory Manual
3
Operating System Laboratory Manual
4
Operating System Laboratory Manual
Laboratory 2:
Operating Systems Installation
2. using sotfwares
Eg. Universal USB installer
B. Changing Boot Menu Settings for Linux Windows Dual Boot
- Interrupt the normal boot by pressing the appropriate key.
DELL – F2 or F12
VAIO – Assist Button
ACER – F2
LENOVO – F12
SAMSUNG – F12
HP – F9 Esc
- I recommend you to change the boot option to legacy from UEFI.
C. Installing the new OS
Windows
Ubuntu
5
Operating System Laboratory Manual
1. Enter your computer's BIOS. Turn off the computer that you want to install
Windows on then turn it back on. When the BIOS screen appears or you are
prompted to do so, press Del, Esc, F2, F10, or F9 (depending on your computer’s
motherboard) to enter the system BIOS. The key to enter the BIOS is usually
shown on the screen.
2. Find your BIOS's boot options menu. The boot options menu of your BIOS may
vary in location or name from the illustration, but you may eventually find it if you
search around.
a.i. If you can't find the boot options menu, search the name of your BIOS
(most likely located in the BIOS menu) online for help.
3. Select the CD-ROM drive as the first boot device of your computer.
a.i. Although this method may vary among computers, the boot options
menu is typically a menu of movable device names where you should
6
Operating System Laboratory Manual
set your CD-ROM drive as the first boot device. It can also be a list of
devices that you can set the order of their boot on. Consult a manual or
the internet for help if you're stuck.
4. Save the changes of the settings. Press the button indicated on the screen or select
the save option from the BIOS menu to save your configuration.
5. Shut off your computer. Either turn off the computer by choosing the shut-down
option in your current operating system, or hold the power button until the computer
powers off.
6. Power on the PC and the insert the Windows 7 disc into your CD/DVD drive.
7. Start your computer from the disc. After you have placed the disc into the disc
drive, start your computer. When the computer starts, press a key if you are asked if you
would like to boot from the disc by pressing any key. After you choose to start from the disc,
Windows Setup will begin loading.
a.i. If you are not asked to boot from the disc, you may have done
something wrong. Retry the previous steps to solve the problem.
8. Choose your Windows Setup options. Once Windows Setup loads, you'll be
presented with a window. Select your preferred language, keyboard type, and time/currency
format, then click Next.
10. Accept the License Terms. Read over the Microsoft Software License Terms, check I
accept the license terms, and click Next.
12. Decide on which hard drive and partition you want to install Windows on. A hard
drive is a physical part of your computer that stores data, and partitions "divide" hard drives
into separate parts.
a.i. If the hard drive has data on it, delete the data off of it, or format it.
Select the hard drive from the list of hard drives.
Click Drive options (advanced).
Click Format from Drive options.
a.ii. If your computer doesn't have any partitions yet, create one to install
Windows on it.
Select the hard drive from the list of hard drives.
Click Drive options (advanced).
7
Operating System Laboratory Manual
1.
13. Install Windows on your preferred hard drive and partition. Once you've decided
on where to install Windows, select it and click Next. Windows will begin installing.
Upgrade
An Upgrade installation upgrades an older version of Windows on your computer
(E.G. Windows Vista to Windows 7.)
.1. Scan your computer for malware. Malware can prevent Windows from
installing correctly.
.2. Disable or uninstall any antivirus software because they may interfere
with the Windows installation.
.3. Uninstall some unnecessary programs to speed up the upgrade. You
can install them after Windows 7 has finished.
.4. Update Windows with Windows Update.
.5. Delete some unnecessary files to speed up the upgrade.
.6. Back up your hard drive in case the installation fails and you lose your
files. (optional).
2. Insert your Windows 7 installation disc into the computer at this point.
3. Start Windows Setup. After the disc has loaded, click Start →Computer, double
click the disc drive that Windows 7 Setup was placed in, and double-
click setup.exe on the disc. Allow Setup to start.
8
Operating System Laboratory Manual
5. Decide whether to install updates for Windows Setup. The updates are intended to
fix known problems with Windows Setup and installing updates makes your
installation smoother and more stable. To get updates, click Go Online to get the latest
updates for installation (recommended). To skip updates, click Do not get the latest
updates for installation.
6. Accept the License Terms. Read over the Microsoft Software License Terms,
check I accept the license terms, and click Next.
3. Download the Windows 7 Setup ISO. An ISO file is a disc image. Note: This
download may take a while, depending on your internet speed.
4. Download and install the Windows 7 USB/DVD Download Tool from this link.
5. Once the ISO has finished downloading, open the Windows 7 USB/DVD
Download Tool.
9
Operating System Laboratory Manual
6. Select the ISO. On the Step 1 of 4: Choose ISO file screen of the Windows 7
USB/DVD Download Tool, select the downloaded ISO file by clicking Browse,
then click Next to continue.
8. On the Step 3 of 4: Insert USB device screen, choose the drive you want to
extract the Setup files to, then click Begin copying.
.1. If you receive an error that says Not Enough Free Space, click
the Erase USB Device button, which will erase all of the files on the
drive.
9. Once Windows 7 USB/DVD Download Tool has finished extracting the ISO to the
flash drive, your drive is ready to install Windows.
1. Make sure the drive that Windows 7 Setup was extracted onto is plugged into the
computer.
2. Enter your computer's BIOS. Turn off the computer that you want to install
Windows on then turn it back on. When the BIOS screen appears or you are
prompted to do so, press Del, Esc, F2, F10, or F9 (depending on your computer’s
motherboard) to enter the system BIOS. The key to enter the BIOS is usually
shown on the screen.
10
Operating System Laboratory Manual
3. Find your BIOS's boot options menu. The boot options menu of your BIOS may
vary in location or name from the illustration, but you may eventually find it if
you search around.
o If you can't find the boot options menu, search the name of your BIOS (most
likely located in the BIOS menu) online for help.
o If your drive doesn't show up as a boot device, then your computer doesn't
support it.
o Although this method may vary among computers, the boot options menu is
typically a menu of movable device names where you should set your drive as
the first boot device. It can also be a list of devices that you can set the order of
their boot on individually. Consult a manual or the internet for help if you're
stuck.
5. Save the changes of the settings. Press the button indicated on the screen or select
the save option from the BIOS menu to save your configuration.
6. Shut off your computer. Either turn off the computer by choosing the shut-down
option in your current operating system, or hold the power button until the
computer powers off.
7. Turn your computer back on. Your computer should enter Windows Setup.
o If your computer asks you if you want to boot from a CD by pressing any key,
boot from it. Windows Setup will load.
o Important Information: If you receive a CD/DVD device driver missing error
during Setup at any point, simply click Cancel on the error message which
will return you to the Welcome screen. Once you reach the Welcome screen,
un-plug the USB drive and plug in into another USB port on your computer,
then continue with the installation.
11
Operating System Laboratory Manual
8. Choose your Windows Setup options. Once Windows Setup loads, you'll be
presented with a window. Select your preferred language, keyboard type, and
time/currency format, then click Next.
10. Accept the License Terms. Read over the Microsoft Software License Terms,
check I accept the license terms, and click Next.
12. Decide on which hard drive and partition you want to install Windows on. A
hard drive is a physical part of your computer that stores data, and partitions
"divide" hard drives into separate parts.
o If the hard drive has data on it, delete the data off of it, or format it.
Select the hard drive from the list of hard drives.
Click Drive options (advanced).
Click Format from Drive options.
o If your computer doesn't have any partitions yet, create one to install Windows
on it.
Select the hard drive from the list of hard drives.
Click Drive options (advanced).
Select New from Drive options.
Select the size, and click OK.
13. Install Windows on your preferred hard drive and partition. Once you've
decided on where to install Windows, select it and click Next. Windows will begin
installing.
12
Operating System Laboratory Manual
Upgrade
An Upgrade installation upgrades an older version of Windows on your computer (E.G.
Windows Vista) to Windows 7.
o Scan your computer for malware. Malware can prevent Windows from
installing correctly.
o Disable or uninstall any antivirus software because they may interfere with the
Windows installation.
o Uninstall some unnecessary programs to speed up the upgrade. You can install
them after Windows 7 has finished.
o Update Windows with Windows Update.
o Delete some unnecessary files to speed up the upgrade.
o Back up your hard drive in case the installation fails and you lose your files.
(optional).
3. Make sure the drive that Windows Setup was extracted onto is plugged into your
computer.
4. Start Windows Setup. Click Start →Computer, double click the USB drive that
Windows 7 Setup was extracted to, and double-click setup.exe on the disc. Allow
Setup to start.
6. Decide whether to install updates for Windows Setup. The updates are intended to
fix known problems with Windows Setup and installing updates makes your
installation smoother and more stable. To get updates, click Go Online to get the
13
Operating System Laboratory Manual
latest updates for installation (recommended). To skip updates, click Do not get the
latest updates for installation.
7. Accept the License Terms. Read over the Microsoft Software License Terms,
check I accept the license terms, and click Next.
Part 3 Post-Installation .
These steps carry off after you have finished installing Windows and your computer has
started in Windows 7.
2. Type your password and click Next. If you don't want a password, leave the text
boxes blank and then click Next.
3. Enter your product key then click Next. Your product key is located on the case
of your Windows 7 disc if you purchased the disc. To skip entering your product
key, just click Next, but Windows will run on a 30-day trial, and you'll have to
enter a key once the 30 day trial time is up.
14
Operating System Laboratory Manual
.1.If the computer is connected to your own personal network, choose Home network.
.2.If you are connected to the network at your workplace, choose Work network.
.3.If you're connected to a public network from places such as restaurants and shops,
choose Public network.
8. Once your computer is ready, format your USB drive back to its default settings
(if you chose the Installing Using a Flash Drive or External Drive method). You
can format your USB drive back to its default settings and place your files back
onto it by right clicking your USB drive in Start→Computer, clicking Format,
clicking Restore Device Defaults in Format, then clicking Start, which
permanently deletes any data off of the drive. After the drive has formatted, you
can move your files back onto it.
9. Be sure to reinstall any software you uninstalled, install any device drivers, and
re-enable your security software. Also, to improve your security, run Windows
Update to install the latest security updates.
15
Operating System Laboratory Manual
1. Download the Ubuntu ISO file. You can get the ISO file from the Ubuntu website.
An ISO file is a CD image file that will need to be burned before you can use it. There
are two options available from the Ubuntu website (you can also buy official Ubuntu
CDs, which come in packs of 10):
o Ubuntu builds (not yet released) 16.10, 17.04, and 17.10 will
come with limited support. They will have the newest
features, though they may not work with all hardware.
These releases are geared more towards experienced Linux
users.
2. Burn the ISO file. Open up your burning program of choice. There are free and
paid programs available that can burn an ISO to a CD or DVD.
3. Boot from the disc. Once you have finished burning the disc, restart your
computer and choose to boot from the disc. You may have to change your boot
16
Operating System Laboratory Manual
preferences by hitting the Setup key while your computer is restarting. This is
typically F12, F2, or Del.
4. Try Ubuntu before installing. Once you boot from the disc, you
will be given the option to try Ubuntu without installing it. The
operating system will run from the disc, and you will have a
chance to explore the layout of the operating system.
o Open the Examples folder to see how Ubuntu handles files and
exploring the operating system.
o Once you are done exploring, open the Install file on the
desktop.
17
Operating System Laboratory Manual
o Once you are satisfied with your settings, click Install Now.
10. Set your keyboard layout. You can choose from a list of
options, or click the Detect Keyboard Layout button to have
Ubuntu automatically pick the correct option.
18
Operating System Laboratory Manual
11. Enter your login information. Enter your name, the name of the
computer (which will be displayed on the network), choose a
username, and come up with a password. You can choose to
have Ubuntu automatically log you in, or require your
username and password when it starts.
2. Using Installer
19
Operating System Laboratory Manual
Laboratory 3:
Introduction to UNIX terminal
Objective:
This Lab is an introduction and review of the UNIX operating system. We are going to use
the operating system for the rest of the course so it is advisable that you follow the steps and
carry out the examples and exercises. The followings are the primary objectives of this lab
session:
Understanding UNIX File System.
Be able to execute commands using the UNIX shell.
Create and manipulate directories.
Create, edit and manipulate files.
Be familiar with command line text editors provided by UNIX.
20
Operating System Laboratory Manual
Introduction:
In Unix, all file systems (Hard Disks, CD-ROMs, Floppy Disks, ZIP drives, network
mounts, etc …) are “mounted” onto one logical tree. The top of the hierarchy is
traditionally called root which is represented by a / (slash).
Examples: Use the above diagram and assume that your current working directory
(your current position in the file system) is ugics:
1. A file named “test.txt” is placed inside the directory “st111111”.
The absolute (full) path is: /home/ugis/st111111/test.txt
The relative path is: st111111/test.txt OR ./st111111/test.txt
2. A file named “csh” is placed inside the directory “bin”.
The absolute (full) path is: /bin/csh
The relative path is: ../../bin/csh
3. A directory named “st123456” is placed inside the directory “ugics”.
The absolute (full) path is: /home/ugics/st123456
The relative path is: st123456 OR ./st123456
Procedures: Open the shell (terminal) and follow the following procedures
To open the terminal use the following options and appears as shown in the above
ctrl + alt + T
or on the dash home type ‘terminal'
or go to Applications – Accessories - terminal
21
Operating System Laboratory Manual
22
Operating System Laboratory Manual
23
Operating System Laboratory Manual
Laboratory 4:
Working with files
24
Operating System Laboratory Manual
25
Operating System Laboratory Manual
- This will clear all text and leave you with the $ prompt at the top of the window.
cat (concatenate)
- The command cat can be used to display the contents of a file on the screen.
Example: To verify your wok in previous section, you can view the content of
hello.txt by typing:
cat hello.txt
- The cat command is useful for displaying short files of a few lines. To display longer
files use less or more commands.
5. Copying Files
cp (copy)
- The cp command allows you to copy a file from one location to another location. There
are different syntaxes to use cp command as shown below:
Syntax 1: ( copy a file to another file)
cp file1 file2
- Where file1 is the name of an existing file and file2 is the name for the new copy of that
file. The original file will remain unchanged and a copy will be placed in file2. If file1 and file2
are not in current directory, then you have to specify their pathname.
Syntax 2: (copy a file to another directory)
cp file directory e.g cp A ~Desktop
- Where file is the name of an existing file and directory is the name for the destination
directory. The original file will remain unchanged and a copy will be placed in that directory.
Exercise:
2. Create a directory called backup inside the current directory. Create a backup
of your hello.txt file into another file called backup.txt which is inside backup
directory and verify the file being copied by using the list command ls.
3. What does the following command does?
cp hello.txt ..
4. Copy the file named “hello.txt” to your home directory? Verify
your work.
6. Moving Files
mv (move)
- To move a file from one place to another, use the mv command. This has the effect of
moving rather than copying the file, so you end up with only one file rather than two. It can
also be used to rename a file, by moving the file to the same directory, but giving it a different
name. (mv hello.txt ~/helloo.txt)
Example: We are going to move the file “hello.txt” to the backup directory, type
mv hello.txt backup
Exercises
1. Rename the file hello.txt to goodbye.txt by using only the mv command.
7. Getting Help
In order to get information about commands, how they can be used, their options and
arguments, we can use different options.
man
26
Operating System Laboratory Manual
The UNIX man pages (man is short for manual) cover every command available. To
search for a man page, enter man followed by the name of the command you want to
find, UNIX will provide the manual or reference provided for that command.
man command_name
Info
The info command is similar to man, but is often more in-depth.
info command_name
This will provide the info page for the given command. If you need to know the
details of a given command you can use either info or man commands.
whatis
Displays short descriptions of commands. This is especially helpful if you just want to see the
basic structure and description of a given command.
whatis command_name
--help
It displays usage summary and argument list of a given command. It gives more
detailed description and argument list than whatis command but it doesn’t provide as
detailed information as man and info commands.
command_name --help
Exercises
1. Use the helps described above and understand the use and
function of the following commands, more, less, grep, wc, ps, id.
Laboratory 5:
More on UNIX and shell commands
Objective:
This Lab is a continuation of review of the UNIX system. We are going to see more basic
commands that are used in UNIX shell. The followings are the primary objectives of this lab
session:
Be able to use more additional commands used for processing files in UNIX
shell and execute them.
Be able to perform simple searches on files using shell commands
Understand and implement input and output redirection.
Understand file protection in UNIX and changing file permissions using the
shell commands.
Creating and executing shell scripts.
Procedures: Open the shell (terminal) and follow the following procedures
Practical 1: Working with additional commands on files.
Create a file called hello.txt on your current directory and follow the following procedures.
Make sure that you have written more than 10 lines of text on the file.
1 Displaying the contents of files.
cat is short for concatenate. This command is used to create, view and concatenate
files.
cat /etc/passwd
27
Operating System Laboratory Manual
This command displays the "/etc/passwd" file on your screen. Notice that
some of the contents of this file may scroll off of your screen.
less The command less writes the contents of a file onto the screen a page at a
time. Type
less hello.txt
Press the [space-bar] if you want to see another page, type [q] if you want to quit
reading. As you can see, less is used in preference to cat for long files.
head: The head command writes the first ten lines of a file to the screen. First
clear the screen then type
head hello.txt
tail: The tail command writes the last ten lines of a file to the screen. Clear the
screen and type
tail hello.txt
1 Concatenating two or more files
cat command can also be used to concatenate two or more files into a single file.
First create a file called goodbye.txt and write some text on it. Then type the
following command.
$ cat hello.txt goodbye.txt > combined.txt
This command combines the contents of the first two files into the third file. We
can also give more than two files to be concatenated.
wc (word count) : A handy little utility is the wc command, short for word count.
To do a word count on hello.txt, type
wc hello.txt
This will display three values, the number of new lines, the number of words
and the number of bytes in the given file. To get only the word count, type:
wc -w hello.txt
To find out how many lines the file has, type:
wc -l hello.txt
1 Simple searching on files
1 Using less to search on files
Using less, you can search though a text file for a keyword (pattern).
For example, to search through hello.txt for the word 'science', type
less hello.txt
then, still in less (i.e. don't press [q] to quit), type a forward
slash [/] followed by the word to search
/science
As you can see, less finds and highlights the keyword. Type [n] to
search for the next occurrence of the word.
1 Using grep to search on files.
grep is one of many standard UNIX utilities. It searches files for
specified words or patterns. First clear the screen, then type
grep science hello.txt
As you can see, grep has printed out each line containing the word
science. Try typing
grep Science hello.txt
The grep command is case sensitive; it distinguishes between Science
and science. To ignore upper/lower case distinctions, use the -i option, i.e.
type
28
Operating System Laboratory Manual
?
The character ? will match exactly one character. It will be used to
match only a single character in a file or directory. So typing:
ls ?ouse
will match files like house and mouse, but not grouse.
ls ?list
Will match every word with five letters and ending with list.
Exercise:
1 Type the following on the shell
head -5 hello.txt
What difference did the -5 do to the head command?
1 How can you view the last 15 lines of the file? Use the help provided by UNIX
to answer the question.
2 List all .txt files that are found on the current directory.
3 Create and save a text file called text.txt, write the following text inside the
file.
This is the second laboratory for systems programming.
Last time we saw some basic file and directory commands.
Today we are adding more commands that are used for manipulating,
displaying and searching files.
Once you finished editing and saved the file perform the following operations.
1.1. Display the number of words and lines in the above file.
1.2. Search for a single word from the file.
1.3. Search a phrase of two or more words from the file.
1.4. Search for all words that end with the phrase is.
29
Operating System Laboratory Manual
1.5. Search for all words that end with t and have a minimum length
of four letters.
1 Input redirection
We use the < symbol to redirect the input of a command. The
command sort alphabetically or numerically sorts a list. Type
sort
Then type in the names of some fruits. Banana, apple, orange, pear and then
Press [Enter] after each one.
The output will be searched and displayed as follows:
apple
banana
Orange
pear
Using < you can redirect the input to come from a file rather than the
keyboard. For example, to sort the list of fruit in the file, type:
sort < fruits.txt
And the sorted list will be output to the screen. To output the sorted list to a
file, type:
sort < fruits.txt > sorted_fruits.txt
Use cat to read the contents of the file in sorted_fruits.txt and see if the fruits
are sorted. Similarly any command's input can be redirected from any given file.
30
Operating System Laboratory Manual
1 Pipes
To see who is on the system with you or see other users who are currently
logged into the system, type:
who
One method to get a sorted list of names is to type,
who > names.txt
sort < names.txt
This is a bit slow and you have to remember to remove the temporary file
called names when you have finished. What you really want to do is connect the
output of the who command directly to the input of the sort command. This is
exactly what pipes do. The symbol for a pipe is the vertical bar |
For example, typing
who | sort
Will give the same result as above, but quicker and cleaner.
To find out how many users are logged on, type
who | wc -l
Exercise:
1. Create a backup of the file called text.txt which you have created in the previous
exercise inside a directory called backup using output redirection.
2. Use the cat command to create a file containing the following data which will be
obtained from the keyboard. Call the file mytable, use tabs to separate the fields
1425 Solmon 15.65
4320 Addis 26.27
6830 Selam 36.15
1450 Mamo 21.86
Each file (and directory) has associated access rights, which may be found by typing ls
-l. Also, ls -lg gives additional information as to which group owns the file.
-rwxrw-r-- 1 ee51ab beng95 2450 Sept29 11:52 file1
In the left-hand column is a 10 symbol string consisting of the symbols d, r, w, x, -,
and, occasionally, s or S. If d is present, it will be at the left hand end of the string, and
indicates a directory: otherwise - will be the starting symbol of the string.
The 9 remaining symbols indicate the permissions, or access rights, and are taken as
three groups of 3.
The left group of 3 gives the file permissions for the user that owns the
file (or directory) (ee51ab in the above example);
31
Operating System Laboratory Manual
The middle group gives the permissions for the group of people to
whom the file (or directory) belongs (eebeng95 in the above example);
The rightmost group gives the permissions for all others.
The symbols r, w, etc., have slightly different meanings depending on whether they
refer to a simple file or to a directory.
Access rights on files.
r (or -), indicates read permission (or otherwise), that is, the presence or
absence of permission to read and copy the file
w (or -), indicates write permission (or otherwise), that is, the
permission (or otherwise) to change a file
x (or -), indicates execution permission (or otherwise), that is, the
permission to execute a file, where appropriate
-rwxrwxrwx A file that everyone can read, write and execute (and delete).
-rw------- A file that only the owner can read and write - no-one else
can read or write and no-one has execution.
Symbol Meaning
u User
g Group
o Other
a All
r Read
w write (and delete)
x execute (and access directory)
+ add permission
- take away permission
32
Operating System Laboratory Manual
For example, to remove read write and execute permissions on the file fruits for the
group and others, type
$ chmod go-rwx fruits.txt
This will leave the other permissions unaffected. To give read and write permissions on
the file fruits to all,
$ chmod a+rw fruits.txt
Use ls -l to check that the permissions have changed.
33
Operating System Laboratory Manual
Laboratory 6:
Editing, compiling and running C programs in UNIX
Objective:
In this lab we are going to start working on C programming under the UNIX operating
system. We will demonstrate how we can edit, compile and execute C programs using the
UNIX operating system. The followings are the primary objectives of this lab session:
Be able edit C programs using command line text editors in UNIX.
Using shell commands to compile and execute C programs under UNIX OS.
Use the gcc compiler driver to interact with different C facilities.
Use command options to manipulate the compilation and execution of C
programs.
34
Operating System Laboratory Manual
Hello Universe
Practical 1: Write a simple C program and execute it.
Write the following C program and save it in a file called hello.c.
#include<stdio.h>
void main()
{
printf(“ Hello Universe “);
}
Compile the file using the gcc compiler driver in the shell
$ gcc –o hello hello.c
Execute the executable file and see the output
$. /hello or $ hello
35
Operating System Laboratory Manual
Exercise: What do you understand from the generated file from the assembler? What
do you think is the function of the assembler? What type of file is generated by the
assembler?
6. Use the gcc compiler driver and link test.o file and see the output of the linker.
$ gcc test.o –o test
Exercise: What do you understand from the generated file from the linker? What do you
think is the function of the linker? What type of file is generated from the linker?
Laboratory 7:
More on C programs in UNIX
void swap();
void display();
int array[2] = {25,50};
void main(){
printf("\nBefore Swap\n");
display();
36
Operating System Laboratory Manual
swap();
printf("\nAfter Swap\n");
display();
}
3. Write the following C program and save it using the name swap.c.
#include<stdio.h>
#include"head.h"
void swap(){
int temp = array[0];
array[0] = array[1];
array[1] = temp;
}
void display(){
printf("\nElement O : %d \n",array[0]);
printf("\nElement 1 : %d \n\n",array[1]);
}
37
Operating System Laboratory Manual
Laboratory 8:
Different simulations on C programs in UNIX
38
Operating System Laboratory Manual
39