Input, Output, and Error Redirection
In order to work with processes on Linux, you must understand the role of redirection. A process that is set to run in the background will continue to display information on the console until it is told otherwise. Changing where a program sends its output is known as redirection.
Standard Output, Standard Input, and Standard Error are the three items that can be redirected. These items are represented by the files /dev/stdin, /dev/stdout, and /dev/stderr. All interactive process’ are programmed to write to these three files for errors, output and input. By default all three of these files are symlinked to through the /proc directory to the terminal the user is currently using. In the case of an interactive user, the flow is as follows.
/dev/stdout -> /proc/self/fd/1 -> /dev/tty1
The /proc directory is a virtual directory that contains information used to construct the users interactive environment and is thus different for each user. In this case you can see that it provides a layer of abstraction and acts as a link between the stdout file, and the file representing the users console device.
Redirection involves using special characters to tell the shell to send input, output, and errors to files other than the defaults. The following table lists these symbols.
> Redirect stdout
>> Redirect and append stdout
2> Redirect stderr
2>> Redirect and append stderr
< Use in place of stdin In order for a background process to truly run 100% in the background, you must suppress display of all errors. The following example uses redirection to produce a file listing of the entire file system as a background process.
Managing Running Processes
The [ps] command is the command used to manage running processes and can be used for many things including viewing the status of your computer and getting a quick idea of how well the computer is performing.
Here are some common ps commands.
ps View current interactive processes on this terminal.
ps –a All current processes on this terminal, by all users.
ps –x All processes not assigned to a terminal (daemons).
ps –aux Output all process running and include resource utilization information.
The man page for ps contains extensive documentation on how to modify and interpret the output of ps.
Top is a utility that can be used to display a live dataset of the currently running processes. Activate it by typing [top].