Lecture Notes
Introduction To UNIX Programming
UNIX was originally written by professional programmers for the use of other professional programmers. UNIX itself is written in C. Many UNIX systems also offer the FORTRAN, Pascal, and other languages.
Programming Languages
A computer program is a set of coded instructions that tell the computer how to perform some task. Computers understand machine language, which is stored in their memory as binary numbers -- combinations of 0s and 1s. Here is how a segment of a program might appear in binary form:
00000000110001100000000000011000
Obviously, it is tedious to program in binary code. A better alternative is to program in assembly language, which represents each machine's binary instructions symbolically. For example:
00000000000000000011100000010010
00000000111000100001000000100000
00100000110001100000000000000001mult $6, $6
This is still difficult to understand. Fortunately, high-level programming languages are available that make programming much easier. Here is that same program segment in the C programming language:
mflo $7
add $3, $7, $2
addi $6, $6, 1sum = sum + 1 * 1;
i = i + 1;Programming in C
Here is a simple demonstration of making and executing a C program. First you need to start and log on to a UNIX/Linux system. Mandrake 8.1 release of Linux will work fine for this task!
1. Get to the command line (or a terminal window if you are in X-Windows.) To start a terminal window, Click on the K on the lower-left if the task bar, then on terminals in the pop-up window, then A Term or X Term.
2. Start the vi editor for a new filed called hello.c by typing:vi hello.c
3. Press the i key, to start the insertion mode.
4. Enter the following C program statements:#include <stdio.h>
5. Now press the Esc key to stop the insertion mode.
int main()
{printf("Hello World\n");
}
exit (0);
6. Type the following::wq
and then press the Enter key, to save the file and quit the vi editor.
7. To compile the pile, type:cc -o hello hello.c
and press the Enter key.
8. To execute the program, type:./hello
and press the Enter key.
9. You should see the following output:Hello World
Programming in C++
Here is a simple demonstration of making and executing a C++ program. First you need to start and log on to a UNIX/Linux system. Mandrake 8.1 release of Linux will work fine for this task!
1. Get to the command line (or a terminal window if you are in X-Windows.) To start a terminal window, Click on the K on the lower-left if the task bar, then on terminals in the pop-up window, then A Term or X Term.
2. Start the vi editor for a new filed called hello.cpp by typing:vi hello.cpp
3. Press the i key, to start the insertion mode.
4. Enter the following C++ program statements:#include
5. Now press the Esc key to stop the insertion mode.
int main()
{cout << ("Hello World! From C++.\n");
}
return 0;
6. Type the following::wq
and then press the Enter key, to save the file and quit the vi editor.
7. To compile the pile, type:c++ -o hello hello.cpp
and press the Enter key.
8. To execute the program, type:./hello
and press the Enter key.
9. You should see the following output:Hello World! From C++.
.Programming in FORTRAN
Here is a simple demonstration of making and executing a FORTRAN program. First you need to start and log on to a UNIX/Linux system. Mandrake 8.1 release of Linux will work fine for this task!
1. Get to the command line (or a terminal window if you are in X-Windows.) To start a terminal window, Click on the K on the lower-left if the task bar, then on terminals in the pop-up window, then A Term or X Term.
2. Start the vi editor for a new filed called hello.f by typing:vi hello.f
3. Press the i key, to start the insertion mode.
4. Enter the following FORTRAN program statements. Be careful, FORTRAN is fixed format. The * for a comment must be in column 1. The P of the statement PROGRAM HELLO, must start in column 7!* First Fortran program.>
5. Now press the Esc key to stop the insertion mode.
*234567
PROGRAM HELLO
WRITE(*.*) 'Hello, world! From FORTRAN!'
END
6. Type the following::wq
and then press the Enter key, to save the file and quit the vi editor.
7. To compile the pile, type:f77 hello.f
and press the Enter key.
8. To execute the program, type:./a.out
and press the Enter key.
9. You should see the following output:Hello world! From FORTRAN!
Programming in HTML
HTML stands for Hyper-Text Mark-up Language. It is used for making Web pages for Internet. We will now make a simple HTML file that will be used in the next section when we write and view a Java applet.
First you need to start and log on to a UNIX/Linux system. Mandrake 8.1 release of Linux will work fine for this task!
1. Get to the command line (or a terminal window if you are in X-Windows.) To start a terminal window, Click on the K on the lower-left if the task bar, then on terminals in the pop-up window, then A Term or X Term.
2. Start the vi editor for a new filed called HelloApplet.html by typing:vi HelloApplet.html
3. Press the i key, to start the insertion mode.
4. Enter the following HTML program statements.5. Now press the Esc key to stop the insertion mode.
HelloApplet
6. Type the following::wq
and then press the Enter key, to save the file and quit the vi editor.
7. This file will be used in the second part of the Java section.Programming in Java
Programming in Pascal
.
Programming in Shell (sh, bash, etc).
CS 248 - UNIX Programming Web Site Menu
Information | Syllabus | Schedule | Online "Lectures" | Projects | Quizzes | Web Board
Copyright © 2001 by James L. Fuller, all rights reserved.