13,420
edits
Changes
Created page with "=LINKING FILES / MANAGING PROCESSES= <br> ===Main Objectives of this Practice Tutorial=== :* Understand the purpose and why links are used in Unix / Linux :* Define the term..."
=LINKING FILES / MANAGING PROCESSES=
<br>
===Main Objectives of this Practice Tutorial===
:* Understand the purpose and why links are used in Unix / Linux
:* Define the term '''inode''' number as it relates to a file on Unix / Linux
:* Define the terms: '''Hard''' Link and '''Symbolic''' Link
:* Issue the '''ln''' command to create hard and symbolic links
:* Define and understand the purpose of a '''process''' in Unix / Linux
:* '''Run''' and '''terminate''' processes in the foreground and background
:* '''Display''' and '''manipulate''' background and foreground processes
<br>
===Tutorial Reference Material===
{|width="100%" cellspacing="0" cellpadding="10"
|- valign="top"
|colspan="2" style="font-size:16px;font-weight:bold;border-bottom: thin solid black;border-spacing:0px;"|Course Notes<br>
|colspan="2" style="font-size:16px;font-weight:bold;border-bottom: thin solid black;border-spacing:0px;padding-left:15px;"|Concepts / Commands<br>
|colspan="1" style="font-size:16px;font-weight:bold;border-bottom: thin solid black;border-spacing:0px;padding-left:15px;"|YouTube Videos<br>
|- valign="top" style="padding-left:15px;"
|colspan="2" |Course Notes:<ul><li>[https://ict.senecacollege.ca/~murray.saul/uli101/ULI101-Week7.pdf PDF] | [https://ict.senecacollege.ca/~murray.saul/uli101/ULI101-Week8.pptx PPTX]</li></ul>
| style="padding-left:15px;" |Links
* Hard Links
* Symbolic Links<br>
Managing Processes
* Process Information
* Manipulating Processes
* Running commands / programs in background with &
| style="padding-left:15px;"|Linux Commands
* [http://man7.org/linux/man-pages/man1/ln.1.html ln]
* [http://man7.org/linux/man-pages/man1/ps.1.html ps]
* [http://man7.org/linux/man-pages/man1/top.1.html top]
* [http://man7.org/linux/man-pages/man1/fg.1p.html fg]
* [http://man7.org/linux/man-pages/man1/bg.1p.html bg]
* [http://man7.org/linux/man-pages/man1/jobs.1p.html jobs]
* [http://man7.org/linux/man-pages/man1/kill.1.html kill]
|colspan="1" style="padding-left:15px;" width="30%"|Brauer Instructional Videos:<ul><li>[https://www.youtube.com/watch?v=tZ94-qH9unM&list=PLU1b1f-2Oe90TuYfifnWulINjMv_Wr16N&index=9 Inodes and Links]</li><li>[https://www.youtube.com/watch?v=q93POTgH-aQ&list=PLU1b1f-2Oe90TuYfifnWulINjMv_Wr16N&index=7 Processes and Jobs]</li></ul>
|}
= KEY CONCEPTS =
===Linking Files===
''Links are powerful and add flexibility to Linux filesystems because everything is a file.<br><br>There are two types of Linux filesystem links: hard and soft. The difference between the two types of links is significant, but both types are used to solve similar problems. They both provide multiple directory entries (or references) to a single file, but they do it quite differently.'' <br><br>Reference: https://opensource.com/article/17/6/linking-linux-filesystem
'''inode (index) Number of a File:'''
<table align="right"><tr valign="top"><td>[[Image:inode-number-1.png|thumb|right|300px|Each inode stores the attributes and disk block locations of the object's data.<br>(Image licensed under [https://creativecommons.org/licenses/by-sa/3.0/ cc])]]</td><td>[[Image:inode-number-2.png|thumb|right|400px|The '''inode number''' is like a '''finger-print''', and usually is '''unique''' for each file on the Unix / Linux file system.]]</td></tr></table>
''The inode (index node) is a data structure in a Unix-style file system that describes a file-system object such as a file or a directory. Each inode stores the attributes and disk block locations of the object's data. File-system object attributes may include metadata (times of last change, access, modification), as well as owner and permission data.''
Reference: https://en.wikipedia.org/wiki/Inode
The '''inode number''' is like a '''finger-print''', and usually is '''unique''' for each file on the Unix / Linux file system.<br>Referring to the diagram on the far right, issuing the '''ls''' command with the '''-i''' option<br>displays the inode number for each file. You can see that <u>each</u> file<br>(whether it is a directory or regular file) has its own unique inode number.
'''Hard Links:'''
<table align="right"><tr valign="top"><td>[[Image:hard-link-1.png|thumb|right|300px|(Image licensed under [https://creativecommons.org/licenses/by-sa/3.0/ cc])<br>Image manipulated by author]]]</td><td>[[Image:inode-number-3.png|thumb|right|400px|(Image licensed under [https://creativecommons.org/licenses/by-sa/3.0/ cc])]]</td></tr></table>
Hard link is a reference to the physical data on a file system
More than one hard link can be associated with the same physical data
Hard links can only refer to data that exists on the
same file system
Hard links cannot be created to a directory
When a file has more than one link, you can remove any one link and still be able to access the file through the remaining links
Assume you used "vi" to create a new file, you create the first hard link (vi myfile)
To Create the 2nd, 3rd , etc. hard links, use the command:
ln myfile link-name
Create a new file called “myfile”
Run the command “ls -il” to display the i- node number and link counter
'''Symbolic Links:'''
<table align="right"><tr valign="top"><td>[[Image:symbolic-link-1.png|thumb|right|300px|(Image licensed under [https://creativecommons.org/licenses/by-sa/3.0/ cc])]]</td><td>[[Image:inode-number-4.png|thumb|right|400px|(Image licensed under [https://creativecommons.org/licenses/by-sa/3.0/ cc])]]</td></tr></table>
A Symbolic Link is an indirect pointer to a file – a pointer to the hard link to the file
You can create a symbolic link to a directory
A symbolic link can point to a file on a different file system
A symbolic link can point to a nonexistent file (referred to as a "broken link")
Also known as soft links or symlinks
===Managing Processes===
All programs that are executing on a UNIX system are referred to as processes
Each process has an owner
Each process has a unique ID (PID) Processes in UNIX can run in:
Foreground
Background
[[Image:process-diagram-1.png|thumb|right|300px|(Image licensed under [https://creativecommons.org/licenses/by-sa/3.0/ cc])]]]
UNIX processes are hierarchical
This structure has a root, parents, and children
Creation of a new process is called forking or spawning
Parent can fork a child and children can fork their own children
Processes keep their PID for their entire life
Usually a parent sleeps when a child is executing
– The exception is when the child process is executing in the background
ps (process status) command displays snapshot information about processes
By default, the ps command displays information only about the current terminal (ps -U username shows all)
The top command provides a continuous update including resource usage
=INVESTIGATION 1: LINKING FILES=
<br>
In this section, you will learn how to ...
'''Perform the Following Steps:'''
# x<br><br>
In the next investigation, you will ...<br><br>
=INVESTIGATION 2: MANAGING PROCESSES =
In this section, you will learn how to ...
'''Perform the Following Steps:'''
# x<br><br>
In the next investigation, you will ...
= LINUX PRACTICE QUESTIONS =
The purpose of this section is to obtain '''extra practice''' to help with '''quizzes''', your '''midterm''', and your '''final exam'''.
Here is a link to the MS Word Document of ALL of the questions displayed below but with extra room to answer on the document to
simulate a quiz:
https://ict.senecacollege.ca/~murray.saul/uli101/uli101_week8_practice.docx
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:'''
# Write a single Linux command to create a hard link called '''~/backup/myfile.txt.lnk''' to the existing file called '''~/myfile.txt'''<br>Write a single Linux command to display detailed information for those files above displaying their i-node numbers.<br>In this case, will the inode numbers for those files above be the same or different?<br><br>
# Write a single Linux command to create a symbolic link called '''~/shortcuts/murray.saul.lnk''' to the existing directory called '''~murray.saul'''<br>Write a single Linux command to display detailed information for those files above displaying their i-node numbers.<br>In this case, will the inode numbers for those files above be the same or different?<br><br>What data is contained in the file called '''~/shortcuts/murray.saul.lnk'''?<br>What would be the size of the file called '''~/shortcuts/murray.saul.lnk'''?<br><br>
# Write a single Linux command to run the program called '''~/clean.sh''' in the background.<br>What command would you issue to place the previously issued program in the foreground?<br>What command would you issue to confirm that this program is running in the background?<br>What key-combination would you issue to send that program again into the background?<br><br>
# Write a single Linux command to display running processes in “real-time”.
# Write a single Linux command to terminal a process that has the following PID: '''22384'''
# 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] Stopped vim a<br>[2]- Stopped vim b<br>[3]+ Stopped vim c</span><br><br>Write a single Linux command to bring the second-recently process placed in the background into the foreground.<br>Write a single Linux command to terminate the '''job #3'''.<br><br>
# Create a '''table''' listing each Linux command, useful options and command purpose for the following Linux commands: '''ln''' , '''ps''' , '''top''' , '''fg''' , '''bg''' , '''jobs''' , '''kill'''
[[Category:ULI101]]
<br>
===Main Objectives of this Practice Tutorial===
:* Understand the purpose and why links are used in Unix / Linux
:* Define the term '''inode''' number as it relates to a file on Unix / Linux
:* Define the terms: '''Hard''' Link and '''Symbolic''' Link
:* Issue the '''ln''' command to create hard and symbolic links
:* Define and understand the purpose of a '''process''' in Unix / Linux
:* '''Run''' and '''terminate''' processes in the foreground and background
:* '''Display''' and '''manipulate''' background and foreground processes
<br>
===Tutorial Reference Material===
{|width="100%" cellspacing="0" cellpadding="10"
|- valign="top"
|colspan="2" style="font-size:16px;font-weight:bold;border-bottom: thin solid black;border-spacing:0px;"|Course Notes<br>
|colspan="2" style="font-size:16px;font-weight:bold;border-bottom: thin solid black;border-spacing:0px;padding-left:15px;"|Concepts / Commands<br>
|colspan="1" style="font-size:16px;font-weight:bold;border-bottom: thin solid black;border-spacing:0px;padding-left:15px;"|YouTube Videos<br>
|- valign="top" style="padding-left:15px;"
|colspan="2" |Course Notes:<ul><li>[https://ict.senecacollege.ca/~murray.saul/uli101/ULI101-Week7.pdf PDF] | [https://ict.senecacollege.ca/~murray.saul/uli101/ULI101-Week8.pptx PPTX]</li></ul>
| style="padding-left:15px;" |Links
* Hard Links
* Symbolic Links<br>
Managing Processes
* Process Information
* Manipulating Processes
* Running commands / programs in background with &
| style="padding-left:15px;"|Linux Commands
* [http://man7.org/linux/man-pages/man1/ln.1.html ln]
* [http://man7.org/linux/man-pages/man1/ps.1.html ps]
* [http://man7.org/linux/man-pages/man1/top.1.html top]
* [http://man7.org/linux/man-pages/man1/fg.1p.html fg]
* [http://man7.org/linux/man-pages/man1/bg.1p.html bg]
* [http://man7.org/linux/man-pages/man1/jobs.1p.html jobs]
* [http://man7.org/linux/man-pages/man1/kill.1.html kill]
|colspan="1" style="padding-left:15px;" width="30%"|Brauer Instructional Videos:<ul><li>[https://www.youtube.com/watch?v=tZ94-qH9unM&list=PLU1b1f-2Oe90TuYfifnWulINjMv_Wr16N&index=9 Inodes and Links]</li><li>[https://www.youtube.com/watch?v=q93POTgH-aQ&list=PLU1b1f-2Oe90TuYfifnWulINjMv_Wr16N&index=7 Processes and Jobs]</li></ul>
|}
= KEY CONCEPTS =
===Linking Files===
''Links are powerful and add flexibility to Linux filesystems because everything is a file.<br><br>There are two types of Linux filesystem links: hard and soft. The difference between the two types of links is significant, but both types are used to solve similar problems. They both provide multiple directory entries (or references) to a single file, but they do it quite differently.'' <br><br>Reference: https://opensource.com/article/17/6/linking-linux-filesystem
'''inode (index) Number of a File:'''
<table align="right"><tr valign="top"><td>[[Image:inode-number-1.png|thumb|right|300px|Each inode stores the attributes and disk block locations of the object's data.<br>(Image licensed under [https://creativecommons.org/licenses/by-sa/3.0/ cc])]]</td><td>[[Image:inode-number-2.png|thumb|right|400px|The '''inode number''' is like a '''finger-print''', and usually is '''unique''' for each file on the Unix / Linux file system.]]</td></tr></table>
''The inode (index node) is a data structure in a Unix-style file system that describes a file-system object such as a file or a directory. Each inode stores the attributes and disk block locations of the object's data. File-system object attributes may include metadata (times of last change, access, modification), as well as owner and permission data.''
Reference: https://en.wikipedia.org/wiki/Inode
The '''inode number''' is like a '''finger-print''', and usually is '''unique''' for each file on the Unix / Linux file system.<br>Referring to the diagram on the far right, issuing the '''ls''' command with the '''-i''' option<br>displays the inode number for each file. You can see that <u>each</u> file<br>(whether it is a directory or regular file) has its own unique inode number.
'''Hard Links:'''
<table align="right"><tr valign="top"><td>[[Image:hard-link-1.png|thumb|right|300px|(Image licensed under [https://creativecommons.org/licenses/by-sa/3.0/ cc])<br>Image manipulated by author]]]</td><td>[[Image:inode-number-3.png|thumb|right|400px|(Image licensed under [https://creativecommons.org/licenses/by-sa/3.0/ cc])]]</td></tr></table>
Hard link is a reference to the physical data on a file system
More than one hard link can be associated with the same physical data
Hard links can only refer to data that exists on the
same file system
Hard links cannot be created to a directory
When a file has more than one link, you can remove any one link and still be able to access the file through the remaining links
Assume you used "vi" to create a new file, you create the first hard link (vi myfile)
To Create the 2nd, 3rd , etc. hard links, use the command:
ln myfile link-name
Create a new file called “myfile”
Run the command “ls -il” to display the i- node number and link counter
'''Symbolic Links:'''
<table align="right"><tr valign="top"><td>[[Image:symbolic-link-1.png|thumb|right|300px|(Image licensed under [https://creativecommons.org/licenses/by-sa/3.0/ cc])]]</td><td>[[Image:inode-number-4.png|thumb|right|400px|(Image licensed under [https://creativecommons.org/licenses/by-sa/3.0/ cc])]]</td></tr></table>
A Symbolic Link is an indirect pointer to a file – a pointer to the hard link to the file
You can create a symbolic link to a directory
A symbolic link can point to a file on a different file system
A symbolic link can point to a nonexistent file (referred to as a "broken link")
Also known as soft links or symlinks
===Managing Processes===
All programs that are executing on a UNIX system are referred to as processes
Each process has an owner
Each process has a unique ID (PID) Processes in UNIX can run in:
Foreground
Background
[[Image:process-diagram-1.png|thumb|right|300px|(Image licensed under [https://creativecommons.org/licenses/by-sa/3.0/ cc])]]]
UNIX processes are hierarchical
This structure has a root, parents, and children
Creation of a new process is called forking or spawning
Parent can fork a child and children can fork their own children
Processes keep their PID for their entire life
Usually a parent sleeps when a child is executing
– The exception is when the child process is executing in the background
ps (process status) command displays snapshot information about processes
By default, the ps command displays information only about the current terminal (ps -U username shows all)
The top command provides a continuous update including resource usage
=INVESTIGATION 1: LINKING FILES=
<br>
In this section, you will learn how to ...
'''Perform the Following Steps:'''
# x<br><br>
In the next investigation, you will ...<br><br>
=INVESTIGATION 2: MANAGING PROCESSES =
In this section, you will learn how to ...
'''Perform the Following Steps:'''
# x<br><br>
In the next investigation, you will ...
= LINUX PRACTICE QUESTIONS =
The purpose of this section is to obtain '''extra practice''' to help with '''quizzes''', your '''midterm''', and your '''final exam'''.
Here is a link to the MS Word Document of ALL of the questions displayed below but with extra room to answer on the document to
simulate a quiz:
https://ict.senecacollege.ca/~murray.saul/uli101/uli101_week8_practice.docx
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:'''
# Write a single Linux command to create a hard link called '''~/backup/myfile.txt.lnk''' to the existing file called '''~/myfile.txt'''<br>Write a single Linux command to display detailed information for those files above displaying their i-node numbers.<br>In this case, will the inode numbers for those files above be the same or different?<br><br>
# Write a single Linux command to create a symbolic link called '''~/shortcuts/murray.saul.lnk''' to the existing directory called '''~murray.saul'''<br>Write a single Linux command to display detailed information for those files above displaying their i-node numbers.<br>In this case, will the inode numbers for those files above be the same or different?<br><br>What data is contained in the file called '''~/shortcuts/murray.saul.lnk'''?<br>What would be the size of the file called '''~/shortcuts/murray.saul.lnk'''?<br><br>
# Write a single Linux command to run the program called '''~/clean.sh''' in the background.<br>What command would you issue to place the previously issued program in the foreground?<br>What command would you issue to confirm that this program is running in the background?<br>What key-combination would you issue to send that program again into the background?<br><br>
# Write a single Linux command to display running processes in “real-time”.
# Write a single Linux command to terminal a process that has the following PID: '''22384'''
# 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] Stopped vim a<br>[2]- Stopped vim b<br>[3]+ Stopped vim c</span><br><br>Write a single Linux command to bring the second-recently process placed in the background into the foreground.<br>Write a single Linux command to terminate the '''job #3'''.<br><br>
# Create a '''table''' listing each Linux command, useful options and command purpose for the following Linux commands: '''ln''' , '''ps''' , '''top''' , '''fg''' , '''bg''' , '''jobs''' , '''kill'''
[[Category:ULI101]]