9.1 Killing Processes
This will teach you how to detect, show and eliminate processes.
Processes
Open two terminal windows to your VM, side by side, to be referred to as left and right.
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 end with an ampersand.
[greater@rhcsa ~]$ while true; do echo -n "game" >> ~/outfile; sleep 1; done &
You will get a message that looks like this [1] 14969.
Execute the following commands too:
while true; do echo -n "set" >> ~/outfile; sleep 1; done &
while true; do echo -n "match" >> ~/outfile; sleep 1; done &
In the right window, use tail to confirm that all three processes are appending to the file:
[greater@rhcsa ~]$ tail -f ~/outfile
In the left window, view jobs to see all three processes “Running”:
[greater@rhcsa ~]$ 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 &
Suspend the “game” process using signals.
[greater@rhcsa ~]$ kill -SIGSTOP %number
Confirm that the “game” process is “Stopped”.
[greater@rhcsa ~]$ jobs
In the right window, confirm that “game” output is no longer active..
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:
[greater@rhcsa ~]$ kill –SIGTERM %number
[greater@rhcsa ~]$ jobs
Resume the “game” process using signals:
[greater@rhcsa ~]$ kill –SIGCONT %number
Confirm that the “game” process is “Running”:
[greater@rhcsa ~]$ jobs
Terminate the remaining two jobs:
[greater@rhcsa ~]$ kill –SIGTERM %number
Confirm that no jobs remain and that output has stopped:
[greater@rhcsa ~]$ jobs
From the left window, terminate the right window’s tail command:
[greater@rhcsa ~]$ pkill –SIGTERM tail