Professional Documents
Culture Documents
Hardware
The hardware consists of the physical components.
The following are some of the hardware components
- One or more processors or central processing units (CPU).
- The memory.
- The input system: consists of the input devices (keyboard, mouse. . . etc) and their controllers.
- The output system: consists of the output devices (monitor, printer . . . etc) and their controllers.
- The storage media and the storage devices. Examples of storage media are the hard disk, CD,
DVD, flash disk and tapes.
The processor (CPU) interprets (decodes) and executes the instructions of a program.
The main memory holds the program(s) being executed and their data.
An input device is used to transmit data from the outside world into the computer whereas an output
device is used to transmit information from the computer to the outside world.
A storage media is used to hold programs and data for future use inside the computer, and a storage
device (or drive) is used to read and write on a storage medium.
Each input/output/storage device has a controller that is used to control its operations. Furthermore,
an input device controller translates the signals of that device into bits whereas an output device
controller translates bits from the computer into the signals of that device. A storage device
controller does the translation in both ways. Device controllers are also used for communication
with the CPU.
Software
The software is the collection of programs that a computer can execute.
There are two major classes of software:
system programs and
Application programs.
Editor
- reads characters from the keyboard and places them into a file.
Compiler
- translates a high-level language program source module into machine language.
- creates an object file (module) that contains the machine language code translation of the source
module.
Loader
- determines how much memory is needed for a program load module and the address of the first
instruction to be executed in the program (program entry point).
- copies the load module into the memory.
- adjusts relative references to memory locations (that depend on the starting address of the
program) by adding a constant to them.
- initializes the registers that are necessary for the execution of the program.
- transfers the control of the CPU to the program for execution.
UNIX Kernel
The UNIX kernel is the program that is loaded from the disk into the main memory when the
computer is first turned on.
It always stays in the main memory and runs until the system is turned off or crashes.
The UNIX kernel contains codes to do the following:
- share the processor(s) and the main memory between competing executing programs
- process all system calls
- handle peripherals (input/output system and storage media/devices).
Note: Many UNIX systems also have a graphical user interface (X Windows) that can be used to
interface with the system.
The name of a user’s home directory is set by the system administrator to his or her username.
Files and subdirectories in the same directory cannot have the same filename.
However, files and subdirectories in different directories can have the same filename.
The largest directory in a UNIX system is the root directory and is denoted by the forward slash /
Example:
A UNIX directory hierarchy in which the names of directories are underlined follows:
glass ndjatou
myfle
prog.cpp
The directory from which a user is working is referred to as that user’s working directory.
When a user logs into a UNIX system, his/her working directory is automatically set by the shell
program to his/her home directory.
Pathnames can also be specified relative to a user’s working directory.
A file or a directory relative pathname is a pathname that is specified relative to a user’s working.
When you type a command in a UNIX system, you may do the following:
use a period (.) to represent your current working directory
use two periods (..) to represent the parent of your current working directory in the directory
hierarchy.
UNIX Users
Every person needs a username and a password to log into a UNIX system.
Each user is also identified in a UNIX system by a non-negative integer called user ID (UID) that is
assigned by the system administrator.
The superuser has the username root and the UID 0.
The superuser has a special power and may access all the resources in the system.
Only the system administrator knows the password to log in as the super user.
A UNIX user is also assigned (by default) to a group (of users) by the system administrator.
A group is simply an arbitrary collection of users which offers a straightforward method for
controlling projects involving several users.
A group is also identified by a non-negative integer called group ID (GID) which is assigned by the
system administrator.
Each UNIX user belongs to at least one group, possibly more.
Information about a UNIX system groups is held in the file /etc/group.
In a typical UNIX system, entries in the password file (/etc/passwd) are used to hold the following
information about a user:
the username
a place marker for the user’s password
the uid
default gid
optional comment field
user’s home directory
the pathname of the user’s default shell.
Hands-On Practice U1
List of commands Discussed
Command purpose Reference
ls . <ENTER> list all the files(whose names do not start with a period) in the current working directory in alphabetical order
ls –a . <ENTER> list all the files in the current working directory in alphabetical order
ls –l . <ENTER> list the files in the current working directory with their attributes
4. Use the mkdir command (UPU book, pages 31-32) to create the directories cs2400 and others in
your home directory. (NB: you may use the ls command to make sure that you did it properly).
mkdir cs2400 <ENTER>
ls –l . <ENTER>
5. Use the cp command (UPU book, pages 33-34) to copy the files
/faculty/ndjatou/cs2400/gpacomputation.cpp and /faculty/ndjatou/cs2400/gpacomputation.h to the
directory cs2400 that you have created in step 4. (NB: you may use the ls command to make sure
that you did it properly).
cp /faculty/ndjatou/cs2400/gpacomputation.cpp cs2400 <ENTER>
ls –l cs2400 <ENTER>
6. Use the cd command (UPU book, pages 32-33) to make the directory others created in step 4 your
current working directory. (NB: you may use the pwd command to make sure that you did it
properly).
cd others <ENTER>
pwd <ENTER>
7. Use the cp command (UPU book, pages 33-34) to copy the files gpacomputation.cpp and
gpacomputation.h from your directory cs2400 into the directory others. (NB: you may use the ls
command to make sure that you did it properly).
cp ../cs2400/gpacomputation.cpp . <ENTER>
cp ../cs2400/gpacomputation.h . <ENTER>
or
cp ../cs2400/gpacomputation.cpp gpacomputation.cpp <ENTER>
8. Use the mv command (UPU book, page 31) to rename the file gpacomputation.cpp (in the directory
others which is your current working directory) gpacomputation1.cpp. (NB: you may use the ls
command to make sure that you did it properly).
mv gpacomputation.cpp gpacomputation1.cpp <ENTER>
ls –l . <ENTER>
9. Use the cd command (UPU book, pages 32-33) to make your home directory your current working
directory. (NB: you may use the pwd command to make sure that you did it properly).
cd <ENTER>
pwd <ENTER>
10. Use the cp command (UPU book, pages 33-34) to copy the file /faculty/ndjatou/cs2400/instructions
to the directory others. (NB: you may use the ls command to make sure that you did it properly).
cp /faculty/ndjatou/cs2400/instructions others <ENTER>
or
cp /faculty/ndjatou/cs2400/instructions others/instructions <ENTER>
ls –l . <ENTER>
11. Use the cat command (UPU book, pages 27 and 29) to display the content of the file instructions
that you have just copied into the directory others in step 10.
cat others/instructions <ENTER>
12. Follow the instructions provided in the file instructions.
13. The lp command (UPU book, pages 37 and 39) is used to print the content of the file
gpacomputation2.cpp on the UNIX machine default printer as follows:
lp gpacomputation2.cpp <ENTER> Use default printer(jennifer)
or
lp –d jennifer gpacomputation2.cpp <ENTER> Use jennifer printer
However, our UNIX system does not have a printer: we will therefore use an ftp software (such as
WinSCP) to download a UNIX file to our PC and then print it from there.
14. Use the rm command (UPU book, pages 27 and 29) to delete all the files in the directory others.
(NB: you may use the ls command to make sure that you did it properly).
You can delete one file at a time as follows:
rm gpacomputation1.cpp <ENTER>
rm instructions <ENTER>
. . .
Ls –l . <ENTER>
ls –l . <ENTER>
15. Use the cd command (UPU book, pages 32-33) to make your home directory your current working
directory. (NB: you may use the pwd command to make sure that you did it properly).
cd <ENTER>
pwd <ENTER>
16. Use the rmdir command (UPU book, page 35) to delete the directory others from your home
directory. (NB: you may use the ls command to make sure that you did it properly).
rmdir others <ENTER>
ls –l <ENTER>
Note: The command line in Step 7 to copy the file ../cs2400/gpacomputation.cpp to the current working
directory and the command line in step 8 to rename it gpacomputation1.cpp could be combined into
one command line as follows:
cp ../cs2400/gpacomputation.cpp gpacomputation1.cpp <ENTER>
Input/Output Redirection
In a C++ program, all the input data read using a cin statement are taken from the standard input,
and all the output data printed using a cout statement are sent to the standard output.
In a UNIX system, the standard input is set by default to the keyboard, and the standard output is set
by default to the monitor.
You can set the standard input to a different file by using input redirection as follows:
gpacomputation1.bin < gpacomputation1.input <ENTER>
- the input of the program gpacomputation1.bin will be read from the file gpacomputation1.input
(from your current working directory) instead of the keyboard.
You can set the standard output to a different file by using output redirection as follows:
gpacomputation1.bin > gpacomputation1.out <ENTER>
- the output of the program gpacomputation1.bin will be written into the file gpacomputation1.out
(that will be created in your current working directory) instead of the monitor.
The command line gpacomputation1.bin < gpacomputation1.in > gpacomputation1.out <ENTER>
executes the program gpacomputation1.bin that reads its input from the file gpacomputation1.in (in
your current working directory) and writes its output into the file gpacomputation1.out (that will be
created in your current working directory).
Example
$ ls -lsF cs2400/gpacomputation.cpp
6 -rw-r--r-- 1 ndjatou faculty 2375 Sep 16 2008 cs2400/gpacomputation.cpp
File Types
The first character of field #2 indicates the file type. The different types of UNIX files with their
corresponding characters are given in Figure 2.35 in page 44 (UP). The file type of the file in the
example above is regular file.
File Permissions
When you create a UNIX file, you must specify the read permission (r), write permission (w), and
the execute permission (x) of that file for the owner of the file, the members of the owner’s group
and the other users.
A file’s permission setting consists of three consecutive groups of three characters as follows:
The first group of characters is the permission settings for the owner,
The second is the permission settings for the members of the owner’s group, and
The last one is the permission settings for the other users of the UNIX system.
The first character of a group is r if the read permission is given, and a dash otherwise.
The second character is w if the write permission is given, and a dash otherwise.
The third character is x if the execute permission is given, and a dash otherwise.
For the file in the example above, the permission settings are rw-r- - r- -, which means that the
owner of the file can only read and write it, the members of his group and the other users can only
read it.
The table in Figure 2.38 in page 45 (UP) lists the permission meanings for files and folders.
You use the chmod command (page 49, UP) to change a file’s permission settings.
Hands-On Practice U3
1. Display the content of the file /etc/group on the screen (do not print it). How many groups are there
on your UNIX system?
2. Display the content of the password file, /etc/passwd, on the screen (do not print it) and find out the
following information about you held in UNIX:
a. your username
b. a place marker for the user’s password
c. your uid
d. your default gid
e. optional comment field
f. your home directory
g. the pathname of your default shell.
3. Use the groups command discussed in page 47 (UP) to display a list of all the groups to which you
are a member. What are they?
4. Use the chmod command to change the file permissions of your home directory such that nobody
else can access it as follows:
a. Display the current permission settings of your home directory: ls -ld . <ENTER>
c. Display again the current permission settings of your home directory: ls -ld . <ENTER>
5. Practice on using the man command to obtain on-line information on user commands, library
functions (system calls), . . . etc.