Unix for Busy People - Logins, Jobs and Process

From Public wiki of Kevin P. Inscoe
Revision as of 01:18, 26 March 2021 by Ah2l671Liu8Hah$K2eit (talk | contribs) (Created page with "==Processes== Every process is assigned a unique value, termed a process identifier (PID). Each child process also has the value of it's parent process referred to as the Par...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Processes

Every process is assigned a unique value, termed a process identifier (PID). Each child process also has the value of it's parent process referred to as the Parent Process Identifier or PID.

Login and jobs

When you log in via terminal, display or network you will be provided a login environment, a shell and a home directory. The login environment consists of what is referred to as a job and consists of a single process. Each job is parent to one or more processes. In the job is stored environment variables used by the shell. Each unix process has its own private set of environment variables. When additional processes are created (refer to as forking) the environment variables of the parent processes are inherited by the child process but can then me modified by the child process if desired.

You can list the environment variables with the command env.

$ env
TERM=vt100
SHELL=/bin/bash
SSH_CLIENT=10.88.75.29 2394 22
SSH_TTY=/dev/pts/2
USER=kinscoe
SSH_AUTH_SOCK=/tmp/ssh-XXkcaWMF/agent.16182
MAIL=/var/mail/kinscoe
PATH=/usr/local/bin:/usr/bin
PWD=/export/home/kinscoe
LANG=en_US.UTF-8
TZ=US/Eastern
SHLVL=1
HOME=/export/home/kinscoe
LOGNAME=kinscoe
SSH_CONNECTION=10.88.75.29 2394 10.88.68.199 22
DISPLAY=localhost:10.0
XAUTHORITY=/tmp/ssh-xauth-jcaWMF/xauthfile

The most common environment variables that are created for you when you log in are:

PWD is the current working directory (same sa the output from the pwd command)

PATH lists directories the shell searches, for the commands the user may type without having to provide the full path. This is very similar to the DOS PATH command.

HOME indicate where a user's home directory is located in the file system.

TERM specifies the type of computer terminal or terminal emulator being used (e.g., vt100 or dumb).

PS1 specifies how the prompt is displayed in the Bourne, bash and ksh shells.

MAIL used to indicate where a user's mail is to be found.

SHELL is the current shell you are using.

LANG is the current setting of the locale for this process (see http://en.wikipedia.org/wiki/Locale for more information on Unix Locales).

Getting and setting environment variables

The variables can be used both in scripts and on the command line. They are usually referenced by putting special symbols in front of or around the variable name. For instance, to display the program search path, in most scripting environments, the user has to type:

echo $PATH

On DOS or Windows system, the user has to type this:

echo %PATH%

The env, set, and printenv commands display all environment variables and their values. env and set are also used to set environment variables and are often incorporated directly into the shell. printenv can also be used to print a single variable by giving that variable name as the sole argument to the command.

In Unix, the following commands can also be used, but are often dependent on a certain shell.

export VARIABLE=value  # for Bourne, bash, and related shells
setenv VARIABLE value  # for csh and related shells