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
||Concepts / Commands
|Linux Commands||Brauer Instructional Videos:|
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.
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.
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.
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).
ln myfile.txt myfile1.hard.lnk
ln myfile.txt myfile2.hard.lnk
ln myfile.txt ~/backups/myfile.hard.lnk
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").
ln -s otherfile.txt otherfile1.sym.lnk
ln -s otherfile.txt otherfile2.sym.lnk
ln -s otherfile.txt ~/backups/otherfile.sym.lnk
All programs that are executing on a Unix/Linux computer 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
- Programs / Commands can be run in the background by placing an ampersand & after the command (eg. program-name &)
UNIX processes are hierarchical:
- The process structure has a root, parents, and children
- Creation of a new process is called forking or spawning
- 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)
Users can learn to manage processes to become more productive while working in the Unix / Linux Command-line environment.
Below are common Linux commands / keyboard shortcuts to manage processes:
|Linux Command / Key Combination||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. The fg command issued without arguments will place the most recent process in the background to the foreground. Example: fg %job-number|
|<ctrl><c>||Terminates a process running in the foreground|
|<ctrl><z>||Sends a process running in the foreground into the background.|
|bg||The bg utility shall resume suspended jobs from the current environment. The bg command issued without arguments will run the most recent process that was placed into the background.|
Example: bg %job-number
|jobs||The jobs utility shall display the status of jobs that were started in the current shell environment|
+ Stopped vim a <-- Job #1 (+ means most recent process placed into background)
 Running sleep 200 & <-- Job #2
 Running sleep 300 & <-- Job #3
- Running sleep 400 &
|kill</td>||The kill command 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.
kill PID , kill -9 PID , kill %job-number ,
kill -9 %job-number</td></tr></table>
INVESTIGATION 1: LINKING FILES
In the next investigation, you will ...
INVESTIGATION 2: MANAGING PROCESSES
In this section, you will learn how to ...
Perform the Following Steps:
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:
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).