CPS 356 & 444/544 Lecture notes: Signals

Coverage: [UPE] Chapters 1 (pp. 33-35), 3 (p. 73), 5 (pp. 150-152), and [USP] Chapters 3 (pp. 84-85), 8 (pp. 255-260), and 11 (pp. 398-401)

Shell job control

  • a shell has job control if it provides support for moving processes from the foreground to the background and vice versa
  • concurrent execution
    • commands which allow control over multiple processes which are executing concurrently
    • foreground: the current process which is attached to the user's terminal
    • background: processes executing without being attached to a terminal (batch commands)
      • daemons are background processes which run indefinitely (e.g., pageout, telnetd, sshd, httpd, printer); why is it called a `daemon'?
    • command &: any shell command can be followed by an & (before the newline) to run the command in the background; also gives it job number
        $ ls &
        [1] 1329
        $ xclock -update 1&
        [2] 1331
        $ firefox &
        [3] 1334
  • jobs: command which lists the current jobs

      [1]  + Stopped             spell termpaper
      [2]  - Running             find /usr -name main.exe -print &

    • + denotes current job; default for fg and bg
    • - denotes previous job

  • management
    • $ <ctrl-c>: kills current foreground process
    • $ fg %<number>: moves a running or stopped background job to the foreground
    • $ <ctrl-z>: suspends the current job and moves it to the background in the stopped state in one stroke
    • $ bg %<number>: resumes execution of a stopped job in the background.
    • combo of <ctrl-z> bg makes a foreground job a running background job
    • $ ps: lists the running processes

      12360 p0 S      0:01 -ksh (ksh)
      12372 p0 I      0:00 main
      12425 p0 R      0:00 ps -x

      • ps -u FA_14_CPS356_03
      • ps -e # standard syntax
      • ps aux # BSD syntax

    • $ kill -l: list all signals
    • $ kill -STOP %<number>: suspends a running background job
    • $ kill %<number>: terminates the process with the corresponding job number
    • $ kill [-signum] <PID>: terminates the process with the corresponding process id; can pass kill a signal #
      • -15 (default)
      • -2 (intr; same as <ctrl-c>)
      • -9 (sure kill; process cannot inoculate itself against this signal)
      • -3 (quit; same as <ctrl-\>)
  • originally no job control in Bourne shell
  • graphical depiction:


  • ssh -X ...
  • xterm
  • rxvt -ls
  • window managers
    • motif (lesstif)
    • open windows
    • next step
  • cut and paste through clicking the middle mouse button

X server

take away:
  • a server is both hardware and software; in order words, there must be a process to respond to a request (i.e., the software is a necessary component)
  • a computer can function as both a client and sever at the same time, in different contexts, of course
  • the two primary interprocess communication methods are I/O (e.g., pipes, sockets), if the processes share a common ancestor, and signals, if they do not share a common ancestor

More job control

  • nice
  • nohup (assumes nice)
  • at, batch, atq, atrm: queue, examine or delete jobs for later execution
    $ at 5:00pm
    echo "Time to go home!"
    $ at now + 2 minutes
    echo "Move on to next topic."
  • crontab, cron: maintain crontab files for individual users
    $ crontab -e
    $ crontab -l


    [UPE] B.W. Kernighan and R. Pike. The UNIX Programming Environment. Prentice Hall, Upper Saddle River, NJ, Second edition, 1984.
    [USP] K.A. Robbins and S. Robbins. UNIX Systems Programming: Concurrency, Communication, and Threads. Prentice Hall, Upper Saddle River, NJ, Second edition, 2003.

Return Home