Changes

Jump to: navigation, search

Tutorial8: Links / Process Management

174 bytes added, 10:53, 2 September 2020
INVESTIGATION 3: ALIASES / COMMAND HISTORY
# Use a text editor to create a file called '''~/links/data-file.txt'''<br><br>
# Enter the following text displayed below:<br><br><span style="font-family:courier;font-weight:bold;">This is line 1<br>This is line 2<br>This is line 3<br><br></span>
# Save your editing session and exit your text editor.<br><br>
# Issue the following Linux command:<br><span style="color:blue;font-weight:bold;font-family:courier;">ls -li ~/links/data-file.txt</span><br><br>View the '''i-node''' number for this file. What does this i-node number represent?<br><br>
# Issue the following Linux command to create the following hard link in the same directory: <br><span style="color:blue;font-weight:bold;font-family:courier;">ln ~/links/data-file.txt ~/links/data-file.hard.lnk<br><br>
# Use a text editor to create a file called '''~/links2/text-file.txt'''<br><br>
# Enter the following text displayed below:<br><br><span style="font-family:courier;font-weight:bold;">This is line one<br>This is line two<br>This is line three<br><br></span>
# Save your editing session and exit your text editor.<br><br>
# Issue the following Linux command to create the following symbolic link in the same directory: <br><span style="color:blue;font-weight:bold;font-family:courier;">ln -s ~/links2/text-file.txt ~/links2/text-file.sym.lnk</span><br><br>
# Issue the '''ls -li''' command for the '''~/links2''' directory.<br><br>What do you notice about both of these file's i-node numbers?<br>What do you notice about the size of the file ''~/links2/text-file.sym.lnk''?<br>What pathname do you think it represents?<br><br>
# Change to your '''home''' directory.<br><br>
# Issue the following Linux command to create the following symbolic link in your home directory: <br><span style="color:blue;font-weight:bold;font-family:courier;">ln -s ~/links2/text-file.txt ~/text-file.sym.lnk</span><br><br>
In this section, you will learn how to manage processes on a Unix / Linux server.
 
# Make certain that you are logged into your Matrix account.<br><br>
# Issue the following Linux command: <span style="color:blue;font-family:courier;font-weight:bold">sleep 700</span><br><br>'''NOTE:''' The '''sleep''' command just waits for a specified number of seconds before completing<br>in order to return returning to the shell prompt. It is useful in order to force a pause in a sequence of commands.<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 process'''.<br><br>The Unix/Linux system is designed to allow users to send '''preemptive signals''' to manage those processes.<br><br># Press the key combination: <span style="color:blue;font-family:courier;font-weight:bold">&lt;ctrl&gt;&lt;c&gt;</span><br><br>You should notice that the process that was running in the foreground has been '''interrupted ''' (i.e. terminated). '''NOTE:''' The '''ctrl-c''' key combination sends '''SIGINT''' ('''Signal Interrupt''') to terminate a process that is running.<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">&lt;ctrl&gt;&lt;z&gt;</span><br><br>
# 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 commands.<br><br>
# Clear your bash shell terminal screen.<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>
# 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 specify the most recent process<br>that was placed into the background. From the '''jobs''' command, the process that has a plus sign "+"<br>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>(denoted by the ampersand character "&"). Now the command is counting-down to zero.<br><br>
# 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>You can run commands with ampersand "'''&'''" to run processes in the background.<br><br> # Press the key combination: <span style="color:blue;font-family:courier;font-weight:bold">&lt;ctrl&gt;&lt;c&gt;</span> to stop '''terminate''' the process running in the foreground.<br><br>
# Issue the following Linux command: <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>
# 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. What do you notice?<br><br>You can also manipulate processes by their '''PID''' ('''process ID''').<br><br>
# Let's use '''grouping ''' to run several commands in sequence within a single process.<br><br>
# Issue the following Linux command: <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><br>
# Issue the following Linux command: <span style="color:blue;font-family:courier;font-weight:bold">ps</span><br><br>What is the PID of the previously issued Linux command in the background?<br><br>
# Issue the following Linux command (using the PID number instead of "PID"):<br><span style="color:blue;font-family:courier;font-weight:bold">kill PID</span><br><br>
# Issue the '''jobs''' command. Is the sleep process still running?<br><br>'''NOTE:''' You need to issue the ''kill -9 PID '' command if the previous commands did not work.<br><br>
# Issue the following Linux command (using the PID number instead of "PID"):<br><span style="color:blue;font-family:courier;font-weight:bold">kill -9 PID</span><br><br>
# Issue the '''jobs''' and '''ps''' commands to confirm there are no processes running in the background.<br><br>
:In the next investigation, you will learn how to create aliases and view command history on your Matrix server.<br><br>
<br>
=INVESTIGATION 3: ALIASES / COMMAND HISTORY=
# 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 ln</span><br><br>What happened?<br><br>
# After you complete the Review Questions sections to get additional practice, then work on your<br>'''online assignment 2 ''' and complete '''section4 ''' labelled: '''Linking files and directories'''.<br><br>
= LINUX PRACTICE QUESTIONS =
13,420
edits

Navigation menu