Noted session - 22/04/2024

Exercise 0: File manipulation using system calls

For the purposes of this exercise, restrict yourselves to the use of I/O system calls like open(), close(), creat(), read(), write(), lseek(). The use of the stdio library will be penalised.

  • Problem 0: Write a C program that takes as argument a filename f (corresponding to a file that is assumed to exist in the current working directory) and creates a new file, whose name is f prefixed by copy_of_. The new file must contain the entirety of the contents of f.

  • Problem 1: Modify the above program so that the contents of the new file prefixed by copy_of_ are those of f but in the reverse of their original order.

Exercise 1: Fork and thread

  • Problem 0: Write a C program that creates two child processes such that:

    1. The first child launches cat on a file of your choice.
    2. The second one recovers the results (via a pipe, for example) of the first one and executes wc -l on them, with the results being printed in the standard output.
    3. The parent finally prints the process IDs of the two children and then exits.
  • Problem 1: Write a C program that creates an integer array of size ARRAY_SIZE (a constant that you must define). It then launches two threads each of which calculates the sum for the first and second halves of said array, respectively. The program then prints the total sum and exits.

Exercise 2: Client-server application

  • Problem 0: Create a server-client program in C, using network sockets (IPv4 or IPv6, datagram or stream), such that:
    1. Clients communicate a filename to the server.
    2. The server checks if a file with the given filename exists in the current working directory and either responds to the client with the entirety of the file's contents, or with an appropriate error message.

Bonus points will be awarded if your server can handle multiple clients in parallel.


Site built with MkDocs and a slightly-modified version of Terminal for MkDocs.
Last update: September 2023