Open main menu

CDOT Wiki β

Changes

Tutorial 8 - Links / Process Management

16,461 bytes added, 12:15, 8 June 2023
m
Protected "Tutorial 8 - Links / Process Management": OER transfer ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite))
Content under development
 
=LINKING FILES / MANAGING PROCESSES=
===Main Objectives of this Practice Tutorial===
= INVESTIGATION 1: LINKING FILES =
<span style="color:red;">'''ATTENTION''': The due date for successfully completing this tutorial (i.e. tutorial 8) is by Friday, December 15 April 21 @ 11:59 PM (Week 14).</span><br>
In this investigation, you will learn how to create '''hard links''' and '''symbolic links''' on your Matrix account,<br>and observe the <u>advantages</u> and <u>limitations</u> of using both types of links.
= 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=
 
<br>
In this investigation, you will learn how to '''manage aliases''' and '''Linux command history''' on your Matrix account.
 '''Perform the Following Steps:''' # Make certain that you are logged into your Matrix account.<br><br>[[Image:alias-1.png|thumb|right|400px|Issuing the '''alias''' command (<u>without</u> arguments) will display a list of existing aliases on your Unix / Linux system.]]# Issue a Linux command to confirm that you are located in your '''home''' directory.<br><br># Issue the following Linux command: <span style="color:blue;font-family:courier;font-weight:bold">alias | more</span><br><br>Observe those <u>existing</u> aliases that have previously been declared. Take a few moments to run those aliases to see what happens.<br><br># Issue the following to create an alias: <span style="color:blue;font-family:courier;font-weight:bold">alias lal='ls -al'</span><br><br># Issue the following alias: <span style= INVESTIGATION "color:blue;font-family:courier;font-weight:bold">lal</span><br><br>What do you notice?<br><br># Issue the following to create another alias (lowercase l and h):<br><span style="color:blue;font-family:courier;font-weight:bold">alias lh='ls --human-readable --size -1 -S --classify'</span><br><br># Issue the following command to confirm that this newly-created alias is stored in memory:<br><br><span style="color:blue;font-family:courier;font-weight:bold">alias | grep "lh"</span><br><br># Issue the following alias: <span style="color:blue;font-family:courier;font-weight:bold">lh</span> <br><br>What do you think this command does?<br><br># '''Logout''' of your Matrix account and then '''login''' to your Matrix account.<br><br># Reissue the '''lal''' alias. What happened?<br><br># Reissue the '''lh''' alias. What happened?<br><br># Issue the '''alias | grep lh''' command without any arguments to see if it is stored in memory.<br><br># Reissue the command to create the '''lh''' alias in '''step #6'''.<br><br># Run the '''lh''' alias to confirm that it is properly set in memory.<br><br># Issue the following Linux command to edit your ~/.bashrc startup file:<br><span style="color:blue;font-family:courier;font-weight:bold">nano ~/.bashrc</span><br><br># Add the following line at the '''bottom''' of this file:<br><span style="font-family:courier;font-weight:bold;>alias lh='ls --human-readable --size -1 -S --classify'</span><br><br># Save your editing changes and exit your text editor.<br><br># '''Logout''' of your Matrix account, then '''login''' to your Matrix account.<br><br># Reissue the '''lh''' alias. What happened?<br><br># Issue the following Linux command: <span style="font-family:courier;font-weight:bold;>unalias lh</span><br><br># Run the '''lh''' alias to see what happens.<br><br>What happenned?<br><br># '''Logout''' of your Matrix account, then '''login''' to your Matrix account.<br><br># Reissue the '''lh''' alias. What happened? Why?<br><br># Reissue the '''lal''' alias. Why '''didn't''' this alias work?<br><br>The checking script below is designed to act as a '''filter''' with a '''pipeline command'''.<br>This will allow to check if your '''lh''' alias exists when it is checked in this program.<br><br># Issue the following Linux pipeline command:<br><span style="color:blue;font-weight:bold;font-family:courier;">alias | ~osl640/week8-check-3</span><br><br>If you encounter errors, then view the feedback to make corrections, and then re-run the checking script.<br>If you receive a congratulation message that there are no errors, then proceed with this tutorial.<br><br>We will complete this investigation by learning to execute p'''reviously issued commands''' by using '''command history'''.<br><br># Issue the following Linux command: <span style="color:blue;font-family:courier;font-weight:bold">history | grep "lh"</span><br><br>What do you notice?<br><br># Type an exclamation mark '''!''' followed by the number by one of those commands<br>listed in the '''history list''' and press <span style="color:blue;font-family:courier;font-weight: ALIASES bold">ENTER</ COMMAND HISTORY span><br><br>What happened?<br><br># Type the following: <span style="color:blue;font-family:courier;font-weight:bold">!unalias</span> and press <span style="color:blue;font-family:courier;font-weight:bold">ENTER</span><br><br>What happened?<br><br># Issue the following Linux command: <span style="color:blue;font-family:courier;font-weight:bold">history | grep "lh"</span><br><br>What happened?<br><br># Complete the Review Questions sections to get additional practice.<br><br>
