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.
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.eduNote 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.
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.
~harazduk/bin/configOSNote that
~harazdukrefers to the home directory of user
harazdukHere you are running a command that I wrote, which configures your account. If the command has been run successfully, a directory called OSGradedLabs is created in your home directory. The instructor will return the graded projects to you by putting the modified (with comments added) source code into this directory.
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
g++ lab1.cppIf 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:
g++ lab1.cpp -o lab1
submitOS lab1.cppYou can then run command
verifyOS lab1.cppTo 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.cppUnfortunately, 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.
bashIf you encounter another error, send me an email with the error and I will fix it for you. You have finished lab1.