- •Management processes
- •1 Purpose of
- •2 Key provisions
- •2.1 Process control: general
- •2.2 Kill command
- •2.3 Priorities processes. Nice command
- •2.4 Ps command
- •2.7 Program cron
- •3 Control questions
- •4 Homework
- •5 Laboratory assignment
- •2.5 Nohup command
- •2.6 At command
- •6 Requirements for the content of the protocol
- •Readdress of input/output, conveyor
- •1 Purpose of
- •2 Key provisions
- •2.1 Standard streams
- •2.2 Pereadrssatsiya standard input / output
- •2.3 Variable noclobber
- •2.4 Device /dev/null
- •2.5 Redirecting stdin using exec
- •3 Key Questions
- •4 Homework
- •5 Laboratory assignment
- •6 Requirements for the content of the protocol
6 Requirements for the content of the protocol
Name of laboratory work.
Objective.
The results of the assignment.
Brief description of the work done.
Conclusions of the work done.
Date, signature of the student visa is a teacher.
Lab № 4
Readdress of input/output, conveyor
1 Purpose of
1.1 Examine input / output streams in OS UNIX.
1.2 Get familiar with standard input / output streams.
1.3 Implement diversion flows.
2 Key provisions
2.1 Standard streams
Standard input / output device provides some basic facilities of input-output. These are the three standard streams: input, output and error. Under the agreement, the standard output stream contains all the "normal" output of the program, while the standard error consists of error messages. By default the standard input program is a keyboard, and standard output and error are sent to the screen.
At the time of receipt of the standard input stream (Fig. 6) or divert a file (Fig. 7), the kernel assigns each file number, or tag:
standard input (stdin) receives a file descriptor 0 (associated with the file from the process reads the data);
standard output (stdout) receives a file descriptor 1 (associated with the file where the process of recording their answers);
standard error (stder) receives a file descriptor 2 (linked to the tether, where the process sends error messages).
Figure 6 - Opening of the standard I / O streams without forwarding commands
2.2 Pereadrssatsiya standard input / output
The main advantage of standard I / O is the ability to redirect input or output from the terminal to a file (Fig. 7).
Figure 7 - Standard output redirected to a file
Despite the fact that the standard I / O is a key element of UNIX, the syntax to redirect depends on the type of interpreter shell (Table 19).
Table 19 - Common ways to redirect standard input-output
Action |
csh |
sh |
1 |
2 |
3 |
Redirect stdout to file Redirect stderr to file Redirect stdout and stderr to file Reading stdin from file |
program> file
program> & file program <file |
program> file program 2> file program> file 2> & 1 program <file |
Redirect stdout to end of file Redirect stderr to the end of file Redirect stdout and stderr to the end of file |
program>> file
program>> & file |
program>> file program 2 >> file program>> file 2> & 1 |
Reading stdin from the keyboard until will be entered a symbol c |
program>> c |
program>> c |
Send stdout to channel
Send stdout and stderr to a channel |
program □ program 2 program □ & program 2 |
|
Consider a few examples of redirection of standard input-output:
To send a file by e-mail user joan, using the operator <filename that tells the interpreter shell, that the standard input program mail instead of a keyboard, connect the file:
% Mail joan <myfile
To send output commands in a file rather than print them on the terminal must be:
% Cat filel file2> file 3
The most common form of redirection in UNIX is a channel (denoted by the operator | (vertical bar)).
For example, to send a correspondent joan files file1 and file2 in one e-mail message, you must enter the following:
% cfn file1 file2 | mail joan
Secure forwarding of I / O
Setting variable noclobber prevent accidental destruction of data file with redirection of standard output. Consider the following scenario:
% Command> output_file
This line command deletes the old output file and creates a new one. If you or falsity enter the file name, or forgot that the file already exists and contains important data, or going to type>> instead of>, then, unfortunately, your old data will be destroyed.
