SYSC 4001B: Operating Systems Programming Assignment 1: Counting Words
Due: January 29, noon
The programming assignments in the course are based on Linux as the Operating System and C as the programming language. If you need a reference to help with either, this one may come in handy: Neil Matthew; Richard Stones, Beginning Linux Programming, 4th Edition, Wrox 2007, Print ISBN-13: 978-0-470-14762-7, Web ISBN-10: 0-470-14762-8. You can
access a free online version of this book through the Carleton University Library or download the PDF version from the cuLearn page for the lab.
To work in the lab, you need to boot up the PC to run Linux, not Windows. Any of the Fedora versions we have on these PCs should be fine. The code you will be given assumes that you work with a terminal/command line, using compilers such as gcc/g++. If you want to set up your assignments/projects in Eclipse or some other IDE, that is okay with me. But at the end of the day, the code has to compile and link using the basic Makefile capabilities that the starting code assumes. If you are unfamiliar with Makefiles, the first lab will also practice this.
The purpose of this assignment is to help you create, debug and extend C programs that run within a shell environment and utilize basic I/O and string manipulation functions.
The scenario: your well-intentioned-but-inexperienced pair-programming buddy has just written some code for the first assignment. Unfortunately, they dropped the course/were abducted by aliens, and it is now up to you to pick up where they left off.
The accompanying program files in the ZIP folder in cuLearn (Makefile and main.c) contain examples of good and bad programming practices and includes deliberate errors. Your job is to find and fix the errors, implement missing features, and learn some tricks of the trade in the process.
Luckily, a test program is included to help you along. You can (and should) use it to check your work. See the Self-Evaluation section for details.
There are three parts to this assignment.
Part One: Crash Course in C
Read the file review.txt. The list of topics it contains is useful for self-assessment and as a study guide. Answer the questions in 1-Pointers.txt. Try to identify the key to each problem and keep your answers concise and to the point; 2-3 sentences should suffice. These questions bring up important points about pointer usage in C. Keep these in mind when working on the remainder of the assignment.
Part Two: Fixing the Bugs
The purpose of the provided program is to count words specified as command-line arguments. Read the description of the program and its functionality in the comment at the top of main.c. Now read through the rest of main.c and the Makefile and understand what each part does.
Finally, compile and run the program from the shell:
(ignore the compiler warning for now)
The program compiles and links… so it must work! But is it really doing what it is supposed to do? Answer the questions in 2-Debugging.txt and fix the corresponding bugs in main.c. Again, try to keep your answers brief and focused.
Part Three: Enhancements
Now that the bugs have been ironed out, it’s time to add some functionality to our word counting program. Follow the instructions in 3-Enhancements.txt to complete the word counter.
The testrunner program is included so that you can check your progress as you implement different parts of the assignment.
To run all tests:
> make test
To run a specific test, e.g., stderr_output:
> ./main -test stderr_output
As you can see, testrunner is implemented entirely in C. If you found this assignment too easy, or are just plain curious, feel free to look at the implementation and see if you can figure out how everything works. The relevant files are: assignment1_test.* and testrunner.*.
Note: You should remove or disable any additional debugging output you may have created before running the tests. One way to do this easily is through the use of the preprocessor directive #ifdef:
fprintf(stderr, “My string %s %d\n”, var1, var2); #endif
Then add -DDEBUG to the CCOPTS line in the Makefile during development, and remove it before testing. Make sure that your code still compiles and runs without the debug output!
Also please note that the test we provide are for your convenience only. The TA may use those or other test cases when marking your submission, so make sure your code works not only for the few test cases but is correct in general.
Submit your assignment using cuLearn, under Assignment 1 Submission for the course. You should submit the following two files (and these two files only): one text document called RESPONSES.txt with answers to all questions in the three documents 1-Pointers.txt, 2- Debugging.txt, and 3-Enhancements.txt. And a modified implementation of main.c that implements all required bug fixes and changes. Do NOT make modifications to any of the remaining files. The TA(s) will compile your main.c with the remaining code and invoke the tests, so changes in other files will cause compilation (or execution) to fail.
Marks will be based on:
• Completeness of your submission
• Good answers to the questions
• Correct solution to the problem
• Adhering to the submission requirements
• Following good coding style
• Sufficient and high-quality in-line comments
The due date is based on the time of the cuLearn server and will be strictly enforced. If you are concerned about missing the deadline, here is a tip: multiple submissions are allowed. So you can always submit a (partial) solution early, and resubmit an improved solution later. This way, you will reduce the risk of running late, for whatever reason (slow computers/networks, unsynchronized clocks, failure of the Internet connection at home, etc.).
In cuLearn, you can manage the submission until the deadline, taking it back, deleting/adding files, etc, and resubmitting it. The system also provides online feedback whether you submitted something for an assignment. It may take a while to learn the submission process, so I would encourage you to experiment with it early and contact a TA in case you have problems, as only assignments properly and timely submitted using WebCT will be marked.