CISC3595: Get Started Lab

In this lab, we will focus on familiarizing ourselves with the programming environment that we will be using for this class. Please do not skip any steps, and take notes about what you have learnt.

1. Log on to storm.cis.fordham.edu server:

To use the lab machines (Unix), you log on as student user. Ask the instructor for the password.

On the desktop of the lab machines, there are usually shortcuts for some useful software.

Using ssh, open a terminal program, and type the following command in order to log on to storm.cis.fordham.edu:

ssh -l yourAccount storm.cis.fordham.edu
Note that the -l yourAccount is the dash followed by letter l, and then your storm account (which your advisor hand out to you). This is an option to the command ssh (a Unix command used to securely log in to a remote server. You will be prompted to enter your password, enter the password, and type return. If you have entered your account and password correctly, you will see a prompt message like the following, indicating that you have logged onto the storm server:
[harazduk@storm ~]$
Now you can start to type commands into the terminal to get different things done. The first thing is:

When you are working from your own computer, you can follow the instruction given at here. http://storm.cis.fordham.edu/~harazduk/cs3595/access.html.

b. Setting up your environment for submission

Most of you have probably taken a class that uses the submitClass and verifyClass scripts. Here are some instructions to remind you how to configure your environment for this class: https://storm.cis.fordham.edu/submissions. When configuring your environment using the ~harazduk/bin/configOS script, remember that changes to the environment won't take affect until you run bash again either by logging in or by running bash again.

2. Review Unix commands

Storm is a Linux (i.e. fedora) system which is considerably different from Windows. In order to be more productive in this class, you need to learn some basics about how to get things done in Linux/Unix system. Below is a list of useful commands to remember. Create a list of commands that manipulate processes or provide resource status. List the command and a short explanation of what it does. Put the list in a file called linux.txt. Include 10 different commands and find the long form (e.g. uname -a). You can use man -k keyword to search the manual like this: man -k status | less. Here are some basic linux commands followed by some Process control and system commands.

Basic commands

Process control and system commands - look for others

Note, you can take the following two tutorials, if you haven't done so before and are completely unfamiliar with linux:

2. You will be Using emacs/vi to type in a small program

If you haven't used vi in a while, you can use vimtutor to familiarize yourself with vi. I also have some other resources on my home page.

3. Configure your environment

Now that you have learnt some basic Unix commands, type in the following commands which will set up your account.

4. Write a program

First go to your home directory, and list files or directories in your home directory. Create a subdirectory named OS.

Now, go to your OS directory, and then create a directory named lab1 under there, and go to this newly created directory. Type in a program that reads all of the arguments from the command line, uses the first argument as a command and the remaining arguments as the arguments to the given command.

Use fork and one of the exec (e.g. execv, execvp) calls to issue the command and waituntil the command is completed. [NOTE: To see how these work, type man 3 exec or man 3 wait. The man pages also tell you what header files to include.] If a -1 is returned from fork or exec, an error occurred. Use perror to print the command, error and exit. Print out the arguments in a for-loop before forking and executing the command. Print out the process id of the parent and child. Examples of good output is shown below. Please match the static parts of the output as much as possible. For more discussion on using command line arguments, see cplusplus.com:How to parse command line parameters

You have to use command-line arguments. In the past, int main() had an empty parameter list. There is another version that allows programs to access command-line arguments (calling a program with options on the command line). This is int main(int argc, char* argv[]). In this Geek for geeks command-lines, it shows how to write a program that uses command-line arguments.

[harazduk@storm lab1]$ lab1 ls -l
lab1 ls -l Child process pid is 6203
total 30 
-rwxr-xr-x 1 harazduk staff  8576 Sep 13 09:24 lab1
-rw-r--r-- 1 harazduk staff   636 Sep 13 09:22 lab1.cpp
-rw-r--r-- 1 harazduk staff 11190 Sep 13 09:15 lab1.html
-rw-r--r-- 1 harazduk staff   523 Sep 13 08:59 linux.txt
lab1 ls -l Parent process pid is 6202
[harazduk@storm cs3595]$ lab1 lss -l
lab1 lss -l Child process pid is 7296
lss: No such file or directory
lab1 lss -l Parent process pid is 7295

5. Compile and run the program

a. Basic compilation command

To compile a program named lab1.cpp, you type in the following command:
g++ lab1.cpp 
If there is no compile time error, the executable file (by default, it's named a.out) will be created. You can then type the following in the terminal to run the program
a.out

Like all Unix commands, the g++ command has many options that you can use to control its behavior. You can type man g++ to view a very long list of all options and their descriptions. For now, please familiarize yourself with the following options to g++ command:

c. Compilation Errors

If you experience compilation errors because errno, wait, fork or execv are unrecognized, you probably have left out an include file. Feel free to google or use the man command (i.e. man 3 exec) to see what include files are needed.

6. Submit your program (lab1.cpp) and cheat sheet (linux.txt)

The following submission method only works from storm server. Write me (jharazduk@fordham.edu) if you encounter any problem; include in your email the error message you received. To submit a file named “lab1.cpp” using command:
	submitOS lab1.cpp
You can then run command
	verifyOS lab1.cpp
To retrieve the file and verify that if the file has been submitted successfully. It should display the file you submitted back to you.

If you want to submit linux.txt and lab1.cpp at the same time, use the command:

	submitOS linux.txt lab1.cpp
Unfortunately, verifyOS only works on one file at a time.
	verifyOS lab1.cpp
OR
	verifyOS linux.txt

NOTE: There are two errors that you may encounter. The first you can fix yourself: submitOS: command not found. Either you did not run ~harazduk/bin/configOS or you did but the change did not take affect. If OSGradedLabs directory exists in your home directory, then you it's the latter. Run bash on the command line alone and try submitOS again.

	bash
If you encounter another error, send me an email with the error and I will fix it for you. You have finished lab1.