0% found this document useful (0 votes)
129 views

Lab 2: System Calls: August 6, 2018

This document provides an overview of Lab 2, which teaches how to use common Linux system calls for input/output operations on files and directories. It describes 3 tutorials that demonstrate how to open, read, write, and seek within files using system calls. It also assigns 4 programming tasks: 1) implement the cat and mv commands, 2) determine a file size and blocks using lseek and stat, 3) delete a directory and subfolders, and 4) delete every 5th byte from a file without a temp file or buffer.

Uploaded by

david sea
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
129 views

Lab 2: System Calls: August 6, 2018

This document provides an overview of Lab 2, which teaches how to use common Linux system calls for input/output operations on files and directories. It describes 3 tutorials that demonstrate how to open, read, write, and seek within files using system calls. It also assigns 4 programming tasks: 1) implement the cat and mv commands, 2) determine a file size and blocks using lseek and stat, 3) delete a directory and subfolders, and 4) delete every 5th byte from a file without a temp file or buffer.

Uploaded by

david sea
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Lab 2 : System Calls

August 6, 2018

Objective :
• Lab 2 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
Recommended Systems/Software Requirements:

• Any flavour of Linux


References:
1. Unix concepts and applications, Fourth Edition, Sumitabha Das, TMH.
Tutorial:

• Tut 1 : Learning how to use the system calls for opening, reading and
writing to files - open, read, write and lseek system calls
1. Login to the system, open the Terminal and use the man command
to read the manual pages of open, read, write and lseek system calls:
2. Download the file open read write with linux sys calls provided
in the helpful resources section of Lab2 and compile using gcc.
This C program intends to read 100 characters from a file and to
print these 100 characters on the terminal. It uses open system call
to open a file. The open call returns a file descriptor fd which is then
used in the successive read and write system calls to access the file.
• Tut 2: Writing lines of text using system calls
1. Download the file write lines of text sys call provided in the help-
ful resources section of Lab2 and compile using gcc.

• Tut 3: Simulating the ls command


1. Download the file simulating ”ls” command provided in the help-
ful resources section of Lab2 and compile using gcc.
This C program performs the simulation of the ls command in Linux
which lists all the folders and sub-folders of its present working di-
rectory.

1
Assignemnts:

1. Using a similar approach as covered in Tut 3 , implement in C the


following UNIX commands using System calls : cat and mv
2. Determine the size of a file using the 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 stat.
3. Write a C program that deletes a directory with all its subfolders.
The name of the directory should be read from the command line.
4. 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 truncate function.

You might also like