# Processes and files

## Processes and files¶

When creating a process, three files are attached to it: the standard files. A process reads its data (and its commands) in the input standard file; it writes its results in the standard output file; and sends its error messages on the standard error file.

The shell process that is created when a user logs on is such that the standard input file is connected to the user's keyboard, and the standard output and error files are connected to the user's screen (terminal).

All the processes created by the original shell inherit these connections. Thus, any shell command (executed in a child process) read its data from the keyboard and display its results on the screen.

When creating a process, you can redirect its standard input/output. One can thus connect the standard files to existing files for example.

##### Example¶

The echo command displays a message on the standard output

echo Hello


"Hello" appears on the screen.

The standard output can be redirected to a file using the > command:

echo Hello > f1


Hello is written in file f1.

To know the contents of file f1, you can use the cat command:

cat f1


Under bash, the redirection syntax is as follows:

command meaning
> f1 redirecting the standard output to "f1", creating "f1" file if it did not exist, or overwriting otherwise
2> f1 same but for standard error
>> f1 redirection of the standard output to f1, with creation of f1 if it did not exist, or elongation of f1 otherwise
2>> f1 same but for standard error
<f1 redirection of standard input using file f1
| redirection of the standard output of a process to the standard input of the next process