Lesson 8: UNIX Processes

  1. Objectives
  2. Definition of a Process
    A process is a program that has been loaded into RAM and either is executing instructions or waiting to be executed.
     
  3. The Life Cycle of a Process

  4. Information kept on a Process
    PID
    Process Identification number - a unique number identifying a process
    PPID
    Parent PID -- the PID of the parent process ( like .. in the file hierarchy)
    UID
    The user running the process
    TTY
    The terminal that the process’ stdout and stderr is attached to
    S
    The status of the process: S = sleeping, R – running T – stopped, Z – defunct
    PRI
    Process priority
    SZ
    Process size
    CMD
    The name of the process (what command was run)
    ... plus lots more:       ps -l
     
  5. Job Control - a feature of the bash shell
    Foreground processes
    processes that receive their input from and write their output to the terminal. The parent shell waits on these processes to die.
    Background processes
    processes that do not get input from a user keyboard. The parent shell does not wait on these processes; it re-prompts the user.
    ^z
    Suspends (Stops) the process running in foreground
    bg
    Starts the currently suspended process running in background
    fg
    Brings the most recent background process to the foreground
    jobs
    Lists all processes running in the background.

  6. Signals
    signals are asynchronous messages sent to processes. They can result in one of three courses of action:
    1. be ignored,
    2. default action (die)
    3. execute some predefined function.
    # Name Purpose
    1 SIGHUP Hangup signal is sent to a shell’s children when the shell is exited. This would guarantee the phone line would be hung up when a user would disconnect from a remote login via modem.
    2 SIGINT Interrupt signal is sent to the foreground process when the user types a preconfigured key, usually ^c
    3 SIGQUIT The quit signal is sent to the foreground process causing a core dump when the user types a preconfigured key, usually ^\
    9 SIGKILL this signal cannot be caught or ignored by any process. It results in the death of the process receiving it.
    15 SIGTERM terminate signals are sent to any process when it it is time for that process to be terminated e.g. when the system shuts down.
    Signals are sent using the kill command:
    $ kill -# PID
    where # is the signal number and PID is the process id.
    (if no number is specified, SIGTERM is sent.)
     
  7. Process Load Balancing
    So that the multiprocessing CPU on a UNIX system does not get overloaded, some processes need to be run during low peak hours such as early in the morning or later in the day. The at command is for this purpose. The at command reads its stdin for a list of commands to run, and begins running them at the time of day specified as the first argument:
          $ at 10:30pm < batch_file