Starting from:

$30

HW 08 Solution

On November 18, 1307 William Tell reputedly shoots an apple off his

son's head. Something Steve Jobs never forgave him for.




Program 0

---------

Program 0 (parent) will create a semaphore (system V type - see http://undcemcs01.und.edu/~ronald.marsh/CLASS/CS451/os-syscalls.pdf),

create two pipes, spawn 3 children (named program1, program2, and

program3), and pass the semaphore ID and pipe IDs to the children

(as required) via command line arguments.




Program 1 and program 2 must be forked at the same time and the

semaphore MUST be used to synchronize reading/writing to one of the

pipes. Program3 can be forked after 1 and 2 terminate.




Program 1

---------

Program 1 will read a text file called "input.data" and extract the

words. Note that words will be separated only by spaces, commas, or

periods. Commas and periods will be considered part of a word. As

each word is extracted, program 1 will write the words (1 word per

line) into the pipe.

 

Program 2

---------

Program 2 will read from the pipe and convert each word into Pig Latin

(rules shown below) and write the converted word to another pipe.

Program 2 will also keep track of how many words of each form (2 types

possible) were converted and write those values to 2 other files

(shared1.dat and shared2.dat).




Pig Latin rules:

1) Type 1: For all words beginning with a vowel add the text "ray" to the

end of the word. For example: "and" becomes "andray," "end" becomes "endray",

etc. Note that any punctuation marks must remain at the end of the newly

formed word (and. becomes andray.).




2) Type 2: For all words beginning with consonants move the first letter to

the end of the word and add "ay". For example "number" becomes "umbernay,"

"letter" becomes "etterlay," etc. Note that any punctuation marks must

remain at the end of the newly formed word.




Program 3

---------

Program 3 will open shared1.dat and shared2.dat files and display the values

contained on the screen using the format:




Type 1: word_count

Type 2: word_count




Program 3 will also open the second pipe and reconstruct the original document

(multiple words per line) and write it out to temp3.data. For example:




temp3.data:

Itray isray hetay uccaZay igantopithecusGay, orray reatGay umpkinPay,

harlieCay rownBay.




REQUIREMENTS:

-------------

1. Your program must run on Linux Mint (Leonard 110/112).




2. Your full name must appear as a comment at the beginning of your

program.




3. Your programs MUST be named program0, program1, program2, and program3.

My script will assume those filenames. If your programs do not work because

you used different filename, you will get 0 points.




4. Your tarball must be named hw8-yourname.tar




5. Your program must use system V semaphores (semget, semop, and semctl).




6. The programs MUST compile with g++. fpermissive flag is NOT allowed.




7. Your code must adhere to coding style 1TBS (https://en.wikipedia.org/wiki/Indentation_style)

More products