= LINUX PRACTICE QUESTIONS =
 
The purpose of this section is to obtain '''extra practice''' to help with '''quizzes'''.
 
Here is a link to the [https://matrix.senecacollege.ca/~osl640/questions/osl640_week8_practice.docx MS Word Document of ALL of the questions] displayed below but with extra room to answer on the document to simulate a quiz:
 
Your instructor may take-up these questions during class. It is up to the student to attend classes in order to obtain the answers to the following questions. Your instructor will NOT provide these answers in any other form (eg. e-mail, etc).
 
'''Review Questions:'''
# Hard Links:<ol type="a"><li>What is the purpose of creating a hard-link?</li><li>What is a limitation of a hard link?<li>Write a single Linux command to create a hard link called '''~/backup/myfile.txt.lnk''' for the <u>existing</u> file called '''~/myfile.txt'''</li><li>Write a single Linux command to display the '''i-node''' number for both files. Are the '''i-node''' numbers identical?</li></ol><br>
# Symbolic (Soft) Links:<ol type="a"><li>What is the purpose of creating a symbolic (soft) link?</li><li>What is a limitation of a symbolic (soft) link?</li><li>Write a single Linux command to create a symbolic link called '''~/shortcuts/murray.saul.lnk'''<br>to the <u>existing</u> directory called '''~murray.saul'''</li><li>Are the i-node numbers identical for both of those files?</li><li>What data is contained in the file called '''~/shortcuts/murray.saul.lnk'''?</li></ol><br>
# Background / Foreground Processes:<ol type="a"><li>Write a single Linux command to run the program called '''~/clean.sh''' in the '''background'''.</li><li>Write a single Linux command to place the previously issued program in the '''foreground'''.</li><li>Write a single Linux command to '''confirm''' that this program is running in the background.</li><li>What '''key-combination''' would you issue to send that program again into the '''background'''?</li><li>Write a single Linux command to have that process sent into the background to '''continue running'''?</li></ol><br>
# Managing Background processes:<br><span style="text-indent:120px;">Use the following diagram to answer the accompanying questions.<br>Each of the following questions will use the diagram below and are treated as independent situations.<br><br><span style="font-family:courier;font-weight:bold;">[1]&nbsp; Stopped vim a<br>[2]- Stopped vim b<br>[3]+ Stopped vim c</span></span><ol type="a"><li>Write a single Linux command to bring the second-recently process placed in the background into the '''foreground'''.</li><li>Write a single Linux command to '''terminate job #3'''.</li></ol><br>
# Write a single Linux command to display running processes in “real-time”.
# Write a single Linux command to terminate a process that has the following PID: '''22384'''<br><br>
# Aliases / History:<ol type="a"><li>Write a linux command to create an '''alias''' called '''ld''' that issues the command: '''ls -ld'''</li><li>Write a linux command to unset the '''alias''' created in the previous question.</li><li>Issue a Linux command to list '''history''' of commands that match the pattern called '''touch'''.</li></ol><br>
# Create a '''table''' listing each Linux command, useful options and command purpose for the following Linux commands:<br>'''ln''' , '''ps''' , '''top''' , '''fg''' , '''bg''' , '''jobs''' , '''kill''' , '''alias''' , '''unalias''' , '''history'''
 
[[Category:OSL640]]