old-www/HOWTO/Path-3.html

92 lines
4.0 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
<TITLE>PATH HOWTO: General</TITLE>
<LINK HREF="Path-4.html" REL=next>
<LINK HREF="Path-2.html" REL=previous>
<LINK HREF="Path.html#toc3" REL=contents>
</HEAD>
<BODY>
<A HREF="Path-4.html">Next</A>
<A HREF="Path-2.html">Previous</A>
<A HREF="Path.html#toc3">Contents</A>
<HR>
<H2><A NAME="s3">3. General</A></H2>
<P>
<P>All the Unix processes contain an "environment". This is a list of
variables that contain name and value, both just strings that can
contain most characters. All Unix processes have a parent process -
the process that created this process as child. Child processes
inherit environment from parent process. They can make some
modifications to the environment before passing it in turn to their
child processes.
<P>One important environment variable is PATH, a list of directories
separated by colons (':'). These directories are searched through to
find commands. If you try to invoke command 'foo', all the
directories in PATH (in that order) are searched for an executable
file 'foo' (one with x-bit on). If a file is found, it is executed.
<P>In this howto, I use term 'command' to refer executable program that
is meant to be called with short names, using the path mechanism.
<P>In Linux, even the low level operating system calls to start
processes (the exec family of calls) searches through directories in
the PATH variable: you can use the path mechanism anywhere where you
try to execute a command. If exec operating system call gets a file
name that does not contain '/', it evaluates the PATH environment
variable. Even if there is no variable PATH in the environment, at
least directories /bin and /usr/bin are looked for suitable commands.
<P>In sh you use export command to set environment, in csh you use setenv
command. For example:
<P>sh:
<BLOCKQUOTE><CODE>
<PRE>
PATH=/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:.
</PRE>
</CODE></BLOCKQUOTE>
csh:
<BLOCKQUOTE><CODE>
<PRE>
setenv PATH /usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:.
</PRE>
</CODE></BLOCKQUOTE>
<P>C-programs can use setenv() library call to change environment. Perl
has environment in an associative array %ENV, you can set PATH as
$ENV{PATH}="/bin".
<P>env command is the basic way of asking the current environment
variables. It can be used to modify it as well.
<P>More information of the basic environment mechanism can be found from
manual pages 'environ', 'execl', 'setenv', info file 'env' and
documentation of shells.
<P>When Linux boots up, the first normal process that starts is the init
process. It is a special process because it does not have parent.
However, it is the ancestor of all the other processes. Init
environment will remain as environment of all the processes if they do
not touch it explicitly. Most processes do touch.
<P>Init starts a group of processes. File /etc/inittab tells what
processes the system starts. These processes work in the environment
that is directly inherited from init - typically they are processes
like 'getty', the program that writes 'login:' to console. If you
start PPP connections here, you must remember that you are working in
the init environment. The system initialization is often a script
that is started here. In Debian 1.3 initialization script
/etc/init.d/rc and it calls other initialization scripts in turn.
<P>The system contains many running servers (daemons) that may or may not
use the default environment. Most servers are started from the
initialization scripts and thus they have the init environment.
<P>When user logs in to the system, the environment is affected by the
settings that are compiled into the programs, system wide
initialization scripts and user initialization scripts. This is
pretty complicated and the current situation is not completely
satisfactory. It is totally different if user logs in from text
console, XDM or from network.
<P>
<P>
<HR>
<A HREF="Path-4.html">Next</A>
<A HREF="Path-2.html">Previous</A>
<A HREF="Path.html#toc3">Contents</A>
</BODY>
</HTML>