User Tools

Site Tools

Return to Home page

Return to Operationg Systems home

Operating Systems Course: Lab05

Laboratory number 05

Exercise 01: Signals and pipe

Implement the solution of exercise 04 of laboratory 04 (Lab04) using pipe for the communication between the two processes.

That is, implement a C program that generates two children, a producer and a consumer. The producer child reads from the keyboard some strings, and it transfers them to the consumer. The consumer child converts the strings into uppercase characters, and it visualizes the strings in standard output. The transfer of the strings (and synchronization) has to take place through pipes.

Observation: The length of the strings transferred through the pipe is variable and not known a priori. It is therefore appropriate to use some communication mechanism/protocol. For instance, it is possible to transfer in the pipe the dimension of the string before the string itself, by using a constant number of characters to code this dimension.

Exercise 02: Pipe and synchronization

Since the read operation in a pipe is a “blocking” operation, pipes can be used to guarantee a “rigorous” synchronization between processes.

More in detail, using two pipes between two processes, the first process can wait for the second process by reading from the first pipe, and the second process can wait for the first process by reading from the second pipe.

By using this mechanism, implement the following procedure. The parent process generates a child process.

After the creation, both processes want to send messages on standard output (or on a file) synchronizing so that the messages are (strictly) alternated, for example:

I'm the father (PID=...)
I'm the child  (PID=...)
I'm the father (PID=...)
I'm the child  (PID=...)
I'm the father (PID=...)
I'm the child  (PID=...)

Note that you have not to use sleep or pause to synchronize processes, and that the derived code has not race conditions. The parent sends to the child a specific synchronization message to indicate that the execution needs to be terminated.

Exercise 03: Command find

Execute the following operation with the find command:

  1. Print the list of the files in the tree with root / that have extension “.exe”, dimension greater than 1024 bytes, and that they are executable.
  2. Print the path of all the files with extension “.c”, and with a dimension of 100 bytes.
  3. Print all the files of your user, of regular type, that contain in the name at least one a and at least one A in an undefined order (i.e., a…A or A…a). Of these files print the last 3 lines.
  4. Print all the files of your user from the level of depth 3 to the level of depth 5, with a dimension of at least 250 bytes, and with the name of exactly 4 characters. Of these files count the number of characters. Repeat the same operation counting the number of rows.
  5. Print all the files in the system with an extension of 3 characters, with the name beginning with an A and with 3 consecutive z. Of these files create a compressed version (see the manual, man, of the command gzip).
  6. Print the content of all the directories, starting from the root of the file system, and with name bin.
  7. Find all the files with the extension .c of the other users (excluding your user!), and belonging to your group.
  8. Modify the permissions of all your files in the first level of the sub-tree of the root of the file system, so that all users other than the owner have no permission.

Exercise 04: Filters

Giving a file of name lab05e04in.txt containing the list of the students enrolled in the course “Algorithms and programming” of the academic year 2012-2013 (source: website of Politecnico di Torino, servizi per gli studenti, iscritti ai corsi, with some small modifications).

Using the known filters (commands sort, grep, etc.) and pipes print in the screen:

  1. The list of the same data ordered by reverse id number (attention to the position of the ids 89499 and 94799)
  2. The list of the same data ordered by surname
  3. The list of students who attended in 2011-2012.
  4. The list of students in computer science (INF1T3) ordered by id number.
  5. The list of students with an id that terminates with 2 or with 4, and ordered by surname.
  6. The list of TCL students (TLC1T3), that they still have to attend (i.e., row with string “Da frequentare”), sorted in descending order by id number.
  7. The list of students which name contains two A letters separated by any two characters.
  8. The list of students which name contains two A letters separated by any two characters, but with the “A” characters that do not start or end the name itself.
  9. Take only the id numbers from the file, eliminate all the digit equal to 0, substitute all the digit equal to 8 with 1, sort the resulting list and eliminate all the duplicates.
  10. Perform all the operation of the previous point (point 9), but print only duplicate lines, counting them.

If you found any error, or if you want to partecipate to the editing of this wiki, please contact: admin [at]

You can reuse, distribute or modify the content of this page, but you must cite in any document (or webpage) this url:
/web/htdocs/ · Last modified: 2024/04/08 22:35 by

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki
Privacy Policy