SYSTEM CALLS & SYSTEM PROGRAMS
When a computer is turned on, the program that gets executed first is called the ``operating
system.'' It controls pretty much all activity in the computer. This includes who logs in, how disks
are used, how memory is used, how the CPU is used, and how you talk with other computers.
The operating system we use is called "Unix".
The way that programs talk to the operating system is via ``system calls.'' A system call looks
like a procedure call (see below), but it's different -- it is a request to the operating system to
perform some activity.
System calls are expensive. While a procedure call can usually be performed in a few
machine instructions, a system call requires the computer to save its state, let the
operating system take control of the CPU, have the operating system perform some
function, have the operating system save its state, and then have the operating system
give control of the CPU back to you. This concept is important, and will be seen time and
time again in this class.
System calls are system dependent. Knowing this, it would not be a good idea to directly
use system calls when portability cannot be neglected. System calls are also quite
complex. Most often, it involves the duo of TRAP and RET (or some variations of those
two). To implement system call, one would need specialized knowledge of I/O registers,
the sequence of operations needed to use them; and most important of all, implement
enough protection because I/O resources are generally shared among multiple users
and/or processes.
System Calls for I/O
There are 5 basic system calls that Unix provides for file I/O.
1. int open(char *path, int flags [ , int mode ] );
2. int close(int fd);
3. int read(int fd, char *buf, int size);
4. int write(int fd, char *buf, int size);
5. off_t lseek(int fd, off_t offset, int whence)
You'll note that they look like regular procedure calls. This is how you program with them -- like
regular procedure calls. However, you should know that they are different: A system call makes
a request to the operating system. A procedure call just jumps to a procedure defined elsewhere
in your program. That procedure call may itself make a system call (for
example, fopen() calls open()), but it is a different call.
The reason the operating system controls I/O is for safety -- the computer must ensure that if my
program has a bug in it, then it doesn't crash the system, and it doesn't mess up other people's
programs that may be running at the same time or later. Thus, whenever you do disk or screen or
network I/O, you must go through the operating system and use system calls.
TYPES OF SYSTEM CALLS
TYPES OF SYSTEM
CALL
Process file Device Information Communication
Control Management Mangement Management
Functions of the types of System Call:
Process control
_ end, abort
_ load, execute
_ create process, terminate process
_ get process attributes, set process attributes
_ wait for time
_ wait event, signal event
_ allocate and free memory
File management
_ create file, delete file
_ open, close
_ read, write, reposition
_ get file attributes, set file attributes
Device management
_ request device, release device
_ read, write, reposition
_ get device attributes, set device attributes
_ logically attach or detach devices
Information maintenance
_ get time or date, set time or date
_ get system data, set system data
_ get process, file, or device attributes
_ set process, file, or device attributes
Communications
_ create, delete communication connection
_ send, receive messages
_ transfer status information
_ attach or detach remote devices
SYSTEM PROGRAMS
Another aspect of a modern system is the collection of system programs. Recall ,which depicted
the logical computer hierarchy. At the lowest level is hardware. Next is the operating system,
then the system programs, and finally the application programs. System programs provide a
convenient environment for program development and execution. Some of them are simply user
interfaces to system calls; others are considerably more complex.
They can be divided into these categories:
File management:
These programs create, delete, copy, rename, print, dump, list, and generally manipulate files
and directories.
Status information:
Some programs simply ask the system for the date, time, amount of available memory or disk
space, number of users, or similar status information. Others are more complex, providing
detailed performance, logging, and debugging information. Typically, these programs format and
print the output to the terminal or other output devices or files or display it in a window of the
GUI. Some systems also support a registry, which is used to store and retrieve configuration
information.
File modification:
Several text editors may be available to create and modify the content of files stored on disk or
other storage devices. There may also be special commands to search contents of files or perform
transformations of the text.
Programming-language support :
Compilers, assemblers, debuggers and interpreters for common programming languages (such as
C, C++, Java, Visual Basic, and PERL) are often provided to the user with the operating system.
Program loading and execution:
Once a program is assembled or compiled, it must be loaded into memory to be executed. The
system may provide absolute loaders, relocatable loaders, linkage editors, and overlay loaders.
Debugging systems for either higher-level languages or machine language are needed as well.
Communications:
These programs provide the mechanism for creating virtual connections among processes, users,
and computer systems. They allow users to send messages to one anothers screens, to browse
web pages, to send electronic-mail messages, to log in remotely, or to transfer files from one
machine to another.