| Current Path : /var/www/html/bibhas.ghoshal/lab_files/ |
| Current File : /var/www/html/bibhas.ghoshal/lab_files/lab2.tex |
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{color}
%opening
\title{Lab 5 : IPC mechanism using semaphores}
%\author{}
\begin{document}
\maketitle
\underline{\textbf{Objective : }}
\begin{itemize}
\item Lab 5 is intended to learn IPC mechanism by solving the sleeping barber problem. The lab requires knowledge of threads and semaphore creation and usage. A pre-requisite exercise (Synchronizing Threads with POSIX Semaphores) has been provided (link provided on the course website) so that you learn how to creat and work with semaphores. You are expected to complete the pre-requisite before starting Lab 5. You are also provided with three c-files: shm.c (describes how to use shred memory), sem.c (using semaphores) and producer_consumer.c (solution to produser consumer problem). You are expected to run these files and study them before starting Lab5.
\end{itemize}
You are expected to refer to the references mentioned in the course website befor you start the lab.\\
\underline{\textbf{Assignments:}}
\begin{enumerate}
\item Use the \emph{ps} command to display the process attributes.
\item Learn the \emph{top} command to display the resource utilization statistics of processes
\begin{itemize}
\item Open a terminal and type the \emph{top} command
\item Start a browser and see the effect on the \emph{top} display
\item Compile a C program and observe the same effect (Use a long loop - say while(1) to observe the effect)
\item From the \emph{top} display, answer the following:
\begin{itemize}
\item How much memory is free in the system?
\item Which process is taking more CPU?
\item Which process has got maximum memory share?
\end{itemize}
\item Write a CPU bound C program and a I/O bound C program (e.g. using more printf statements withing while(1) loop), compile and execute both of them.\\ Observe the effect of their CPU share using the \emph{top} display and comment.
\end{itemize}
\item Write a program in C that uses the \emph{fork} system call. You can use the program described in the lecture class on \textbf{Process}. Compile the program and execute it.
\item For the above C program, change the program such that the associated child process will change the core image.
\item In a C program, print the address of the variable and enter into a long loop (say using while(1)).
\begin{itemize}
\item Start three to four processes of the same program and observe the printed address values.
\item Try the experiment of different OS and comment wheteher the addresses remain same on both OS or not?
\end{itemize}
\item Use \emph{strace} command to find out system call traces of an executing process. You can use any process that has been crteated earlier.
\begin{itemize}
\item Find out a command on the shell such that the command does not make a system call. Use \emph{strace} to locate such a command.
\item \emph{strace} \textbf{bash} to observe how bash uses system calls to read commands from the console and echo it back to screen.
\end{itemize}
\item Write a C program to create threads. You can use the program demonstrated in class which has been provided as additional resource in the course website.
\end{enumerate}
% 5. Using lseek system call, find out if you can read from and write to any position in a file opened for reading and writing with O_APPEND. Write a program that when you launch N times in the background, writes the ID of the current process in a file. Neither of the programs can continue their execution until all the processes haven’t written their ID in the file. In the end all processes should print out the ID of the following process. Consider N as a known value.
% 8.
%
% 9.
%
% 10. Write a C program that finds a file in a file-tree starting from a given directory. The name of the file for which we are searching for, as well as the name of the starting directory should be read from the command line. Optionally, the name of the file can be specified as a pattern using the ‘*’ character.
%
% 11. Write a C program similar to the previous one, but this time try to find a string in the files.
%
% 12.
%
% 13. Write a program that would allow traversing a file-tree printing out the type, size and access rights for of the found files. The name of the starting directory should be read from the command line. Observation: be attentive to the symbolic links.
%
% 14. A binary file fil.bin contains integers. Calculate the arithmetic mean of each group of numbers that are situated between two 0s in the file. Write these obtained values on distinct lines in the file means.txt. The beginning and the end of the file plays the role of a 0, except the case when the first and last element of the file is 0.
%
% 15. A binary file fil.bin contains numbers and characters in the following way: 2 integers followed by a character from the set {+,-,*,/}. Write a C program that reads a group of numbers and the attached character and performs the operation on the two integers and then writes the result in a file res.txt in the form:
%
% nr1 operator nr2 = result
%
% The result line should be appended to the end of the file. The number of groups in the binary file should be specified in the command line as an input parameter.
\end{document}