Remarks

Exercise 1 - My Cat

  • Use the system call open() to open a file that is specified on the command line. Read the first 10 bytes of the file with the system call read() and then display them on standard output using write(). Use a static buffer.
  • Still using a static buffer, write a program that functions as cat ie, by opening one by one files specified on the command line, reading them and writing them to standard output.

Exercise 2 - My CP

Rewrite a simple program cp (copy a file to another). To create the "target", be sure to use the flags O_CREAT, O_TRUNC, and the third parameter of open() to properly position the rights of the newly created file (look what happens if you do not).

Exercise 3 - Highlander

Write a program that "resists" to signal SIGINT (reminder: this signal is sent when you type Control-C in the terminal). To do so, use system call signal().

Exercise 4 - Highlander II

Rewrite the previous program with the system call sigaction(). To manipulate sigset_t, see the manpage sigsetops (you should at least use sigemptyset()).

Exercise 5 - Speed-O-Meter

Write a speed-o-meter, a program that measures the speed at which one send him data (standard input), in bytes per second.

Exercise 6 - Shaper

Write a shaper, a program that reads from standard input and writes to standard output, but does not write faster than a certain speed specified in bytes per second.