Operating System Manual
Operating System Manual
Operating System Manual
Operating System
(CS – 330)
Fall Semester
PREPARED BY
Lab manual is prepared by Dr. Hammad Afzal and Lab Engr Umar Mahmud under the supervision of Head of
Department Dr. Naveed Iqbal Rao in year 2012.
GENERAL INSTRUCTIONS
a. Students are required to maintain the lab manual with them till the end of the semester.
b. All readings, answers to questions and illustrations must be solved on the place provided. If more space is
required then additional sheets may be attached.
c. It is the responsibility of the student to have the manual graded before deadlines as given by the instructor
d. Loss of manual will result in re submission of the complete manual.
e. Students are required to go through the experiment before coming to the lab session. Lab session details will
be given in training schedule.
f. Students must bring the manual in each lab.
g. Keep the manual neat clean and presentable.
h. Plagiarism is strictly forbidden. No credit will be given if a lab session is plagiarised and no re submission
will be entertained.
i. Marks will be deducted for late submission.
Grand Total
4. Operating System is an intermediary between the user of a compute machine and the
underlying hardware. The major need of an OS is to provide a convenient means to the user for
machine operation. Moreover, the OS also solves the user problems as well as hides the
complexities of the underlying hardware.
Operating System
Introduction
A computer system can be divided into 4 components:
An Operating system is software that creates a relation between the User, Software and
Hardware. It is an interface between the all. All the computers need basic software known as an
Operating System (OS) to function.
The OS acts as an interface between the User, Application Programs, Hardware and the System
Peripherals. The OS is the first software to be loaded when a computers starts up. The entire
application programs are loaded after the OS.
1. Single User: If the single user Operating System is loaded in computer’s memory; the computer
would be able to handle one user at a time.
Ex: MS-Dos, MS-Win 95-98, Win-ME
1. Multi user: If the multi-user Operating System is loaded in computer’s memory; the computer
would be able to handle more than one user at a time.
Ex: UNIX, Linux, XENIX
2. Network: If the network Operating System is loaded in computer’s memory; the computer would
13. What happens when we type IPCONFIG? What happens when IPCONFIG/ALL is typed?
14. Windows
18. In the Performance Tab, What are the current CPU usage, the Paged pool?
What is your computer’s RAM type?
19. In the Users tab? Who all are the current users? Can users be switched in windows? If so how?
20. What is the total number of Handles, Threads and Processes currently on your machine?
Where did you find it?
21. Disk Manager: Right click on My Computer and select Manage. Go to storage and then Disk
Management. What is displayed?
23. Device Manager: Select device manager. Disable and then Enable the sound driver. What
facility is provided in Device Manager?
24. Describe how can you get the MAC address of your PC and mobile phone? Write the
command/procedure and the MAC address
/bin - Contains common Linux user commands, such as ls, sort , date etc.
/boot - Has the bootable Linux kernel and boot loader configuration files (GRUB).
/dev - Contains files representing access points to devices on your systems. These include
terminal devices ( tty* ), floppy disks ( fd* ), hard disks ( hd* or sc* ), RAM ( ram* ), and CD-
ROM ( cd* ). (Applications normally access these devices directly through the device files,
but end users rarely access them directly.)
/etc - Contains administrative configuration files.
/home - Contains directories assigned to each user with a login account.
/media - Provides a location for mounting devices, such as remote file systems and
removable media (with directory names of cdrom , floppy , and so on). In Fedora and RHEL,
many removable media are mounted automatically in this directory when the media is
inserted (CD or DVD) or connected (USB pen drives or cameras ).
/proc - Provides a mechanism for the kernel to send information to processes.
/root - Represents the root user's home directory.
/sbin - Contains administrative commands and daemon processes.
/sys - A /proc -like file system, added with the Linux 2.6 kernel and intended to contain files
for getting hardware status and reflecting the system's device tree as it is seen by the
kernel. It pulls many of its functions from /proc .
/tmp - Contains temporary files used by applications.
/usr - Contains user documentation, games , graphical files (X11), libraries (lib), and a variety
of other user and administrative commands and files.
o /var - Contains directories of data used by various applications. In particular, this is
where you would place files that you share as an FTP server ( /var/ftp ) or a Web
server ( /var/www ). It also contains all system log files ( /var/log ). In time, FTP,
HTTP, and similar services will move to the /srv directory to adhere to the Linux
Standards Base ( www.freestandards.org/spec ).
5. Using Terminal: Terminal is Command Line Interface of Ubuntu.
(a). Methods to load terminal are : -
(1) Dash -> Search for Terminal
(2) Dash -> More Apps -> 'See More Results' -> Terminal
(3) Dash -> More Apps -> Accessories -> Terminal
(4) Keyboard Shortcut: Ctrl + Alt + T
(5) Type help to view commands
6.
Finally to terminate the unix session execute the command exit or logout.
15. Which is better System Monitor or Task Manager? Give your thoughts.
16. Use the Device Manager in Ubuntu. Disable and Enable the Sound Driver. What facility is
provided in Device manager?
19. Resources
https://help.ubuntu.com/
http://showmedo.com/videotutorials/ubuntu
Summary:
In this experiment we have learned how to perform basic tasks in Ubuntu, change network
settings and how to create java codes in Ubuntu.
4. Process States: As a process executes, it changes state. The states of a process are: -
(a). New: The process is being created
(b). Running: Instructions are being executed
(c). Waiting: The process is waiting for some event to occur
(d). Ready: The process is waiting to be assigned to a process
(e). Terminated: The process has finished execution
5. Process State Model: Process state models describe the life cycle of a process. The
Process State Model is given in Figure 1.
8. For the information in following set create the trace and show the output.
(a). Example 1
(b). Example 2
9. Applet at http://courses.cs.vt.edu/csonline/OS/Lessons/Processes/index.html
Summary
In this experiment we have learned and simulated 5-state process model using examples.
5. Using getpid(): This function returns the pid of the current program. Use the
following code and write the output.
int main(){
int pid;
pid = getpid();
printf(“Process ID is %d\n”, pid);
return 0;
}
6. Using getppid()
This function returns the pid of the parent process.
int main(){
int ppid;
ppid = getppid();
printf(“Parent Process ID is %d\n”, ppid);
return 0;
}
What is the outcome?
7. Using fork():
Summary:
In this experiment we have learned how to create processes in Ubuntu and
Windows.
The calls with v in the name take an array parameter to specify the argv[]
array of the new program.
The calls with l in the name take the arguments of the new program as a
variable-length argument list to the function itself.
The calls with e in the name take an extra argument to provide the
environment of the new program; otherwise, the program inherits the
current process's environment.
The calls with p in the name search the PATH environment variable to find
the program if it doesn't have a directory in it (i.e. it doesn't contain a /
character). Otherwise, the program name is always treated as a path to the
executable.
5.
Using Execlp: execlp allows you to specify all the arguments as parameters to the
function. Note that the first parameter is the command. The second parameter is the
first argument in the argument list that is passed to the program (argv[0]). These are
often the same but don't have to be. The last parameter must be a null pointer.
More help can be found here http://www.cs.rutgers.edu/~pxk/416/notes/c-
tutorials/exec.html
6.
What is the outcome of this program?
/* This program forks a separate process using the fork()/exec() system calls.
* * Figure 3.10*
* @author Gagne, Galvin, Silberschatz Operating System Concepts - Seventh
Edition
#include <stdio.h>
#include <unistd.h>
#include<stdlib.h>
#include <sys/types.h>
int main(){
pid_t pid;
pid = fork(); // fork a child process
if (pid < 0) { // error occurred
perror (“fork failed”); // prints error message
exit(-1);
}
else if (pid == 0) { // child process
printf ("I am the child %d\n",pid);
execlp ("/bin/ls","ls",NULL);
}
else { // parent process
printf ("I am the parent %d\n",pid);
wait (NULL); // parent will wait for the child to
complete
7.
Creating a Process in Windows:
/**
* This program creates a separate process using the CreateProcess() system call.
Figure 3.12
* @author Gagne, Galvin, Silberschatz Operating System Concepts - Seventh
Edition
* Copyright John Wiley & Sons - 2005.
*/
#include <windows.h>
#include <stdio.h>
int main( VOID ){
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) ); // Start the child process.
if( !CreateProcess( NULL, // No module name (use command line).
"C:\\WINDOWS\\system32\\mspaint.exe", // Command line.
Summary:
In this experiment we have learned how to create processes in Windows and
learned exec and execlp commands.
10. To get the exit value modify the code as follows. What is the output?
import java.util.*;
import java.io.*;
import java.lang.management.*;
public class JavaExec {
public static void main(String args[]){
try {
System.out.println(ManagementFactory.getRuntimeMXBean().getName());
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("mspaint"); // execute mspaint
Thread.sleep (5000); // system sleeps for 5
seconds
proc.destroy (); // close mspaint
int exitVal = proc.waitFor();
System.out.println("Process exitValue: " + exitVal);
}
catch (Exception t){
t.printStackTrace();
}
}
}
11 Re-execute point 6 but close the application in windows before the time expires.
Write the output here.
13. Challenging Task: Make a program of CLI (Command Line Interface) which can
understand the command “Open <App_Name>” and “Close <App_Name>” and
open and close the mentioned application.
12. What is your learning in this experiment? Are threads better than processes? Why?
13. References
1. http://docs.oracle.com/javase/6/docs/api/java/lang/Thread.html [MUST
VISIT]
Summary:
In this experiment we have learned how to use and synchronize threads in Java.
14. Calculate average wait time for each algorithm and for all three states on Points 10,
11 and 12. Average wait time is the sum of waiting times by each process divided by
the total number of processes
15. What is your conclusion based on the throughput and average wait time as well as the
type of input.
16. Resources
http://www.cosmolearning.com/video-lectures/concurrency-processes-threads-and-
address-spaces-7406/
17. Video Links
http://www.youtube.com/watch?v=FiGKndlvO8I
http://www.youtube.com/watch?v=u9VOokHuXIA
http://www.youtube.com/watch?v=bta48Ix3t_Q
Summary:
In this experiment we have learned process scheduling and simulated scheduling algorithms and
then compared them based on their throughput and wait time.
8. References
1. http://www.cs.rutgers.edu/~pxk/416/notes/07-scheduling.html
2. http://sharingmythreeyears.blogspot.com/
9. Video
http://www.youtube.com/watch?v=6vk2yMwa2n0
http://www.youtube.com/watch?v=XONQb3dj78g
9.
Create a program which can create any number of threads user inputs. Create a
semaphore that implements a semaphore for mutual exclusion. Also implement
threads that acquire the use of a shared resource through the shared semaphore in
similar critical section. Threads should implement the wait and signal method having
similar handler. Show the output. (10 marks)
10. References
http://en.wikipedia.org/wiki/Semaphore_(programming)
http://elvis.rowan.edu/~hartley/ConcProgJava/Semaphores/bbou.java
http://www.cs.loyola.edu/~jglenn/702/F2007/Examples/Producer_Consumer_Semap
hores/pc_semaphore.html
http://www.amparo.net/ce155/sem-ex.html
11. Video Link
http://freevideolectures.com/Course/2260/Computer-Science-III-Programming-
Paradigms/16
Summary
In this experiment we have implemented semaphores for scheduling processes in
operating system
Create a program which can create any number of threads user inputs. Create a
semaphore that implements a semaphore for mutual exclusion. Also implement
threads that acquire the use of a shared resource through the shared semaphore in
similar critical section. Threads should implement the wait and signal method having
similar handler(acquire/release). Show the output. (10 marks)
9. References
http://en.wikipedia.org/wiki/Semaphore_(programming)
http://elvis.rowan.edu/~hartley/ConcProgJava/Semaphores/bbou.java
http://www.cs.loyola.edu/~jglenn/702/F2007/Examples/Producer_Consumer_Semap
hores/pc_semaphore.html
http://www.amparo.net/ce155/sem-ex.html
39 CS 330 Operating Systems – Process
10. Video Link
http://freevideolectures.com/Course/2260/Computer-Science-III-Programming-
Paradigms/16
Summary
In this experiment we have implemented semaphores for scheduling processes in
operating system
First Fit
First Fit simply scans the free list until a large enough hole is found. Despite the
name, first-fit is generally better than best-fit because it leads to less
fragmentation. Small holes tend to accumulate near the beginning of the free list,
6. making the memory allocator search farther and farther each time. Solution: Next
Fit
Best Fit
The allocator places a process in the smallest block of unallocated memory in
which it will fit. It requires an expensive search of the entire free list to find the
best hole. More importantly, it leads to the creation of lots of little holes that are
not big enough to satisfy any requests. This situation is called fragmentation, and
is a problem for all memory-management strategies, although it is particularly bad
for best-fit. One way to avoid making little holes is to give the client a bigger block
than it asked for. For example, we might round all requests up to the next larger
multiple of 64 bytes. That doesn't make the fragmentation go away, it just hides it.
Unusable space in the form of holes is called external fragmentation
7. Algorithm
Start the program.
(a). Get the number of segments and size.
(b). Get the memory requirement and select the option.
(c). If the option is ‘2’ call first fit function.
(d). If the option is ‘1’ call best fit function.
(e). Otherwise exit.
(f). For first fit, allocate the process to first possible segment which is free.
(g). For best fit, do the following steps.
a. Sorts the segments according to their sizes.
9. Resources: https://en.wikipedia.org/wiki/Memory_management
Video http://www.youtube.com/watch?v=PSPF_ELJ0cY
Summary: In this experiment we have written codes and implemented best fit and
first fit algorithms used in memory management.
7. Resources
https://en.wikipedia.org/wiki/Memory_management
Video
http://www.youtube.com/watch?v=PSPF_ELJ0cY
Summary:
all:
make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules
45 CS 330 Operating Systems – Process
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) clean
(b). The first line should show the name of your file with .o extension after the
+= characters.
(c). Do not forget to put a tab character before make in both instances of the
keyword make.
(d). In the terminal type sudo make. If asked for the password type in the
password.
(e). What is the outcome of this step (if correctly executed)? Show the output as
well as the names of the files created in the working directory.
(f). Use modinfo hello-1.ko to see what kind of information it is. Show the
output here.
7. Loading Module: To load the module in kernel, type sudo insmod ./hello-1.ko
and remember to rename hello-1 if you have different file name.
8. Type lsmod and see if the module is loaded. Show the screen capture here. (1)
9. Viewing Log: To view log type dmesg. Show the output here. (1)
10. Removing Modules: To remove module type sudo rmmod hello-1 and remember
to rename hello-1 if you have different file name.
11. Type lsmod and see if the module is unloaded.
12. Type dmesg again and show the output here. (1)
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) clean
10. Remove the modules by typing sudo rmmod hello-1 and then sudo rmmod hello-
2
11. Show the output of dmesg (1)
Summary:
In this experiment we have learned how to develop and removes modules in Linux .