The data file To exchange data with pre-open OS UNIX file system calls are read
and write. In the case should clearly specify what byte file to be read or write
data, the system is also used lseek challenge. System call reading data from the
file is read three arguments: read (fd, buffer, nbytes); The first argument is
an integer variable fd relevant open file descriptor. The second argument is a
pointer to the buffer area of user memory, which should put the matter of data.
Number of bytes of memory that is set to integer argument nbytes. The function
returns a true read a handful of bytes (it may be different from a given if, for
example, has raised the area of reading, going beyond file), or error code -1.
The beginning of the disk you want to read with the call read out in the system
call is not reported. Reading starts with a byte, which indicates the offset
offset in the file structure. This shift indicates the record number fd table of
open files. After the call read shift offset increasing the number of bytes read.
View Systems call records write similar challenge to read: write (fd.buffer.nbytes):
The function write writes nbytes of buffer RAM buffer to a file descriptor fd
out. The function write, as well as read, returns caused it to the real value of
the programme of bytes or error code. Consider an example in which the
application is working with the file, which is comprised of fixed-length records
of 50 bytes: fd = open ( "/ doc/qwery/basel2.txt." 0_RDWR): readCfd.bufferl.50):
read (fd.buffer2.2500): lseekCfd, 150.0): write (fd.output. 300): close (fd): In
the fragment program after opening file / doc/query/base12.txt to read and write
is your reading of the first file, and then read the file area, which includes
about 50 entries, ranging from 2 to 51. After a handful of records (these are
omitted) are moving pointer offsets in the file at the beginning of the fourth
record and the record of six consecutive records, starting with the fourth.
Completed fragment closing the file system through close call. All described the
system calls are synchronous, that is a custom process will be placed in waiting
until the I / O operation is completed. Described set of system calls, appeared
in UNIX OS still in the 70 years, became the de facto standard for modern
operating systems. These traditional system calls often in specific OS
complemented by original system I / O calls, such as asynchronous operation type.
Based on the input-output system calls are usually more powerful I / O library
functions that make up the application interface OS. Locking Files Blocking
files and individual records in the files are a means of synchronization between
working in cooperation processes, trying to use the same file simultaneously.
Processes can be appropriate access to the file, but simultaneous use of these
rights (especially the right notes) can lead to incorrect results. A case is the
simultaneous editing the same document multiple users. If a file is not
controlled lock, every person who is entitled to write to a file, works with a
copy of their data file. The result of this editing unpredictable, it depends on
the order in which changes to a file recording the user application editors.
Multiuser operating systems generally supported a special challenge to a system
that allows a programmer to install and test the lock on the file and its
sections. On UNIX systems such challenge is fcntl. In his arguments indicated
descriptor file, which you need to install or check the lock, the type of
operation (block or check, blocking access to reading or writing), and area
closures, movement from the beginning and the size of the file in bytes. When
checking locks set by other processes, call fcntl immediately return a message
from management. When the lock can be set two modes of the system call: the
transition process in a state of expectation, if not a lock (synchronous system
call), and an immediate return to a situation with a negative message (asynchronous
call). Block requested records could not be determined if another process is
already set its blocking list for the same file. That is blocking record is
exceptional. Lock reading are not exclusive and can be installed on a file, if
not their area of overlap. If any of the file is read-blocking, then this area
can not be blocked account. In UNIX, there are two modes of lock-advisory (advisory)
and mandatory (mandatory). The main guideline for the use of a consultative mode.
In its operating system is not blocking transactions with the file, but only
sets the signs blocking of file structures that support operations with files.
Kooperiruyuschiesya processes must check locks on the file to synchronize their
work. If the lock is installed, but the process does not check them, the
operating system does not prevent access of the file, the process makes the
system calls read or write. Compulsory treatment ban on the operation with
locked file supported operating system, therefore, in any case, will not have
access to this file. However, the work in this mode operating system spends a
lot of time and effort to maintain it, so it is usually not recommended.
Standard input and output files, then withdrawal In the UNIX operating system
were introduced at the time such a thing as a "standard input file", "standard
output file" and "standard" file error. The three already open file there any
custom process since its inception. The process may at any time to enter data
from the standard input file by following a systematic challenge: read (stdio.
bufer. nbytes); Here stdio-name predetermined constants, showing standard file
descriptor entry. Similarly, as stdout-name descriptor predetermined standard
output file, the process can move data to the standard output file using the
system next challenge: write (stout. buffer, nbytes): For standard file error is
addressed stderr. In fact, with a new process OS puts in its table of open files
three entries: with the number 0-for standard input file (hence, stdin is always
0), the number-one file for standard output (stdout = l), and number 2-for
standard file error (stderr = 2). Accordingly created three types of file
structure, which indicates the first three entry of open files. In the early
years of the existence of these three file structure associated operating system
with a single file. As the file is a special file-terminal, which logged in user.
The appointment of standard file naturally enough. Applications launched user
during the session work, often display results and the error messages on the
terminal screen, which is user and the keyboard of the same terminal read
commands, and other basic data. Model standard file I / O is mainly alphanumeric
terminals managed well describes the withdrawal stream of bytes, which appears
in the form of lines of characters on the screen, and the flow of input bytes
posed consecutive pushing buttons. The most well-known program, widely using
standard file I / O, is the team interpreter, also called a shell (shell)
operating system. Interpreter to read user input from the keyboard command (from
the standard input file) and perform their own or with their internal functions
(such teams are called domestic) or interpreted as a command name executable
file on disk, which should start to perform as a single process (external
commands). Communications interpreter arrives at the terminal screen is a
standard output file. Standard input and input files are widely used not only
command interpreter; But by the team. Many internal and external commands
designed so that they either read their raw data from the standard input file,
or display results in a standard output file. If the team is doing both, it is
called a filter. Consider a few examples of UNIX commands, working with standard
input and output files: ls dir2-read directory entry dir2 and displays them in
a symbolic form of a standard output file; we-filter, which is a sequence of
bytes read from the standard input file, counts the number of words, lines or
characters in a matter of data, and displays the result in a standard output
file; who, in a standard file displays information about users working in the
system. Interpreter teams perform such an important function as a standard
redirect input and output. This is the replacement terminal debug output log
file, the default as the standard input and output files to an arbitrary file.
Referral Mechanism based on the fact that the application does not know what the
file is standard, but simply use a descriptor as a pointer to the file.
Therefore, I / O redirection to make the process of executing the standard
connection with a non-standard entries in the table of open files. Redirecting
using special designs command language. For a interpreter to redirect standard
input file to file uses the following structure: file
To redirect the standard required following the withdrawal of construction:
file For example, shown below command line record of the contents of a file
directory dir2 a.txt: ls dir2> a.txt I / O redirection mechanism introduced OS
UNIX has been widely disseminated in command interpreters many operating systems,
such as MS-DOS, Windows, OS / 2.
|