Return to Operationg Systems home
Implement the solution of exercise 04 of laboratory 05 (Lab05) 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.
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
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.
Execute the following operation with the
/that have extension “.exe”, dimension greater than 1024 bytes, and that they are executable.
aand at least one
Ain an undefined order (i.e.,
A…a). Of these files print the last 3 lines.
Aand with 3 consecutive
z. Of these files create a compressed version (see the manual,
man, of the command
.cof the other users (excluding your user!), and belonging to your group.
Giving a file of name lab06e04in.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
grep, etc.) and pipes print in the screen:
Aletters separated by any two characters.
Aletters separated by any two characters, but with the “A” characters that do not start or end the name itself.