Transcript C and Unix

C and Unix
A Couple Basic Concept and Terms
• 1. File.
• 2. Process.
• 3. Memory
• 4. HD
Binary Number
•
•
•
•
•
•
Decimal
Binary
Octal
Hexadecimal
Logical Operations
Arithmetic Operations
Unix
•
•
•
•
What is Unix?
What is Operating System (OS)?
Basic Computer components.
The relationship between hardware and
software.
• The roles of OS.
• The roles of C (programming language).
Unix as an “open” system
• The internal software architecture is well
defined and available in source code form,
either free or for a relatively small fee.
• Another similar OS is Linux which is
basically free.
Unix Standards
• AT&T’s Bell Lab first invented and
introduced the original Unix version (now
becomes system V).
• Other versions:
• BSD—Berkeley Standard Distribution
• IBM—AIX
• HP– HP-UX
Main Features of Unix
•
•
•
•
•
•
•
•
1. It is a multi-user system.
*** The most important concept—Time Sharing
2. It shares CPUs, memory, disk space
efficiently.
3. It has a large number of standard
utilities.
4. It is a portable system that is available
for many different platforms.
Using C with UNIX
• A little knowledge is necessary before you can
write and compile programs on the UNIX
system. Every programmer goes through the
same three step cycle.
• 1. Writing the program into a file
• 2. Compiling the program
• 3. Running the program
• During program development, the programmer
may repeat this cycle many times, refining,
testing and debugging a program until a
satisfactory result is achieved.
• C and UNIX
• This course teaches C under the UNIX operating
system.
• C programs will look similar under any other
system (such as VMS or DOS), some other
features will differ from system to system.
• In particular the method of compiling a program
to produce a file of runnable (executable) code
will be different on each system.
• The UNIX system is itself written in C. In fact C
was invented specifically to implement UNIX.
• All of the UNIX commands which you type, plus
the other system facilities such as password
checking, line printer queues or magnetic tape
controllers are written in C.
• In the course of the development of UNIX,
hundreds of functions were written to give
access to various facets of the system.
These functions are available to the
programmer in libraries.
• By writing in C and using the UNIX system
libraries, very powerful system programs
can be created.
• These libraries are less easy to access
using other programming languages.
• C is therefore the natural language for
writing UNIX system programs.
This Course
• One of the main objects for this course is to
introduce programmers to the C language.
• Previous programming experience is assumed,
so we can quickly progress to looking at the
features of C and their uses.
• Students with little programming experience will
need to do some more homework in order to
keep up with the lectures.
Common C
• Until recently there was one dominant
form of the C language.
• This was the native UNIX form, which for
historical reasons is known as either Bell
Labs C, after the most popular compiler, or
K. &R. C, after the authors of the most
popular textbook on the language.
• It is now often called "Classic C"
ANSI C
• The American National Standards Institute defined a
standard for C, eliminating much uncertainty about the
exact syntax of the language. This newcomer, called
ANSI C, proclaims itself the standard version of the
language. As such it will inevitably overtake, and
eventually replace common C.
• ANSI C does incorporate a few improvements over the
old common C. The main difference is in the grammar of
the language. The form of function declarations has
been changed making them rather more like Pascal
(another used to be popular language) procedures.
• This course introduces ANSI C since it is supported by
the SUN workstation compilers. Most C programming
texts are now available in ANSI editions.
.
Unix File System
• .
• Unix has three categories of files:
• 1. Regular Files
•
which could be: code, data, text….
• 2. Directory Files
• 3. Special Files
•
device files, such as: printers, disks,
•
terminals…
File and Directory Names
• Avoid using the following characters in any
filenames:
• < >, ( ) , [ ], { }, *, ? , “ , ` , - , $, ^
• To avoid confusion, the following characters
are recommended:
• ( A – Z ) , (a – z), ( 0 – 9) , ( _ ) , ( . )
• Be careful about using:
• Space --- Never use it in any part of Filename
File Type and Access Mode
• When using ls –l command, one can see the full
nature of files.
• The first character in each line indicate the file
types:
• - indicates an ordinary file
• d indicates a directory file
• b indicates a block-orientated special file
• c indicates a character-oriented special file