Bookmark this page

Guided Exercise: Killing Processes

In this lab, students will use keyboard sequences and signals to manage and stop processes.

Outcomes

Experience with observing the results of starting and stopping multiple shell processes.

Log in as student to serverX. Start in your home directory.

  1. Open two terminal windows, side by side, to be referred to as left and right.

  2. In the left window, start three processes that append text to an output file at one-second intervals. To properly background each process, the complete command set must be contained in parentheses and ended with an ampersand.

    [student@serverX ~]$ (while true; do echo -n "game " >> ~/outfile; sleep 1; done) &
    [student@serverX ~]$ (while true; do echo -n "set " >> ~/outfile; sleep 1; done) &
    [student@serverX ~]$ (while true; do echo -n "match " >> ~/outfile; sleep 1; done) & 
  3. In the right window, use tail to confirm that all three processes are appending to the file. In the left window, view jobs to see all three processes "Running".

    [student@serverX ~]$ tail -f ~/outfile
    [student@serverX ~]$ jobs
    [1]   Running                 ( while true; do
        echo -n "game " >> ~/outfile; sleep 1;
    done ) &
    [2]-  Running                 ( while true; do
        echo -n "set " >> ~/outfile; sleep 1;
    done ) &
    [3]+  Running                 ( while true; do
        echo -n "match " >> ~/outfile; sleep 1;
    done ) &
    
  4. Suspend the "game" process using signals. Confirm that the "game" process is "Stopped". In the right window, confirm that "game" output is no longer active.

    [student@serverX ~]$ kill -SIGSTOP %number
    [student@serverX ~]$ jobs
  5. Terminate the "set" process using signals. Confirm that the "set" process has disappeared. In the right window, confirm that "set" output is no longer active.

    [student@serverX ~]$ kill -SIGTERM %number
    [student@serverX ~]$ jobs
  6. Resume the "game" process using signals. Confirm that the "game" process is "Running". In the right window, confirm that "game" output is again active.

    [student@serverX ~]$ kill -SIGCONT %number
    [student@serverX ~]$ jobs
  7. Terminate the remaining two jobs. Confirm that no jobs remain and that output has stopped. From the left window, terminate the right window's tail command.

    Close extra terminal windows.

    [student@serverX ~]$ kill -SIGTERM %number
    [student@serverX ~]$ kill -SIGTERM %number
    [student@serverX ~]$ jobs
    [student@serverX ~]$ pkill -SIGTERM tail
    [student@serverX ~]$ 
Revision: rh124-7-1b00421