Assignment
5
(Marks 10)
- Date of assignment out: 07.09.2006
- Last date of report: 12.10.2006
- You
have to create a static library
that supports calls similar to creation
of unnamed pipes,
read from the pipe and write to the pipe (on SUN SPARC). The functions
to implement are int mypipe(int
fd[]), int readpipe(int
fd, char *buff,
int noc), int writepipe(int fd, char *buff, int
noc), int rmpipe(int
fd[]).
- The
parent process will be compiled with the library. It will open the
required
number of 'pipes' and then it creates child processes where the library
will be copied to the child processes. Child can use the
opened 'pipes' for communication. A child can also create new 'pipes'
which
can be used by itself and its children. Naturally it cannot work with exec() call.
- int
mypipe(int fd[]): called from the parent process acquires a shared memory and a set of semaphores. Stores the
identifiers of the shared memory and the semaphore set in a global data structure of the library.
The shared memory is used as the
buffer. The semaphores are used to ensure exclusive access to the
shared buffer and also to check buffer-full
and buffer-empty conditions. The
function puts two identifiers in fd[0]
(read) and fd[1] (write)
to be used by other functions. It returns zero (0) on success and -1 on any error.>
- int
writepipe(int fd, char *buff, int noc): when called from the parent or any of its child (no exec) process,
attatches the shared memory corresponding to the write identifier fd and writes noc bytes from the local buffer
pointed by buff in the
'pipe', the shared memory. It should not write when the buffer is full
and should implement critical section for exclusive access to the
buffer. Both are to be achieved by the set of semaphores associated
with the 'pipe'. After the writing, the shared memory is detached. Return values are
similar to mypipe().
- int
readpipe(int fd, char *buff, int noc): reads noc bytes from the 'pipe'
(shared memory), identified by the read
identifier fd, in the
local buffer pointed by buff.
It should not read from the empty buffer and should implement critical
section for exclusive access to the buffer using the set of semaphores.
After the reading is complete, the shared memory is detached. Return values are
similar to mypipe().
- int
rmpipe(int fd[]):
removes the shared memory and the set of semaphores identified by the
pair of read-write
identifiers fd[0] and fd[1]. Return values are
similar.
- The essential files are mypipe.h, mypipe.c The following
commands show how to create a static library and how to link it with a user
program.
$ gcc -Wall -c
mypipe.c
$ ar -qv libmypipe.a mypipe.o
$ gcc -Wall testMyPipe.c -L. -lmypipe
- Prepare a Makefile that will take the user
program testMyPipe.c as a parameter and will create the a.out file. Finally prepare the tar file <rollNo>_05.tar with mypipe.h, mypipe.c and the Makefile. Keep it in the proper
directory. Do not change names or types of any of the
function or files.