RHCSA Rapid Track
Use signals to manage and stop processes.
Outcomes
Start and stop multiple shell processes.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command prepares your environment and ensures that all required resources are available.
[student@workstation ~]$ lab start processes-kill
Instructions
On the
workstationmachine, open two terminal windows side by side. In this section, these terminals are referred to as left and right. In each terminal, use thesshcommand to log in to theserveramachine as thestudentuser.[student@workstation ~]$
ssh student@servera[student@servera ~]$In the left terminal shell, create the
/home/student/bindirectory. Create theinstanceshell script in the new directory. Change the script permissions so that it is executable.Create the
/home/student/bindirectory.[student@servera ~]$
mkdir /home/student/binCreate the
instancescript file in the/home/student/bindirectory. Press the i key to enter Vim interactive mode. The file must have the following content as shown. Use the:wqcommand to save the file.[student@servera ~]$
cd /home/student/bin[student@servera bin]$vim /home/student/bin/instance#!/bin/bash while true; do echo -n "$@ " >> ~/instance_outfile sleep 5 doneNote
The
instancescript runs until the process is terminated. It appends command-line arguments to the~/instance_outfilefile once every 5 seconds.Make the
instancescript file executable.[student@servera bin]$
chmod +x /home/student/bin/instance
In the left terminal shell, change into the
/home/student/bin/directory. Start three processes with theinstancescript file, by passing thenetwork,interface, andconnectionarguments. Start the processes in the background.[student@servera bin]$
instance network &[1] 3460 [student@servera bin]$instance interface &[2] 3482 [student@servera bin]$instance connection &[3] 3516In the right terminal shell, verify that all three processes are appending content to the
/home/student/instance_outfilefile.[student@servera ~]$
tail -f ~/instance_outfilenetwork interface network connection interface network connection interface network ...output omitted...In the left terminal shell, list existing jobs.
[student@servera bin]$
jobs[1] Running instance network & [2]- Running instance interface & [3]+ Running instance connection &Use signals to suspend the
instance networkprocess. Verify that theinstance networkprocess is set toStopped. Verify that thenetworkprocess is no longer appending content to the~/instance_outputfile.Stop the
instance networkprocess. Verify that the process is stopped.[student@servera bin]$
kill -SIGSTOP %1[1]+ Stopped instance network [student@servera bin]$jobs[1]+ Stopped instance network [2] Running instance interface & [3]- Running instance connection &In the right terminal shell, view the
tailcommand output. Verify that the wordnetworkis no longer appended to the~/instance_outfilefile....output omitted... interface connection interface connection interface connection interface
In the left terminal shell, terminate the
instance interfaceprocess. Verify that theinstance interfaceprocess disappeared. Verify that theinstance interfaceprocess output is no longer appended to the~/instance_outfilefile.Terminate the
instance interfaceprocess. Verify that the process is terminated.[student@servera bin]$
kill -SIGTERM %2[student@servera bin]$jobs[1]+ Stopped instance network [2] Terminated instance interface [3]- Running instance connection &In the right terminal shell, view the
tailcommand output. Verify that the wordinterfaceis no longer appended to the~/instance_outfilefile....output omitted... connection connection connection connection connection connection connection connection
In the left terminal shell, resume the
instance networkprocess. Verify that theinstance networkprocess is set toRunning. Verify that theinstance networkprocess output is appended to the~/instance_outfilefile.Resume the
instance networkprocess. Verify that the process is in theRunningstate.[student@servera bin]$
kill -SIGCONT %1[student@servera bin]$jobs[1]+ Running instance network & [3]- Running instance connection &In the right terminal shell, view the
tailcommand output. Verify that the wordnetworkis appended to the~/instance_outfilefile....output omitted... network connection network connection network connection network connection network connection
In the left terminal shell, terminate the remaining two jobs. Verify that no jobs remain and that output is stopped.
Terminate the
instance networkprocess. Next, terminate theinstance connectionprocess.[student@servera bin]$
kill -SIGTERM %1[student@servera bin]$kill -SIGTERM %3[1]+ Terminated instance network [student@servera bin]$jobs[3]+ Terminated instance connection
In the left terminal shell, list the current running processes in all open terminal shells. Terminate the
tailprocesses. Verify that the processes are no longer running.List all current running processes. Refine the search to view only
taillines.[student@servera bin]$
ps -ef | grep tailstudent 4581 31358 0 10:02 pts/0 00:00:00 tail -f /home/student/instance_outfile student 4869 2252 0 10:33 pts/1 00:00:00 grep --color=auto tailTerminate the
tailprocess. Verify that the process is no longer running.[student@servera bin]$
pkill -SIGTERM tail[student@servera bin]$ps -ef | grep tailstudent 4874 2252 0 10:36 pts/1 00:00:00 grep --color=auto tailIn the right terminal shell, verify that the
tailcommand is no longer running....output omitted... network connection network connection network connection Terminated [student@servera ~]$
Close the extra terminal. Return to the
workstationsystem as thestudentuser.[student@servera bin]$
exitlogout Connection to servera closed. [student@workstation ~]$