Open main menu

CDOT Wiki β

Tutorial 8 - Links / Process Management

Content under development

LINKING FILES / MANAGING PROCESSES

Main Objectives of this Practice Tutorial

  • Define the term i-node as it relates to the Unix/Linux File System
  • Issue the ls -i command to view i-node (index) numbers associated with Unix/Linux files
  • Define the terms Hard and Symbolic Links
  • Issue the ln command to create hard and symbolic links
  • Define term process as it relates to the Unix/ Linux operating system
  • Run and terminate processes in the foreground and background
  • Display and manipulate background and foreground processes
  • Use alias and history commands in Unix/Linux

Tutorial Reference Material

Course Notes
Concepts / Commands
Course Notes:


Links

Managing Processes

Linux Commands


KEY CONCEPTS

i-node (index) ID Number of a File

 
The i-node number is like a finger-print, and is considered to be unique for each file on the Unix / Linux file system.

An i-node is a database containing information (e.g. file type, owner, permissions, etc.) for all files that are created on the Unix/Linux filesystem.

The i-node number is like a finger-print, and is considered to be 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 i-node number for each file. You can see that each file (whether it is a directory or regular file) has its own unique
i-node number.

Hard Links

 
A Hard link is a file which is created that shares the same i-node number with the original file
(Image licensed under cc)
Image manipulated by author

A Hard link is a reference to the physical data on a file system.
It does this by creating a file that shares the same i-node number with the original file.


Advantages: If only one hard link remains (even if original file has been removed), the data in that hard linked file is NOT lost. The data in hard linked files are automatically updated when original file are updated.

Disadvantages: Hard links take-up extra space, you cannot hard link directories,
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:

ln myfile.txt myfile1.hard.lnk
ln myfile.txt ~/backups/myfile.hard.lnk

Symbolic Links

 
Symbolic Link is an indirect pointer to a file and are also known as soft link or symlink. The symbolic link file contains the pathname to the original file. (Image licensed under cc)

Symbolic Link is an indirect pointer to a file and are also known as soft link or symlink. The symbolic link file contains the pathname to the original file.


Advantages: symbolic links 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: Symbolic links are NOT good for backup purposes
since a symbolic link can point to a nonexistent file (referred to as a "broken link").


Examples:

ln -s otherfile.txt otherfile1.sym.lnk
ln -s otherfile.txt ~/backups/otherfile.sym.lnk


Managing Processes

All commands/programs (tasks) that are running on a Unix/Linux computer system are referred to as processes.

Characteristics of Processes:

  • Each process has an owner
  • Each process has a unique ID (PID)
  • Processes keep their PID for their entire life.
  • Usually a parent sleeps (suspends) when a child is running (the exception is when the child process is running in the background)
  • UNIX / Linux processes are hierarchical. The process structure can have child processes, great grandchild processes, etc.


Users can manage processes to become more productive while working in the Unix / Linux Command-line environment.
Processes that run in the terminal are known as foreground processes. You can run or send processes currently running
in the foreground to the background to free-up your terminal (e.g. issue other Linux commands).

Below are a listing of common Linux commands and keyboard shortcuts to manage foreground and background processes:

Linux Command /
Key Combination
Purpose
psDisplays snapshot information about processes.
Examples: ps , ps -l , ps -ef , ps -u , ps aux
topThe top command provides a realtime status of running processes.
NOTE: You can press ctrl-c to exit
ctrl-cTerminates a process running in the foreground
ctrl-zSends a process running in the foreground into the background.
fgMoves a background job from the current environment into the foreground.
Example: fg %job-number
bgRuns (starts) the most recent process that was placed into the background.
Example: bg %job-number
jobsThe jobs utility displays the status of jobs that were started in the current shell environment. Example:
jobs
[1]+ Stopped vim a   <-- Job #1 (+ most recent process / background)
[2]  Running sleep 200 &  <-- Job #2
[3]  Running sleep 300 &  <-- Job #3
[4]- Running sleep 400 &  <-- Job #4 (- second recent process / background)

killThe 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.
Examples:
kill PID , kill -9 PID , kill %job-number ,
kill -9 %job-number

Aliases / Command History


Aliases:

An alias is a nickname to an existing command or group of commands.

An alias existing in system memory and will be lost when your current Linux session ends,
unless the alias is set in a start-up file (e.g. ~/.bashrc. You will learn about using start-up files later in this course.

Examples:

alias (Alias command without an argument will display all the aliases currently set)

alias dir=ls
alias ls='ls -al'
alias clearfile='cat /dev/null >'

unalias alias-name (removes alias from memory)


Command History:

The filename ~/.bash_history stores recently executed command lines

Examples of commands that use command history:

up arrow or down arrow move to previous command or next command within Bash shell prompt
fc -l display last 16 commands
history | moredisplay all stored commands
!numre-execute an issued command number by command number (determined from history command)
!xxxre-run a most recent previously-issued command beginning with string "xxx"


INVESTIGATION 1: LINKING FILES

INVESTIGATION 2: MANAGING PROCESSES

INVESTIGATION 3: ALIASES / COMMAND HISTORY

LINUX PRACTICE QUESTIONS