C Review Exercises and Linking / Unlinking
Background info:
Link command:
- link(from,to) // returns -1 for error
- unlink(file) // returns -1 for error
gdb Debug commands: http://condor.depaul.edu/glancast/373class/docs/gdb.html
Exercise #1: Exploring programming with links:
Write a program that creates a file, links it 2 other names, writes to the original file and unlinks the original file.
Create a file named link1.txt
- Use O_CREAT | O_WRONLY as access mode
- Use S_IRUSR | S_IWUSR as permission request
Link the file to link2.txt
Link the file to link3.txt
Write hello to the file link1.txt
Unlink link1.txt
Exercise #2: debugging directory read program.
wget http://home.adelphi.edu/~pe16132/csc271/note/scripts/fileio/gdbexercise/readdirectory.c
inside the directory you retrieved the program to, create a directory and put in 2 files and one directory
mkdir testdir
cp readdirectory.c testdir/x.c
cp readdirectory.c testdir/y.c
mkdir testdir/insidedirread the comments inside readdirectory.c and follow the instructions to debug to see the problem, then fix it.
You need to debug even if you can see the problem without debugging.
Exercise #3: debugging timestampwithseek program.
wget http://home.adelphi.edu/~pe16132/csc271/note/scripts/fileio/gdbexercise/timestampwithseek.c
wget http://home.adelphi.edu/~pe16132/csc271/note/scripts/fileio/gdbexercise/testtime.txt
read the comments inside timestampwithseek.c and follow the instructions to debug to see the problem, then fix it.
You need to debug even if you can see the problem without debugging.
Exercise #4: debugging alarm.c
wget http://home.adelphi.edu/~pe16132/csc271/note/scripts/fileio/gdbexercise/alarm.c
read the comments inside alarm.c and follow the instructions to debug to see the problem, then fix it.
You need to debug even if you can see the problem without debugging.