Lab 1

Here is your Lab 1.

Lab 1 is ungraded and you need not submit you lab sheet. It aims to familiarize with basic UNIX commands, the C programming language (particular, pointers), and C programming tools on UNIX (compiler and debugger).

12 thoughts on “Lab 1

  1. Hi Prof Ooi, just to clarify on page 9 of the lab assignment. The part which you say to “tell the debugger to break at line number 5 (the closing } of function main()}…”.. Do you mean that the debugger should break at the line where “}” is found? Because according to the code given, at line 5, it is x = 0; Which is the right interpretation?

  2. I think the number 5 varies according to your code. If you have extra blank lines or use addition line for the {}, it will not be 5 anymore but 6,7,8, etc.

  3. I realize that many people haven’t had any experience with UNIX environment. So here are some basic tips as the standing ground for further learning:

    This command is mentioned in the lab sheet. Use this extensively in the lab to find out what a command does and the options of the command. Depending on what UNIX-like OS you are using, it usually calls ‘less’ command to display the man pages.

    Type ‘/’ + keyword to find the keyword in the man page
    Type ‘n’ to go to the next keyword.
    For more, look at the man page of ‘less’.

    In case you cannot scroll up the man page, try piping the man page to ‘less’.

    This is usually “scroll down only” text displaying program, which also leaves the text you are reading on the screen when you quit.

    This is a better text displaying service, with more functionality. It will not leave any text on the screen when you quit.

    In this lab, you will need to create a text file. You will need some text editor to do that. There are quite a number of text editor you can choose from: vim, vi, nano, etc. I’ll give a few commands for vim/vi.

    To type, type ‘i’ to enter “Insert” mode. Then type as normal.
    If you are stuck in some strange mode, tap Esc, or press ‘q’ once to see if you are out.
    ZZ Save and quit
    ZQ Discard change and quit
    :w Write to file
    :q Quit
    :wq Write to file then quit

    For more commands, please find out yourself from the guides on the Internet and man page.

    In gdb, you can type ‘help’ for more commands. Try to explore around with it.

    • About the man pages, I add the following line to my .bash_profile:
      export PAGER=”less -s”

      That gives me nicely scrollable man pages.

  4. Heres my command, not sure if its 100% right :/

    Step 1: “ps -el”
    Lists every process running, in long format.

    Step 1+2: “ps -el | cut -c 7-11,78-82”
    Then cut columns 7-11 (UID), 78-82(CMD) from the output of step 1.

    Step 1+2+3: “ps -el | cut -c 7-11,78-82 | grep sshd”
    Filter out only sshd. But 1 user can have multiple sshd process.

    Step 1+2+3+4: “ps -el | cut -c 7-11,78-82 | grep sshd | sort”
    Sort them, so that unique will work properly.

    Step 1+2+3+4+5: “ps -el | cut -c 7-11,78-82 | grep sshd | sort | uniq”
    Removes any consecutive lines that are the same.

    Step 1+2+3+4+5+6: “ps -el | cut -c 7-11,78-82 | grep sshd | sort | uniq | wc -l”
    word count showing number of lines.

  5. personally i find the lab confusing… would there be answers published? since it is ungraded I think some real standard answer might help because I don’t even know what I did is correct or wrong..

    • I agree, it would be nice to know the answers. Considering we’ll need to get the basics down properly.

      • As a policy, we do not publish answers — however, I would be very happy to take a look at your answers and discuss them with you.

        Publishing answers is the easy way out (both for me and for students) but it is not the best way to learn IMHO.

    • We will discuss the answer to the previous lab in the next lab session. Do not worry.

      If you have more questions, you may email any of us.

  6. Here is the set of slides that explain key points in lab 1 and list out a few pointers for those who wants to find out more:
    I understand that lab 1 might be quite heavy for those who haven’t had any experience with UNIX-like system before (I was in the same situation last year). If you have any question, you can email me or any of the TAs.

Comments are closed.