2. 11-2
Text Editors
--Mostly used editors in Linux are:
• vi
• pico
• nano
About VI editor:
Visual Interface is standard text editor that is supplied with most of the Unix
distributions.
In Linux environment, the vim text editor is used as a substitute for VI.
The Vim editor (VI iMproved) is upward compatible with vi editor
3. 11-3
VI Editor
Starting vi
--The following sections describe how to start vi, type text in a file, save (write)
the file, and quit vi.
--Creating a File
Start vi and edit the file paint as shown in this example:
$ vi <file_name>
--If file name already exists, vi opens the existing file. If this is a new file, vi
creates it. For the purposes of this example, paint should be a new file.
--The vi editing screen appears in a moment:
--The cursor appears in the upper left corner of the screen. Blank lines are
indicated by a vertical series of tildes (~).
--Note that you can also start vi without specifying a file name by just typing vi.
You can then name the file later when you exit vi.
4. 11-4
VI Editor
Status Line
The last line of the screen, called the status line, shows the name of the file
and the number of lines and characters in the file. When you create a new
file, as is the case with the example, the status line indicates that it is a new
file
5. 11-5
VI Editor
Two Modes of vi editor
Two modes of operation in vi are insert mode and command mode. You
use insert mode to type text into a file, while command mode is used to
type commands that perform specific vi functions. Command mode is the
default mode for vi.
When you first open a vi file, it's always in command mode. Before you
can type text in the file, you must type one of the vi insert commands,
such as i ("insert"), to insert text at the current cursor location, or a
("append"), to insert text after the current cursor location.
Whenever you want to return vi to command mode, press Esc. If you're
not sure which mode vi is presently in, simply press Esc to make sure it's
in command mode and continue from there.
6. 11-6
VI Editor
• x - is for deleting
• u - is for Undo
• dd - is for removing of the line
• p - paste the cutting data below the
cursor line
• yy -for copying the data ( yanking)
• p - paste
• /keyword - to search for a keyword
• G - for end of the file
• :w - Save your data.
• :q - quitting.
• :wq - for Saving and quitting
• :q! - quitting without any changes
forcefully.
• h - go left ( arrow keys)
• l - go right
• j - go down
• k - go up
7. 11-7
Process Management
- A process can be simply defined as an instance of a running program.
• each process will have a unique numeric identifier associated with it, referred
to as its process identification number, or PID
• each process also has a reference to the PID of its parent, i.e. the parent
process id, or PPID
• each process will have priorities associated with it, i.e. the priority of order of
execution
-/proc = all the processes information
10. 11-10
Process Management
Zombie Process: On Unix operating systems, a zombie process or defunct
process is a process that has completed execution but still has an entry in the
process table.
• When a process ends, all of the memory and resources associated with it are
deallocated so they can be used by other processes.
• Zombies can be identified in the output from the Unix PS command by the
presence of a "Z" in the STAT column.
• To remove zombies from a system, the SIGCHLD signal can be sent to the
parent manually, using the kill command.
So how do I find out zombie process?
--Use top or ps command:
11. 11-11
Process Management
Commands:
• top
• ps aux | grep –wi z
• kill -s SIGCHLD <ppid>
• kill -9 <pid>
--Please note that kill -9 does not guarantee to kill a zombie process
--If you have zombie processes it means those zombies have not been
waited for by their parent (look at PPID displayed by ps -l)