CMPS-3600 - Operating Systems - Lab-1

Elements of this lab...
  • Setup your Odin account
  • Work with the C programming language
  • Refactor a C++ program to ANSI C
  • Modify your C program
  • Build and run an X11 windowed C program

Lab instructions

Step-1 Setup your work folder on the Odin server... 1. Log in to Odin $ ssh username@odin.cs.csub.edu Skip this part if your 3600 folder is already setup using the script. 2. Change to your home directory $ cd 3. Run a bash script $ /home/fac/gordon/p/3600/build_dirs.sh
Step-2 Do this work in your Odin 3600/1/ folder run this script: $ /home/fac/gordon/p/3600/lab-start.sh Follow along... We will write a C++ program together. 1. name your program lab1.cpp 2. get the user's name 3. get a number from the user 4. open a file named "log" 5. write the user's name to the file 6. calculate the summation from 1 to user's number, using a for-loop 7. write the summation total to the file 8. close the file 9. end the program Build and run the program like this: $ g++ lab1.cpp -Wall $ ./a.out Now we will refactor the program to the C language. $ cp lab1.cpp lab1.c Follow along...
Step-3 Log out and back in to Odin...
$ ^D # CTRL-D to disconnect from Odin $ ssh -YC username@odin # log back in using -YC options
The YC options Y says transfer to me the X11 window graphics C says try to compress the transmission for efficiency Copy a few more files in now.
$ cd 3600/1 $ cp ~gordon/public_html/3600/examples/1/xwin89.c . $ gcc xwin89.c -Wall -lX11 $ ./a.out
You should see a small window pop up on your screen. Here are some modifications to make in the program... 1. Change the background to a beautiful CSUB gold color. -------------------------------------------------------- Use XSetForeground and XFillRectangle. Look up these X functions on google. Show where you found the information in a C-style comment. CSUB color codes 2. When the mouse moves within the window, print an 'm' to terminal. -------------------------------------------------------------------- Call the write(2) function. Flush the output buffer with each call of write(2). Do not print a newline character! 3. Optional: Display some text in the window. --------------------------------------------- $ man XDrawString The text you print might be your name. It might be some instructions such as: Press 'A' key to see our school colors. Then, each press of 'A' will change the window background color to blue, gold, blue, gold, etc.
Step-4 Add the lab1.c program to your Makefile. Running make will now build both programs. Try this: make clean make make The first call to make will build your program. The second call to make will say "Nothing to do" because your program is built. Files to be collected at 9:50am ------------------------------- 3600/1/lab1.cpp 3600/1/lab1.c 3600/1/xwin89.c 3600/1/log 3600/1/Makefile