Review Unix Programming Tools and Basics of the C Language 


 

This is a simple and important project for you to review Unix and C programming. Please do the following reading in order:

  1. Read Chapter 4 and Sec 9.2 of  Running Linux  (Available as an Electronic Book through SFU Library). You may practice the commands on the Unix machine  csil-cpu6.csil.sfu.ca.  (Use port 24 when you SSH to it).
     
  2. Unix Programming Tools for information on how to use the gcc compiler, make tool, and gdb debugger. Make sure that you actually use gdb on some small C programs (Read this debugging tutorial).
     
  3. Essential C or any similar document/book. Pay careful attention to pointers and memory management in C.

     

1. Practice Unix [10 points]

Write a one-line description for each of the following commands:
 

1.      xemacs &

2.      cd                     

3.      cat ~/.bashrc > tmpfile.txt

4.      ln -s  tmpfile.txt  ~/tmp-alias

5.      ls -al 

6.      chmod a+rwx  tmpfile.txt

7.      grep  bash   /etc/passwd

8.      ps -ef  |  more 

9.      man 2 chown 

10.  gcc  test.c  2 > error-msg  

 


2. Implement a few String Manipulation Functions [40 points]

In this problem, you will develop a few string manipulation functions similar to the standard C string functions. You are not allowed to use any standard string functions (e.g., strcpy, strlen, etc)  in your code. Download the file  mystring.tar.gz  to your home directory on csil-cpu6.csil.sfu.ca (you may download the file to your  machine first, then transfer it to csil-cpu6.csil.sfu.ca using any FTP client).  After the download, issue  the command: 

        tar  xvfz  mystring.tar.gz

which creates the directory ~/mystring. In that directory, you will find the following files:

Start by issuing the command make to ensure that you got everything ready to start coding. The code should compile without a problem and you should find an executable file named test_mystring. Try it by issuing  the command ./test_mystring. Of course, the tests there will fail. Now, start coding the functions in mystring.c one at a time and modify test_mystring.c to add more tests.

 

Testing Your Code

To help you testing your code, we provide below some testing programs. Copy test_mystring.c to your mystring directory.  Compile your code again. Run the test file: ./test_mystring x, where x is the test number between 1 and 4.