mkdir cs44 cd cs44 pwd mkdir weelylabs cd weeklylabs pwd cp -R ~newhall/public/cs44/week01 . cd week01 ls
Try looking at the man page for fork to see how it is telling you information about the fork function: how to call it; what header file(s) to be included to call it; and what the function does and what its return value(s) are.
% man fork # or, I could specify the man section...I don't need to for fork: % man 2 fork # the man page for the system call fork in section 2 of the manual
If you have not used git, or if it has been awhile, here is some information
about how to use it:
using git
Here is a directory of files you can copy over that can be used to test out some gdb features:
cd ~/cs44/weeklylabs cp -r ~newhall/public/gdb_examples . cd gdb_examplesFirst, run make to build the executables (note they are all compiled with -g).
Let's look through a couple of the example programs in gdb, following along in my GDB Guide.
We are going to look at badprog and segfaulter in gdb. These are listed in the "Sample gdb sessions" part of my gdb guide under run 1: debugging badprog and run 2: debugging segfaulter.
Let's also try setting a break point in the C++ example code you copied over. Make use of gdb's tab completion to list the names of class methods.
Up the page on this guide are lists of common gdb commands and some examples
of how to use them.
Valgrind is a tool for finding heap memory access errors and memory leaks in C and C++ programs. Memory access errors are often very difficult bugs to find, and valgrind helps you easily find errors like reads or writes beyond the bounds of a malloc'ed array, accessing free'ed memory, reading uninitialized memory, and memory leaks (not freeing malloc'ed space before all variables referring to it go out of scope).
Here are some files you can copy over that can be used to test out valgrind:
cd ~/cs44/weeklylabs cp -r ~newhall/public/valgrind_examples . cd valgrind_examplesTo use valgrind, just compile with -g, and run valgrind on your program (the Makefile has this already):
make valgrind ./badprogThe output at first seems a bit cryptic, but once you see the basics of how to interpret it, it is extremely helpful for finding and fixing memory access errors. Let's look at my Valgrind Guide to see how to interpret some of this valgrind output. This guide contains links to other valgrind resources, and the README file in the code you copied over lists some command line options for running valgrind.
Some more information on debugging tools for C++:
C++ programming tools: gdb and valgrind
Here are some C and C++ programming resources:
I also really hate wrapped lines. Don't do it. See my guide for some techniques for avoiding it.