Clarification of Answer by
maniac-ga
on
19 Dec 2002 18:47 PST
Hello Vpb,
... more explanation ... easy to understand. Hmm. I don't know if I
can provide an easier to understand answer but I will describe what
happens in a different manner to see if that works for you.
The Unix shell reads a line of text and interprets it according to a
set of rules. In the example you provided, there are three commands as
follows.
ls -ls
grep user
sort
The first "argument" (or word) of each command refers to a program
that will be run. For example "ls" is a program that produces a list
of files that varies based on the arguments that follows. If you enter
man ls
to a Unix system you will get an explanation of the ls command which
on my system say that "-l" means to provide a "long format" listing of
the files and -s means to display the total number of 512 file system
blocks for each file (in addition to the long format output). You can
do the same for each of the other commands.
Each of the programs listed above will run in a separate process.
Generally that is done using fork and exec calls as described in the
original answer. In this case, it is necessary to connect the output
from the first program to the input to the second, and the output from
the second program to the input to the third. That is what the pipe
(|) symbol represents. This is done by the shell using the pipe
function call and some manipulation of the file descriptors by the
shell.
Each process will run, in parallel, to completion with the input and
output connected as I described it. When they are finished, the shell
ensures the new processes, pipes, and other resources are cleaned up.
For more description of the specific system calls and functions I
suggest the following Unix commands
man fork
man exec
man pipe
to understand what each does,
man ls
man grep
man sort
to understand what the individual commands do, and
man sh
to provide a user level description of the shell program.
--Maniac