RHCSA Rapid Track
In this exercise, you will use signals to manage and stop processes.
Outcomes
You should be able to start and stop multiple shell processes.
Log in to workstation as student using student as the password.
On workstation, run the lab processes-kill start command.
The command runs a start script that determines whether the host, servera, is reachable on the network.
[student@workstation ~]$lab processes-kill start
On
workstation, open two terminal windows side by side. In this section, these terminals are referred to as left and right. In each terminal, use the ssh command to log in toserveraas thestudentuser.[student@workstation ~]$ssh student@servera...output omitted... [student@servera ~]$In the left window, create a new directory called
/home/student/bin. In the new directory, create a shell script calledkilling. Make the script executable.Use the mkdir command to create a new directory called
/home/student/bin.[student@servera ~]$mkdir /home/student/binUse the vim command to create a script called
killingin the/home/student/bindirectory. Press the i key to enter Vim interactive mode. Use the :wq command to save the file.[student@servera ~]$vim /home/student/bin/killing#!/bin/bash while true; do echo -n "$@ " >> ~/killing_outfile sleep 5 doneNote
The
killingscript runs until terminated. It appends command line arguments to the~/killing_outfileonce every 5 seconds.Use the chmod command to make the
killingfile executable.[student@servera ~]$chmod +x /home/student/bin/killing
In the left terminal shell, use the cd command to change into the
/home/student/bin/directory. Start three killing processes with the argumentsnetwork,interface, andconnection, respectively. Start three processes callednetwork,interface, andconnection. Use the ampersand (&) to start the processes in the background.[student@servera ~]$cd /home/student/bin[student@servera bin]$killing network &[1] 3460[student@servera bin]$killing interface &[2] 3482[student@servera bin]$killing connection &[3] 3516Your processes will have different PID numbers.
In the right terminal shell, use the tail command with the
-foption to confirm that all three processes are appending to the/home/student/killing_outfilefile.[student@servera ~]$tail -f ~/killing_outfilenetwork interface network connection interface network connection interface network ...output omitted...In the left terminal shell, use the jobs command to list jobs.
[student@servera bin]$jobs[1] Running killing network & [2]- Running killing interface & [3]+ Running killing connection &Use signals to suspend the
networkprocess. Confirm that thenetworkprocess isStopped. In the right terminal shell, confirm that thenetworkprocess is no longer appending output to the~/killing_output.Use the kill with the
-SIGSTOPoption to stop thenetworkprocess. Run the jobs to confirm it is stopped.[student@servera bin]$kill -SIGSTOP %1[1]+ Stopped killing network[student@servera bin]$jobs[1]+ Stopped killing network [2] Running killing interface & [3]- Running killing connection &In the right terminal shell, look at the output from the tail command. Confirm that the word
networkis no longer being appended to the~/killing_outfilefile....output omitted... interface connection interface connection interface connection interface
In the left terminal shell, terminate the
interfaceprocess using signals. Confirm that theinterfaceprocess has disappeared. In the right terminal shell, confirm thatinterfaceprocess output is no longer appended to the~/killing_outfilefile.Use the kill command with the
-SIGTERMoption to terminate theinterfaceprocess. Run the jobs command to confirm that it has been terminated.[student@servera bin]$kill -SIGTERM %2[student@servera bin]$jobs[1]+ Stopped killing network [2] Terminated killing interface [3]- Running killing connection &In the right terminal shell, look at the output from the tail command. Confirm that the word
interfaceis no longer being appended to the~/killing_outfilefile....output omitted... connection connection connection connection connection connection connection connection
In the left terminal shell, resume the
networkprocess using signals. Confirm that thenetworkprocess isRunning. In the right window, confirm thatnetworkprocess output is being appended to the~/killing_outfilefile.Use the kill command with the
-SIGCONTto resume thenetworkprocess. Run the jobs command to confirm that the process isRunning.[student@servera bin]$kill -SIGCONT %1[student@servera bin]$jobs[1]+ Running killing network & [3]- Running killing connection &In the right terminal shell, look at the output from the tail command. Confirm that the word
networkis being appended to the~/killing_outfilefile....output omitted... network connection network connection network connection network connection network connection
In the left terminal shell, terminate the remaining two jobs. Confirm that no jobs remain and that output has stopped.
Use the kill command with the
-SIGTERMoption to terminate thenetworkprocess. Use the same command to terminate theconnectionprocess.[student@servera bin]$kill -SIGTERM %1[student@servera bin]$kill -SIGTERM %3[1]+ Terminated killing network[student@servera bin]$jobs[3]+ Terminated killing connection
In the left terminal shell, list
tailprocesses running in all open terminal shells. Terminate running tail commands. Confirm that the process is no longer running.Use the ps command with the
-efoption to list all running tail processes. Refine the search using the grep command.[student@servera bin]$ps -ef | grep tailstudent 4581 31358 0 10:02 pts/0 00:00:00 tail -f killing_outfile student 4869 2252 0 10:33 pts/1 00:00:00 grep --color=auto tailUse the pkill command with the
-SIGTERMoption to kill thetailprocess. Use the ps to confirm it is no longer present.[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, confirm that the tail command is no longer running.
...output omitted... network connection network connection network connection Terminated [student@servera ~]$
Exit from both terminal windows. Failure to exit from all sessions causes the finish script to fail.
[student@servera bin]$exitlogout Connection to servera closed. [student@workstation ~]$[student@servera ~]$exitlogout Connection to servera closed. [student@workstation ~]$
This concludes the guided exercise.