| Current Path : /var/www/html/bibhas.ghoshal/lab_files/ |
| Current File : /var/www/html/bibhas.ghoshal/lab_files/lab3.tex |
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{color}
%opening
\title{Lab 3 : System Programming I}
%\author{}
\begin{document}
\maketitle
\underline{\textbf{Objective : }}
\begin{itemize}
\item Lab 3 is intended to provide the way to use the most common system calls in order to make input-output operations on files, as well as operations to handle files and directories in Linux
\end{itemize}
\underline{\textbf{Recommended Systems/Software Requirements}}:\\
\begin{itemize}
\item Any flavour of Linux
\end{itemize}
\underline{\textbf{References:}}
\begin{enumerate}
\item \emph{Unix concepts and applications}, Fourth Edition, Sumitabha Das, TMH.
\end{enumerate}
\underline{\textbf{Theoretical Background:}}\\
You are expected to refer to the resource reading file available at the course website before starting the lab.\\
\underline{\textbf{Problems:}}
\begin{enumerate}
\item Implement in C the following UNIX commands using System calls : \emph{cat}, \emph{ls} and \emph{mv}
\item In lecture classes,we described a program that copies the contents of one file to a destination file. This program works by first prompting the user for the name of the source and destination files. Write this program using POSIX API. Be sure to include all necessary error checking, including ensuring that the source file exists. Once you have correctly designed and tested the program, if you used a system that supports it, run the program using a utility that traces system calls. Linux systems provide the \emph{ptrace} utility.
\item Determine the size of a file using the \emph{lseek} command. Once you found out the size, calculate the number of blocks assigned for the file. Compare these results with the similar results obtained when using the function \emph{stat}.
\item Write a C program that writes the lines of a file into another file, but in the reverse order. The names of the files should be read as input parameters.
\item Write a C program that deletes a directory with all its subfolders. The name of the directory should be read from the command line.
\item Write a program that deletes every 5th byte from a file, but without using a temporary file or allocating a buffer in the memory. For adjusting the size of the file you may use the \emph{truncate} function.
\item Write a program having the name move, similar with the Linux command mv. The user should be able to call the program in any of the following ways:
move numeFisOld numeFisNew\\
move numeFis numeDir\\
move numeDirOld numeDirNew\\
\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}