Page 257 - DCAP403_Operating System
P. 257
Operating System
Notes stalled, the entire computer system stalled. By making use of an additional component to pre-
empt each process when its “turn” is up, stalled programs do not affect the overall flow of the
operating system.
Each “turn” is called a time slice, and each time slice is only a fraction of a second long. It is this
rapid switching from process to process that allows a computer to “appear’ to be doing two
things at once, in much the same way a movie “appears” to be a continuous picture.
Types of Processes
There are generally two types of processes that run on Linux. Interactive processes are those
processes that are invoked by a user and can interact with the user. VI is an example of an
interactive process. Interactive processes can be classified into foreground and background
processes. The foreground process is the process that you are currently interacting with, and
is using the terminal as its stdin (standard input) and stdout (standard output). A background
process is not interacting with the user and can be in one of two states - paused or running.
The following exercise will illustrate foreground and background processes.
1. Logon as root.
2. Run [cd \]
3. Run [vi]
4. Press [ctrl + z]. This will pause vi
5. Type [jobs]
6. Notice vi is running in the background
7. Type [fg %1]. This will bring the first background process to the foreground.
8. Close vi.
The second general type of process that runs on Linux is a system process or Daemon (day-mon).
Daemon is the term used to refer to process’ that are running on the computer and provide
services but do not interact with the console. Most server software is implemented as a daemon.
Apache, Samba, and inn are all examples of daemons.
Any process can become a daemon as long as it is run in the background, and does not interact
with the user. A simple example of this can be achieved using the [ls -R] command. This will list
all subdirectories on the computer, and is similar to the [dir /s] command on Windows. This
command can be set to run in the background by typing [ls -R &], and although technically you
have control over the shell prompt, you will be able to do little work as the screen displays the
output of the process that you have running in the background. You will also notice that the
standard pause (ctrl+z) and kill (ctrl+c) commands do little to help you.
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
250 LOVELY PROFESSIONAL UNIVERSITY