Question: Objective Get familiar with the Linux/C environment, specifically use an editor, compiler, and run a socket program pair. First, here are several links to good
Objective
Get familiar with the Linux/C environment, specifically use an editor, compiler, and run a socket program pair.
First, here are several links to good tutorials on using text editors and the C compilation tools on the Linux system.
http://heather.cs.ucdavis.edu/~matloff/unix.html http://cslibrary.stanford.edu/ http://www.cs.cf.ac.uk/Dave/C/
Info on Make files http://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/
https://www.cs.bu.edu/teaching/cpp/writing-makefiles/
https://www.cs.oberlin.edu/~kuperman/help/make.html
Learn how to use a text editor on the Linux machines. You can pick whichever one you want. Some commonly used editors are vim, joe, or emacs. Any of these are good choices if you have not used one before. Read the man (manual) page describing the editor either directly on the Linux machine (e.g., >man vim) or at http://www.die.net/doc/linux/man/
Now use your editor to create a very simple program. The contents of the file are given below. Name the file hello.c.
#include
#include
int main() {
printf(hello world );
exit(0);
}
Now compile your program using the gcc compiler. You can compile it using this line: gcc hello.c o hello.
Now run the program using this command: hello (or possibly ./hello if your path does not include the current directory.)
Now lets get more ambitious and compile and run a couple programs which will communicate across 2 machines. Download the urecv and usend programs posted with this prelab. Use WinSCP or another secure FTP program to upload them to your csweb01 account. Compile them both. Now, using one putty session (say to csweb01), run urecv. Open another (simultaneous) putty session to different Linux machine (say hopper) and run usend. Usend will send one packet to urecv. Very exciting! The instructions for running each program are in the program headers and I posted a script showing them working as well.)
Questions:
Read the manual on the editor you have chosen. a) State which editor you chose to use. Explain how you b) add a new line of code, c) search for a string, and d) save the file and exit.
Read (or perhaps skim) the man page on gcc. You may use other C compilers on Linux if you prefer (e.g., g++). a) State which compiler you used. Explain how you b) link in a library. (Note this is not the same as including an include file.)
Read the tutorial on make files above. a) What is the purpose of makefiles? b) Give a simple example makefile which you could use to compile your program by typing make.
Change the hello program to print out your name. Type script to begin recording all output. Type "cat hello.c" to display your program code. Now recompile your new program and run it. Type exit to end the recording session. The output file is called typescript. Use the WINSCP file transfer program or another FTP program to transfer your file from the Linux machine to your home machine. See the class announcements for a pointer to WINSCP. Print out the script file.
Create script files showing your usend and urecv programs running as well and print them out. (You dont need to cat them or compile them in the script.)
Specify which machines you ran usend and urecv on, and which port number urecv used.
Notes:
To do this lab, you may log onto a Linux machine remotely using an ssh (secure shell) program. A free ssh tool that you may find on download.com is called putty. See the class announcements for a pointer to putty
The names of the Linux machines that you may access are given in the announcement. How to log onto your Linux account. csweb01.csueastbay.edu, hopper.csueastbay.edu, and turing.csueastbay.edu are currently available.
Check your execution path to see if it includes the current directory by typing echo $PATH. This is my path: /usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/apps/instantclient_12_2/bin:/home/ad.csueastbay.edu/ua9347/.local/bin:/home/ad.csueastbay.edu/ua9347/bin
It currently does not include the current directory, which is abbreviated to .. You can add the current directory into your path by editing your .bash_profile. This is a configuration file for your shell (or command interpreter.) I did so and my new path is: /usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/apps/instantclient_12_2/bin:/home/ad.csueastbay.edu/ua9347/.local/bin:/home/ad.csueastbay.edu/ua9347/bin:.
(Notice the . at the end.) Now when I type the name of an executable and that executable is in the current directory, the operating system can find it and run it. (Well, actually, you have to log out and back in for it to take effect.) Your .bash_profile configfile is in your home directory. Since it begins with a ., it is hidden. You can see hidden files by typing ls la.
If you dont modify your .bash_profile, you can force the operating system to look in the current directory by specifying the path in the command line, e.g., ./urecv4
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
