CS 279 - Week 6 Lecture 1 - 2022-09-26
TODAY WE WILL
* announcements/reminders
* bit more on environment variables
* intro to processes and jobs
* [did not get to] standard files and redirection
* prep for next class
======
a bit more on environment variables
======
* we've seen that regular local variables in a shell
are not visible in a subshell of that shell
* CAN you make an environment variable in a shell
that WOULD be visible in its subshells?
more accurately: that will be *copied* to its
subshell
* YES!
* the export built-in command makes this possible
* LDP (Linux Documentation Project)'s Bash Beginners
Guide - Section 3.2.3
2021 rewrite of course text: Section 14.1
* export VARNAME="value"
VARNAME="value"
export VARNAME
* and now child shells will be passed a
copy of VARNAME...
======
Processes! Jobs! Oh my!
======
* when Linux is running, many activities
are underway at the same time --
these are called PROCESSES
(another quickie-definition I like:
a process is as program-in-execution)
* they may be literally running in parallel
(if multiple CPUs are involved)
or they may be so-called time-sharing a
single CPU
* in Linux/UNIX,
there's at LEAST a process for the running kernel
kernel: the HEART of a UNIX/Linux OS!
* in normal operation, the kernel process itself
has several processes running,
and there will be a process for each user logged
into the system,
and each user can have multiple processes running
* ps - process status command - lets you find out
the status of current processes
* the ps command options DO seem to vary
based on one's shell...!
* ps x - will list all of the processes you
are the "owner" of
* kernel manages all the processes
switching back and forth as needed between them
* a process can create other processes --
creator process is called the PARENT process,
the created process is called the CHILD process
* certain system processes called DAEMONS reside
in the system more-or-less permanently,
and perform ongoing tasks like handling e-mail,
handling print jobs, scheduling tasks that
occur at regular intervals, etc.
* job control facilities let you switch back and forth
between your own processes
* BSD started this, POSIX standarized it;
* job: a collection of one or more processes
* in a logged-in-shell process,
it is in one of two states:
* waiting for you to enter a command
* executing a command
* if a logged-in-shell-process is executing
a command, the processes making up that
command constitute the FOREGROUND job
so there is either ONE foreground job, or none
* BUT -- any number of jobs can be running in
the background OR stopped/suspended
* a background job is a job that is running
but is not the foreground job
* a stopped job is in a state of suspense --
it remains dormant until you take action
to resume it
* you can view the current status of your jobs
with the jobs command
* those numbers on the left in square brackets
are the job numbers
* the + to right of one of those job numbers
indicates the so-called "current job",
the one that was stopped MOST recently
* you can START a job running in the background
by ending it with a &
emacs blah.txt &
* when you start a job in the background like this,
the shell displays its job number and its
PROCESS ID, abbreviated as PID in ps command
output
* you can bring the so-called current job back
into the foreground with the fg command:
fg
...and if you fg an argument that is % and a number,
you can specify to bring *that* job to the
foreground rather than the current job
fg %2
* when a job terminates or changes status in some
way, the shell notifies you of the change JUST
before it issues the next command prompt
* to kill a job or process,
the polite first attempt:
kill desired-process-id
kill %desired-job-num
the more-last-resort possibly-messy attempt:
kill -9 desired-process-id
kill -9 %desired-job-num
* some special job identifiers:
%desired-job-num Job number desired-job-num
%desired-str A unique job whose name begins
with desired-str
%?desired-str the unique job whose string contains
the string desired-string
%+ the current job
%- the previous job (one put into
background second-most-recently)
* hey! the % notation by itself can bring
that job to foreground without being
the argument to an fg command...!