Tutorial8: Links / Process Management
LINKING FILES / MANAGING PROCESSES
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
Tutorial Reference Material
Course Notes |
Concepts / Commands |
YouTube Videos | ||
Course Notes:
|
Links
Managing Processes
|
Linux Commands | Brauer Instructional Videos: |
KEY CONCEPTS
Linking Files
Links are powerful and add flexibility to Linux filesystems because everything is a file.
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.
Reference: https://opensource.com/article/17/6/linking-linux-filesystem
inode (index) Number of a File:
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.
Referring to the diagram on the far right, issuing the ls command with the -i option
displays the inode number for each file. You can see that each file
(whether it is a directory or regular file) has its own unique inode number.
Hard Links:
A Hard link is a reference to the physical data on a file system.
Advantages of hard links are that if one hard link remains (even if original file has been removed), the data in that hard linked file is NOT lost, a hard links will automatically change when a change to that original file or hard links occur since they share the same i-node number
and the Unix/Linux OS treats them all as the same file.
Disadvantages of hard links are that they take-up extra space,
you cannot hard link directory files, and you cannot hard link files from other Unix/Linux servers
(since the inode number may already be used by the other Unix/Linux server).
Examples:
touch myfile.txt
ln myfile.txt myfile1.hard.lnk
ln myfile.txt myfile2.hard.lnk
ln myfile.txt ~/backups/myfile.hard.lnk
Symbolic Links:
A Symbolic Link is an indirect pointer to a file and are also known as soft link or symlink.
Advantages of symbolic links are that they are shortcuts to other files, where the symbolic link only contains the pathname to the original file, you can create symbolic links
on different Unix/Linux servers, and that you can create symbolic links for directories.
Disadvantages of symbolic links are that they are NOT good for backup purposes
since a symbolic link can point to a nonexistent file (referred to as a "broken link").
Examples:
touch otherfile.txt
ln -s otherfile.txt otherfile1.sym.lnk
ln -s otherfile.txt otherfile2.sym.lnk
ln -s otherfile.txt ~/backups/otherfile.sym.lnk
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 the foreground or background.
UNIX processes are hierarchical:
- The process structure has a root, parents, and children
- Creation of a new process is called forking or spawning
- Each process has its own PID (process ID number)
- The Parent process can spawn a child and children can spawn 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)
Below are some common Linux commands involving processes:
Linux Command | Purpose |
---|---|
ps | The ps (process status) command displays snapshot information about processes. By default, the ps command displays information only about the current terminal (ps -l provides a detailed listing, ps -U username shows all) Examples: ps , ps -l, ps -ef, ps -u ps aux |
top | The top command provides a continuous update including resource usage NOTE: You can press ctrl-c to exit |
fg | The fg (foreground) command moves a background job from the current environment into the foreground. Example:fg %job-number</td></tr> |
bg</td> | the bg utility shall resume suspended jobs from the current environment. Examples:</td></tr> |
jobs</td> | The jobs utility shall display the status of jobs that were started in the current shell environment Examples:</td></tr> |
kill</td> | The command kill sends the specified signal to the specified processes or process groups. If no signal is specified, the TERM signal is sent. The default action for this signal is to terminate the process. Examples:</td></tr></table> INVESTIGATION 1: LINKING FILES
In the next investigation, you will ... INVESTIGATION 2: MANAGING PROCESSESIn this section, you will learn how to ...
Perform the Following Steps:
In the next investigation, you will ...
LINUX PRACTICE QUESTIONSThe 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).
|