- (5 points) Do problem 5.5 on page 111. Your program must demonstrate your claim and you must document how your program demonstrates this claim. Please call your program dupWorks
- (5 points) Write a simple version of od. Your program should read the contents of a file and print the contents in hex or ascii based on the commend line arguments. Please call this program xd.
By default your program should read from standard input and write to standard output. If a single command line argument does not match, this should be assumed to be the name of the input file.
Your program should print an address as a 8 bit hex digit and the data at that address as a hex digit.
You should support the following command line arguments.
- -c: if the byte is an ascii printable character, print the character, otherwise print the hex representation. (isprint might be helpful here)
- --begin offset: begin dumping the file at the specified offset rather than 0
- --end offset: stop dumping the file at the specified offset rather than the end of the file.
You may not use iostreams (C++) or stdio (c) to accomplish this task. It must be done with open, read, write, close and lseek. You may use iostreams or stdio for debugging, for error messages and for help functions. By
- (2.5 points) Write a program makeArray which generates 100 random integers in the range 0 - 10000 and writes them to a file in binary format. If a name is given as the first command line argument, the program should write to that file, otherwise the output should be to standard out. All output must be via write.
- (2.5 points) Write a program dumpArray which reads the data in a file as an array of integers and prints this data out to the standard output as ascii formatted integers (ie numbers you can read). The program should read from the standard input unless a command line argument is present. Any command line argument will be the name of the file. All input must be done via read.
Note, you should be able to use dumpArray to see the data makeArray printed to the file.
- (10 points) Write a program sorter which given a file containing 100 integers in binary format, will mergesort those numbers in parallel. Your program should work as follows
- Call the first process processA.
- processA should fork a second process, processB.
- Both processA and processB should fork a new process (processA1 and ProcessB1)
- Process A should read in numbers 0-24 and sort these, writing the results back to the file in positions 0-24.
- Process A1 should read in numbers 25-49 and sort these, writing the results back to the file in positions 25-49.
- Process B should read in numbers 50-74 and sort these, writing the results back to the file in positions 50-74.
- Process B1 should read in numbers 74-99 and sort these, writing the results back to the file in positions 75-99.
- On the exit of process A1 and B1
- Process A should read the numbers 0-49 into two arrays and write a merged list back to the file in positions 0-49
- Process B should read the numbers 50-99 into two arrays and write a merged list back to the file in positions 50-99
- On exit of process B, process A should merge the numbers in the two lists and write the results back to the file.
All file I/O should be via read and write.
The result of running the program should be a file containing an ordered list of 100 integers.
You may use vectors, arrays, and the sort function from the algorithm library if you wish to accomplish the low level sorting. You MUST however, use the above algorithm for the high level sort.
When you are finished email a compressed tar file containing your code, a Makefile and a README file to your instructor. Please do not include executable or object files in your submission.