CS 279 - Week 4 Lecture 1 - 9-11-12
* still on Chapter 2!
* NOTE:
* when you run a bash shell script, it turns out
it is run in a new child shell (which exits
when your shell script exits)
* to run a bash shell script's commands as part
of the current shell session, use the source
command:
source <script-name>
compare:
* put a job in the background
* run:
jobs-demo.sh
* compare to:
source jobs-demo.sh
Job Identifiers - from course text, p. 34
------------------------------------------
* (DON'T type the < > below -- they are surrounding things YOU
choose)
%<n> Job number <n>
%<str> The unique job whose name begins with <str>
%?<str> The unique job whose name contains the string <str>
%+ The current job
%% The current job
% (in bash) The current job
%- The previous job
* you can change the status of a Stopped job to Running (in
the background) with the bg command
bg %3 # tries to make job [3] Running in the background
Process Groups - from Section 2.6.4, course text
-------------------------------------------------
* process group: a set of processes that can be signalled
together
* FIRST process to enter a process group becomes the
process group leader --
its process ID becomes the GROUP's process ID;
* example: the processes in a pipeline form a process group
whose process group leader is the first process in the pipeline:
ps x | grep emacs | sort > looky
* ps x is the process group leader above;
its process ID becomes the group's process ID (according
to the textbook, not sure based on our experience???)
Environment Variables - a little taste, with more to come
----------------------------------------------------------
* from section 2.6.5 of the course text
* every process has a collection of ENVIRONMENT VARIABLES
associated with it;
* want to see those currently in effect? use the env command
env
* these can be USED or SET by the process
* these are INHERITED by SUB-processes
* Inherited? Yes --
* when you start a new process as a CHILD of another,
UNIX sets the environment variables of the child process
to a COPY of its parent's environment variables;
* FROM THAT POINT, though, the environment variables of the
child and the parent are INDEPENDENT -- it's a one-way
thing!
* one process CANNOT examine or modify the environment
variables of another...! (acc. to p. 36, course text)
* when a process ends, its environment variables DISAPPEAR
and any CHANGES to these variables are LOST;
* but wait, there's more --
most UNIX programs that accept commands interactively
(including shells)
ALSO have a set of LOCAL VARIABLES that help to define the
program's behavior;
* the relationship between environment variables and
local variables IS confusing; more on that later!
Real and Effective Users and Groups - p. 36, course text
--------------------------------------------------------
* REAL USER ID of a process ordinarily identifies which user
CREATED the process
* when a *process* spawns a child process, that child
process INHERITS the real user ID of the parent;
* also: each process has an EFFECTIVE USER ID that determines
the process's PRIVILEGES
* this provides a mechanism for a program to perform
privileged operations on your behalf;
e.g., the passwd program
* likewise, each process has analogous REAL GROUP ID and
EFFECTIVE GROUP ID
The UNIX file system -- continued!
-----------------------------------
* from section 2.7 of the course text;
* because we've already talked about it quite a bit,
with quite a bit more to come...!
* 3 kinds of files:
* regular files
* directory files
* special files (of several kinds)
* UNIX views a file -- whichever its type -- as a
SEQUENCE of BYTES;
* a filename can include any character except for '/' or the null
character
* (although some characters such as '&' and <space> can be
a pain, because of their special meanings on command lines)
* (and avoid hyphens as the FIRST character of a filename...)
* by convention, a dot (.) at the start of a filename is used
for an INITIALIZATION file or other SUPPORTING file for a
particular program --
* recall that these are the "invisible" files not shown
by the ls command unless the -a (all) option is given;
Pathnames
---------
* a PATHNAME is a name that designates a file -
consists of a sequence of filenames separated by slashes (/)
* see the idea here?
the filenames are the COMPONENTS of the pathname;
* the LAST filename in a pathname is called the BASENAME
* the portion PRECEDING the last filename is called the
PATH PREFIX
* (the trailing slash is OPTIONAL in a path prefix
designating a directory...)
* (and we've already discussed how there are TWO kinds of
pathnames, ABSOLUTE and RELATIVE)
...where ABSOLUTE begins with a /,
and RELATIVE does not;)
* (and we've already discussed how
.
is a nickname for the current working directory, and
..
is a nickname for the parent of the current working directory)
* likewise, we've noted that (in all but the Bourne shell)
* ~
...at the start of a pathname refers to the home
directory of the current user
~/bin
...refers to the bin directory in the logged-in user's home
directory
* ~<user>
...refers to the home directory of user <user>
~st10/279submit
...refers to file 279submit in st10's home directory