Professional Documents
Culture Documents
Laboratory Manual: Applied Operating System (IT 607)
Laboratory Manual: Applied Operating System (IT 607)
For
B.Tech (IT)
SEM VI
June 2010
Faculty of Technology
Dharmsinh Desai University
Nadiad.
www.ddu.ac.in
Table of Contents
EXPERIMENT-1
Study of UNIX commands with all their important options ........................................................ 5
EXPERIMENT-2
Program maintenance using make utility. ...................................................................................... 6
EXPERIMENT-3
Study system calls related to process & process control ............................................................... 7
EXPERIMENT-4
Study system calls related to file operations. ................................................................................. 8
EXPERIMENT-5
Study of functions related to threads (POSIX)………………………………………………….9
EXPERIMENT-6
Inter process communication (POSIX-IPC) using pipe……………………………………….10
EXPERIMENT-7
Inter process communication (POSIX-IPC) using shared memory ............................................. 11
EXPERIMENT-8
Study system calls related to semaphore………………………………………………………12
EXPERIMENT-9
Simulation of Process scheduling algorithm: Feedback policy……………………………….13
EXPERIMENT-10
Simulation of I/O requests scheduling algorithm: Elevator algorithm………………………..14
EXPERIMENT-11
Simulation of deadlock handling algorithm: Banker’s algorithm................................................ 15
EXPERIMENT-12
Simulation of Memory management algorithm: LRU page replacement algorithm. ................. 16
Sample experiment
1 AIM: Inter process communication (POSIX-IPC) using shared memory
Problem: Establish Inter process communication using shared memory. Implement day time
server and test it using client program.
2 TOOLS/APPARATUS: gcc, libpthread.so library
3 STANDARD PROCEDURES:
3.1 Analyzing the Problem:
Two entities are needed: (1) client (2) server.
Client and server will communicate using shared memory, so, shared memory region is
needed.
Shared memory will be used by both server and client, so, for synchronization semaphore
is needed.
Server provided time-server facility, so, to access time, time() and ctime() functions are
needed.
//Open a file
fd=open(argv[1],O_RDWR|O_CREAT,FILE_MODE);
//Write content of structure to opened file
write(fd,&sharedv,sizeof(struct shared));
ptr=mmap(NULL,sizeof(struct
shared),PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
close(fd);
//initialize semaphore
sem_init(&ptr->sem,0,1);
setbuf(stdout,NULL);
time(&timeval);
strcpy(ptr->dateval,ctime(&timeval));
//create a new process using fork, assign duty of client to child process
if(fork()==0){ //child:client
while(choice=='y'){
//lock semaphore before reading shared memory
sem_wait(&ptr->sem);
printf("Current date-time is %s\n",ptr->dateval);
//unlock semaphore after reading shared memory
sem_post(&ptr->sem);
printf("Do you want to know current date, Enter your choice (y/n)=");
scanf("%c",&choice);
getchar();
}
exit(0);
}
//assign duty of server to parent process
//parent:server
while(1){
//get current time value
time(&timeval);
//lock semaphore before writing to shared memory
sem_wait(&ptr->sem);
strcpy(ptr->dateval,ctime(&timeval));
//unlock the semaphore after writing is over
sem_post(&ptr->sem);
sleep(1);
}
}
4 Conclusions:
Both the client and server perform their activities. As we are using semaphore operations while
accessing shared memory, we do not get any corrupted date value as output.
COMMON PROCEDURE
The common procedure for solving programming related problems is as follows:
Step 1: For given problem statement, find out the names of required system calls.
Step 2: Study and understand the usage of those system calls.
Step 3: Design the logic for solving the given problem.
Step 4: Implement the logic in C programming code.
Step 5: Compile the program using make utility
Step 6: Run the program by passing the appropriate command line arguments
Step 7: Note down the output and draw your conclusion.
EXPERIMENT-1
Procedure:
1. For each command, read the documentation from man pages, e.g., using man command.
2. Study important options
3. Execute the command with options and study the output.
EXPERIMENT-2
Procedure:
1. Write a program that is spread over two files.
2. Use following Makefile for program maintenance. To use make utility, use make
command.
Makefile
test.out: test.o
cc test.o –o test.out
test.o: test.c test.h
cc test.c –c
clean:
rm –f *.o *.*~ *~
run:
./test
EXPERIMENT-3
Procedure:
Use common procedure
EXPERIMENT-4
Procedure:
Use common procedure
EXPERIMENT-5
Procedure:
Use common procedure
EXPERIMENT-6
Procedure:
Use common procedure
EXPERIMENT-7
Procedure:
Use common procedure
EXPERIMENT-8
Procedure:
Use common procedure
EXPERIMENT-9
Procedure:
Use common procedure
EXPERIMENT-10
Procedure:
Use common procedure
EXPERIMENT-11
Procedure:
Use common procedure
EXPERIMENT-12
Procedure:
Use common procedure
EXPERIMENT-13
Aim: Installation of Virtual Machine Software and installation of Operating System on Virtual
Machine.
Tools / Apparatus: Windows XP OS, Source of Linux OS, Sun Virtual Box
Procedure:
1. Install Sun Virtual Box software on Windows XP OS.
2. Run Virtual Box
3. Click New to set up a new virtual machine profile and follow the wizard.
4. Title your virtual machine. e.g. Red Hat Linux
5. VirtualBox will try to guess how much RAM to allocate for the virtual machine. If you
have 1 GB of RAM, 512 MB might be a good allocation.
6. Create a virtual hard drive to install OS.
7. Configure CD ROM settings.
8. Select the newly created virtual machine profile and click Start.
9. After it boots up, click the Install icon on the desktop.
10. Answer all the questions.
11. After installation is over, now you can start/shutdown/use Linux OS on Windows XP OS.
EXPERIMENT-14
Aim: Intercepting and recording the system calls made by a running process using strace tool.
Procedure:
1. Study strace command with its options.
2. Create an executable file or use some existing executable file.
3. Run the executable file using strace. strace -o strace-echo-output.txt echo "Hello there"
4. Note down the output listing of strace generated for selected executable file.
5. Understand the use of system calls by the created process. e.g., echo
References