Changes

Jump to: navigation, search

Tutorial 8 - Links / Process Management

8,433 bytes added, 21:17, 25 October 2021
INVESTIGATION 2: MANAGING PROCESSES
= INVESTIGATION 2: MANAGING PROCESSES =
In this investigation, you will learn how to '''manage processes''' on a Unix / Linux server.
 
 
'''Perform the Following Steps:'''
 
# Make certain that you are logged into your Matrix account.<br><br>
# Issue a Linux command to confirm that you are located in your '''home''' directory.<br><br>The '''sleep''' command '''pauses for a specified number of seconds''' before returning to the shell prompt.<br>In this tutorial, we will be using this command to '''simulate''' the management of "long-running" processes.<br><br>
# Issue the following Linux command: <span style="color:blue;font-family:courier;font-weight:bold">sleep 700</span><br><br>Notice that this process will run for '''700 seconds''', and is forcing the user to '''wait''' until this process finishes.<br>A process that is '''running in the terminal''' is referred to as a '''foreground processes'''.<br><br>The Unix/Linux system is designed to allow users to send '''preemptive signals''' to manage those processes.<br><br>
# Press the following '''key combination''' to '''terminate''' the command running on the terminal: <span style="color:blue;font-family:courier;font-weight:bold">ctrl-c</span><br><br>You should notice that the process that was running in the foreground has been '''interrupted''' (i.e. terminated).<br>'''NOTE:''' The '''ctrl-c''' key combination sends '''SIGINT''' ('''Signal Interrupt''' - which is signal '''#2''')<br>to ''terminate'' a process that is running on the terminal (i.e. a '''foreground''' process).<br><br>
# Reissue the Linux command: <span style="color:blue;font-family:courier;font-weight:bold">sleep 700</span><br><br>
# Press the '''key combination''': <span style="color:blue;font-family:courier;font-weight:bold">ctrl-z</span><br><br>[[Image:process-jobs1.png|thumb|right|300px|Running a command in the terminal, pressing '''ctrl-z''' to place into the background, and issuing the '''jobs''' command to view processes in the background.]]
# You should now see output similar to what is displayed below:<br><span style="font-family:courier;font-weight:bold">[1]+ Stopped sleep 700</span><br><br>'''NOTE:''' This indicates that this process has been placed into the '''background'''.<br>This is useful in order to "'''free-up'''" the terminal to run other Linux commands.<br><br>
# Issue the following Linux command: <span style="color:blue;font-family:courier;font-weight:bold">jobs</span><br><br>You should see the following output similar that was displayed above:<br><span style="font-family:courier;font-weight:bold">[1]+ Stopped sleep 700</span><br><br>This display indicates that this process (that is now in the background) has '''stopped'''.<br>In other words, the ''sleep'' command is NOT counting-down to zero to terminate.<br><br>'''NOTE:''' You need to use the '''bg''' command to '''run''' that process that was sent into the '''background'''.<br><br>[[Image:process-jobs2.png|thumb|right|300px|Using the '''bg''' command to '''run recent process''' that was placed into background from using '''ctrl-z''' keys.]]
# Issue the following Linux command: <span style="color:blue;font-family:courier;font-weight:bold">bg</span><br><br>'''NOTE:''' You can use the bg command WITHOUT arguments to run recent in the background. From the '''jobs''' command, the process that has a plus sign "+" indicates the most recent process placed into the background.<br><br>
# Issue the following Linux command: <span style="color:blue;font-family:courier;font-weight:bold">jobs</span><br><br>You should see the following output similar that was displayed above:<br><span style="font-family:courier;font-weight:bold">[1]+ sleep 700 &</span><br><br>This display indicates that this process in the background is '''running in the background'''<br>(indicated by the ampersand character "'''&'''"). Now this command has resume pausing until '''700 seconds'''.<br><br>[[Image:process-jobs3.png|thumb|right|300px|Using the '''ampersand''' character '''&''' to run a '''series of processes''' in the background.]]
# Issue the following Linux command: <span style="color:blue;font-family:courier;font-weight:bold">fg</span><br><br>You should notice that the ''sleep'' command is now running in the '''foreground'''.<br><br>
# Press the '''key combination''' to '''terminate''' the process running in the '''foreground''':<br><span style="color:blue;font-family:courier;font-weight:bold">ctrl-c</span> <br><br>You can issue Linux commands with ampersand "'''&'''" in your terminal to '''run''' processes automatically in the '''background''' <u>without</u> having to issue ''ctrl-z'' and ''bg'' short-cut keys.<br><br>
# Issue the following Linux commands:<br><span style="color:blue;font-family:courier;font-weight:bold">sleep 500 & sleep 600 & sleep 700 &</span><br><br>
# Issue the '''jobs''' command. What do you notice?<br><br>In the jobs command output, jobs that display a plus sign ('''+''') indicates the '''most recent''' process<br>placed in to the background, and a minus sign ('''-''') indicates the '''second most recent''' process<br>placed into the background.<br><br>The '''kill''' command issued to terminate processes that are running in the '''foreground''' or '''background'''.<br>Issuing the kill command <u>without</u> options would send the '''SIGTERM''' signal (eg. ''signal terminate'' - which is signal '''#15''').<br><br>[[Image:process-jobs4.png|thumb|right|300px|Using the '''kill %1''' command to '''terminate''' job #1.]]
# Issue the following Linux command to '''terminate''' the '''first''' job running in the background:<br><span style="color:blue;font-family:courier;font-weight:bold">kill %1</span><br><br>'''NOTE:''' You can specify job number preceded by percent % with the<br>'''kill''', '''bg''', and '''fg''' commands to specify the processes' job number.<br><br>
# Issue the '''jobs''' command. What do you notice?<br><br>
# Issue the following Linux commands:<br><span style="color:blue;font-family:courier;font-weight:bold">kill %2</span><br><span style="color:blue;font-family:courier;font-weight:bold">kill %3</span><br><br>
# Issue the '''jobs''' command (you may have to issue the ''jobs'' command several times to get final result).<br> What do you notice?<br><br>[[Image:process-jobs5.png|thumb|right|300px|Using round brackets to '''group''' a series of commands to be run as '''one process'''.]]
# Let's use '''grouping''' to run several commands in sequence within a single process.<br><br>
# Issue the following Linux command:<br><span style="color:blue;font-family:courier;font-weight:bold">(sleep 400; sleep 500; sleep 600) &</span><br><br>
# Issue the '''jobs''' command. What do you notice?<br>You should notice all commands are run in a group as just one process.<br><br>
# Issue the following Linux command to terminate the first job running in the '''background''':<br><span style="color:blue;font-family:courier;font-weight:bold">kill %1</span><br><br>NOTE: If issuing the kill command does not work, then you would need to send a STRONGER signal<br>to "'''kill'''" (not "''SIGTERM'' - which is signal ''#15''") the process. The '''SIGKILL''' signal (signal '''#9''')<br>would be required to do this by issuing the '''kill''' command with the option: '''-9'''.<br><br>
# Issue the '''jobs''' command and make certain there are no processes that are running in the '''background'''.<br><br>You can also manipulate processes by their '''PID''' ('''process ID'''). Let's terminate our Matrix Bash shell process<br>by using the '''kill''' command using that processes' '''PID'''.<br><br>
# Issue the following Linux command: <span style="color:blue;font-family:courier;font-weight:bold">ps</span><br><br>
#Note in the '''ps''' command output the PID of the process called '''bash'''.<br><br>You will be using that PID when issuing the <u>next</u> Linux command.<br><br>
# Issue the following Linux command (using the bash processes' PID number instead of "PID"):<br><span style="color:blue;font-family:courier;font-weight:bold">kill PID</span><br><br>What did you notice?<br><br>'''FYI:''' If the command did NOT work, issue the following Linux command (using the bash processes' PID number instead of "PID"):<br><span style="color:blue;font-family:courier;font-weight:bold">kill -9 PID</span><br><br>
 
:In the next investigation, you will learn how to '''create aliases''' and '''view command history''' on your Matrix server.<br><br>
= INVESTIGATION 3: ALIASES / COMMAND HISTORY =
= LINUX PRACTICE QUESTIONS =

Navigation menu