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 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: