David Chiu

Professor of Computer Science
University of Puget Sound
dchiu@pugetsound.edu


home | teaching | research | people | service | faq for students

CS 475 - Operating Systems

Hwk 1: Remote C Environment

In this tutorial, we will set you up to develop on a remote server. Here’s why we have to do this, instead of developing on your own machines. C is a very finicky language, and is highly dependent on the environment on which it compiles and executes. This is everybody’s worst nightmare: turning in an assignment you’ve spent hours on, only to have it not compile or execute on your professor’s machine. Indeed, having a common compiling and runtime environment was what made Java (and the Java Virtual Machine JVM) so successful when it was introduced in the mid-90s. Today, most languages have a common runtime environment, and C has certainly made significant efforts to being more portable across systems, but alas I find that it’s still very system dependent.

It’s therefore important that we all code in a common environment, so I’ve prepared a remote server for everyone to log into, including myself. This means we’re all coding and running on the same machine, which leads to more predictable and repeatable results!

Student Outcomes

Installing C Development Tools

Connecting to the Remote Server

Using the VS Code Editor

Using the Shell (within the VS Code Integrated Terminal)

Setting up Git and Github

To download and submit your homework assignments for this class, you’ll need to get connected to github and configure it all to work with this server. Follow these steps.

  1. Open your browser, and go to github.com. If you don’t already have an account, create one now.

  2. Navigate to https://github.com/settings/tokens to create a new “personal access token.” You can also get there via Settings > Developer Settings.

  3. Click to generate new a (classic) token. On the next screen, give your new token a good note, like “For OS assignments” or “My OS class” so you know what it is later. Assign it an expiration period that will take you to the end of the course (or indefinitely).

  4. Below that, select the boxes: repo, admin:org, and admin:public_key.

  5. Click the Generate token button on the bottom of the page, and take note (save) the token in a secure place. Don’t share it. Treat this like your password. STORE IT SOMEWHERE SAFE BECAUSE YOU’LL BE REPEATEDLY ASKED FOR IT.

  6. Go back into your VS Code’s terminal window. Type:
    1
    
     $ gh auth login
    
  7. Follow the prompts in this program. Use your up/down keys to choose the following selections to their questions:

    1
    2
    3
    4
    5
    6
    7
    8
    
     ? What account do you want to log into? 
     > GitHub.com
    
     ? What is your preferred protocol for Git operations?
     > HTTPS
    
     ? How would you like to authenticate GitHub CLI?
     > Paste an authentication token
    

    Finally, get your github access token ready for pasting:

    1
    
     ? Paste your authentication token: ****************************************
    
  8. Now run this to complete the setup.
    1
    
     $ gh auth setup-git
    
  9. We should be set up for git! Occasionally, a push/pull will require you to enter the authentication token again, so don’t lose it!

Our First C Program

  1. From your browser, find my code repository here: https://github.com/davidtchiu/os-first.

    • Click on the green Use this template button and select the Create new repository option. In the next page, give your repository a good name (the “suggestion” they give is fine). My only request is that you don’t name it to be the same as mine. This is hide your homework solution from Google searches.

    • Leave your repository with public visibility.

    • Copy the URL of your new from the browser window.

  2. Now from VS Code, open a terminal, and *clone* your new Github repository down to your local working directory using:

    1
    
     $ git clone <your-github-repo-url>
    
  3. You will be prompted in the terminal for your github username and password. Enter those now – however, you will use the “access token” we previously generated as your password. Do not attempt to use your regular github login password here. If successful, it will download a directory called os-first.

  4. Navigate into the new directory you just cloned. Inside, create a new directory create a new file called hwk1.c:

    1
    2
    3
    
     $ cd ~
     $ cd os-first
     $ code hwk1.c
    
    • The first command cd ~ changes your current-working-directory to your home directory. You should remember that ~ is a shortcut to your home directory!

    • The second command cd os-first changes your current-working-directory to the os-first directory that git just cloned in the previous steps.

    • Finally, code hwk1.c opens a new file called hwk1.c inside your VS code editor.

  5. With the blank hwk1.c opened in your editor, write a main function to fill in the code to print “hello world” ten times.

  6. When you’re ready to compile and test, go back down to the terminal window to compile and run it:

    1
    
     $ gcc -Wall -g hwk1.c
    

    gcc invokes the GNU C Compiler (gcc) to run. The -Wall flag instructs it to display all compiler warnings (even if the code ultimately compiles.) The -g flag generates debugging information for debuggers that we’ll use later on.

  7. If all goes well the runnable executable (binary) file that is produced is called a.out. Type ls on the terminal to make sure it’s there. If you don’t see a.out, that means the compilation failed and there was a syntax error that need to fix. To run it, use the command ./<executable-file>

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
     $ ./a.out
     Hello world 1 of 10!
     Hello world 2 of 10!
     Hello world 3 of 10!
     Hello world 4 of 10!
     Hello world 5 of 10!
     Hello world 6 of 10!
     Hello world 7 of 10!
     Hello world 8 of 10!
     Hello world 9 of 10!
     Hello world 10 of 10!
    
  8. It seems a bit odd that your executable file would be named a.out by default. To instruct the compiler to output the executable under a different name, you can run gcc with the -o <executable-name> flag:

    1
    
     $ gcc -Wall -g -o helloworld hwk1.c
    

    This would output the binary as helloworld, and you can run it using ./helloworld on the terminal.

  9. After you’re done, commit and push the hwk1.c file to github for grading. From the terminal,

    1
    2
    3
    
     $ git add hwk1.c
     $ git commit -m "<write-a-commit-msg>"
     $ git push origin main
    
  10. It may ask you for your github credentials again. Enter it now – remember once again to use your “access token” for the password. (You should only have to do this once for the initial push, and all subsequent github actions should bypass this step.)

  11. Navigate to your github repository from your browser to make sure that hwk1.c exists. If so, you have successfully committed your code and pushed to github! This is how you will submit all assignments in this course.

VS Code Editor Tips

By now, you may have noticed how helpful (or irritating) the AI suggested-fixes can be. I don’t think it’s a good way of learning C if they are turned on, because it tries to complete (incorrectly frequently) too much code. I would strongly recommend turning this feature off:

I also found it useful to suppress AI suggestions in your terminal:

Submission

To prove that you have logged in successfully:

  1. Change your login password on the server.

  2. Commited and pushed your git repository. Make sure your github repo is public so I can access it for grading.

  3. On canvas, simply submit the URL to your github repo. No other form of submission is accepted.

Credits

Written by David Chiu. 2022. Updated 2026.