- Build Static and Shared Libraries using a Makefile
- Read "make and Makefile" session in Chaper 10 of BLP textbook
if you're using that text. Certainly refer to the online GNU documentation
for GNU make
.
- Write 3 very simple c source files: hello.c, here.c, bye.c, mylib.h
. In hello.c, a function should print out "Hello!"; in here.c
, another function should print out "I am here!"; and yet another function
should print out "Bye bye!" in bye.c. So, actually, in each code
file, there is only one C printf statement. mylib.h should include prototypes for the 3 functions you will be writing.
- Write a main.c to call above 3 functions so that the
result should display like following
"Hello!"
"I am here!"
"Bye bye!"
Please note there is no C printf statement in main.c;
- Read and understand this
makefile first and write your own Makefile called Makefile1
to compile them and build a static lib called mylib.a, comprised
of hello.c, here.c, and bye.c (but NOT main.c).
- Review "shared libraries naming structure" and "building a shared
library" in lecture 3.
- Read and understand this makefile first
and write your own makefile called Makefile2 to compile them and
build a shared lib with the soname of libmylib.so.5. Make the minor
version .1 and the release .10. This will mean your actual shared library
file will be named "libmylib.so.5.1.10" with .so links set accordingly.
- Note that the two makefiles actually build separate libraries based
on the same source code files, one static, the other shared.
DELIVERABLES:
see the submission faq
- Implement the stat command in C. Write a C program
called my_stat that implements the default behavior of the UNIX
stat command. Your output should exactly match the default
output of the stat command. For instance:
File: "/usr/bin/stat"
Size: 7212 Blocks: 16
IO Block: 4096 Regular File
Device: 303h/771d Inode: 311082
Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/
root) Gid: ( 0/ root)
Access: Wed Jul 10 23:00:30 2002
Modify: Wed Aug 8 10:49:41 2001
Change: Thu Apr 4 12:34:28 2002
Hint: "man stat" and "man 2 stat". Again, the output of your stat program with the option should
match the output of the original stat program. For those of you using
Molay's text, you will find his discussion on the stat call on pages 82ff
quite helpful in using the stat call and formatting the output correctly.
For extra credit (5 points): Implement handling of any one of the following two
flags:
-L (follow Links)
-c --format (implement a subset of 5 of the formatting options (your choice which 5))
DELIVERABLES: your source file(s) (e.g., my_stat.c), a makefile, and a README as described in the submission faq
- Implement a simplified version of the UNIX program "cp"
, which copies one file to another. Call the file filecopy.c. This
version copies only files, it does not permit the second argument to be a
directory. We also ignore all options in command "filecopy".
Please follow these steps:
- Read chapter 3 in the BLP textbook carefully, or chapter 2 of Molay
if you're using that text.
- Read and understand these examples:
read.c and
write.c; (man 2 read; man 2 write if necessary)
- Use Low-level File Access functions such as creat, open, read,
write, close, etc.) to implement this command
- You must handle the situation when the second argument is the same
as the first, i.e., you should not allow a file to be copied over itself.
Handle this situation intelligently.
- Acctually, you only need to integrate above examples and add only
serveral lines.
DELIVERABLES: your source file(s) (e.g., filecopy.c), a makefile, and a README as described in the submission faq
- Signal Handling
Write a signal handler that catches the CTRL-C (SIGINT signal 2) and SIGUSR1
(signal 10) signals. Your process should not by default exit on CTRL-C back to your shell. You may want to look on the BLP
example on signals, or Chapter 6 of Molay's text if you're using that.
The following requirements apply:
- You should accumultate the handling of CTRL-C in the handler. That
is to say, you should have a variable counter accumulate each time the handler
is called, and print out the current count in the handler. For instance,
if you've hit CTRL-C 6 times, your handler should print out something to
the effect of "You've pressed Ctrl-C 6 times. Aren't you getting the
message that I'm invulnerable?"
- Your program should accept a command line argument that specifies
the MAXSTOPS allowed, after which, Ctrl-C is handled in the default way (i.e.,
the program terminates). So if the user passes in '10' on the command
line, the program prints out it's message above the first 9 times, but the
10th time CTRL-C is pressed, the default action applies (program termination).
- You should print out a message that states that your program received
the SIGUSR1 signal when it is handled. You should be able to issue
a kill command to send your program the SIGUSR1 signal, and have that signal
handled properly (by printing out a receipt notification) and then continue
to function and handle subsequent CTRL-C and SIGUSR1 signals.
Please following these steps to finish this part smoothly:
- Read "signal" session in Chapter 10 of BLP textbook or in Chapter
6 of Molay's text.
- Read and understand the example code first.
- Understand that handling SIGUSR1 is one of the most primitive forms
of interprocess communication in Unix (i.e., you are communicating with another
process).
DELIVERABLES: your source file(s) (e.g., my_sig.c), a makefile, and a README as described in the submission faq
MARKS DISTRIBUTION
- Excercise 1:
- 10 points: implementation
- 3 points: correct results after running the implementation
- Excercise 2:
- 10 points: implementation
- 3 points: correct results after running the implementation
- Excercise 3:
- 10 points: implementation
- 3 points: correct results after running the implementation
- Excercise 4:
- 10 points: implementation
- 3 points: correct results after running the implementation
- Correct Submission:
Total Marks: 55
Ross Girshick