1 CHAPTER – 1 Linux Operating System An operating system is software that manages computer hardware and software resources and provides common services for computer programs. The operating system is an essential component of the system software in a computer system. Application programs usually require an operating system to function. Time-sharing operating systems schedule tasks for efficient use of the system and may also include accounting software for cost allocation of processor time, mass storage, printing, and other resources. For hardware functions such as input and output and memory allocation, the operating system acts as an intermediary between programs and the computer hardware, although the application code is usually executed directly by the hardware and will frequently make a system call to an OS function or be interrupted by it. Operating systems can be found on almost any device that contains a computer— from cellular phones and video game consoles to supercomputers and web servers. Examples of popular modern operating systems include Android, BSD, iOS, Linux, OS X, QNX, Microsoft Windows, Windows Phone, and IBM z/OS. All these examples, except Windows, Windows Phone and z/OS, share roots in UNIX. Types of OS Real-time: A real-time operating system is a multitasking operating system that aims at executing real-time applications. Real-time operating systems often use specialized scheduling algorithms so that they can achieve a deterministic nature of behavior. The main objective of real-time operating systems is their quick and predictable response to events. They have an event-driven or time-sharing design and often aspects of both. An event-driven system switches between tasks based on their priorities or external events while time-sharing operating systems switch tasks based on clock interrupts. Time-sharing operating systems schedule tasks for efficient use of the system and may also include accounting software for cost allocation of processor time, mass storage, printing, and other resources. Multi-user: A multi-user operating system allows multiple users to access a computer system at the same time. Time-sharing systems and Internet servers can be classified as multi-user systems as they enable multiple-user access to a computer through the sharing of time. Single-user operating systems have only one user but may allow multiple programs to run at the same time. Multi-tasking vs. single-tasking : A multi-tasking operating system allows more than one program to be running at the same time, from the point of view of human time scales. A single-tasking system has only one running program. Multi-tasking can be of two types: pre-emptive and co-operative. In
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
1
CHAPTER – 1
Linux
Operating System
An operating system is software that manages computer hardware and software resources and provides
common services for computer programs. The operating system is an essential component of the system
software in a computer system. Application programs usually require an operating system to function.
Time-sharing operating systems schedule tasks for efficient use of the system and may also include
accounting software for cost allocation of processor time, mass storage, printing, and other resources.
For hardware functions such as input and output and memory allocation, the operating system acts as an
intermediary between programs and the computer hardware, although the application code is usually
executed directly by the hardware and will frequently make a system call to an OS function or be
interrupted by it. Operating systems can be found on almost any device that contains a computer—
from cellular phones and video game consoles to supercomputers and web servers.
Examples of popular modern operating systems include Android, BSD, iOS, Linux, OS
X, QNX, Microsoft Windows, Windows Phone, and IBM z/OS. All these examples, except Windows,
Windows Phone and z/OS, share roots in UNIX.
Types of OS
Real-time: A real-time operating system is a multitasking operating system that aims at executing
real-time applications. Real-time operating systems often use specialized scheduling algorithms so
that they can achieve a deterministic nature of behavior. The main objective of real-time operating
systems is their quick and predictable response to events. They have an event-driven or time-sharing
design and often aspects of both. An event-driven system switches between tasks based on their
priorities or external events while time-sharing operating systems switch tasks based on clock
interrupts. Time-sharing operating systems schedule tasks for efficient use of the system and may
also include accounting software for cost allocation of processor time, mass storage, printing, and
other resources.
Multi-user: A multi-user operating system allows multiple users to access a computer system at the
same time. Time-sharing systems and Internet servers can be classified as multi-user systems as they
enable multiple-user access to a computer through the sharing of time. Single-user operating systems
have only one user but may allow multiple programs to run at the same time.
Multi-tasking vs. single-tasking : A multi-tasking operating system allows more than one program
to be running at the same time, from the point of view of human time scales. A single-tasking system
has only one running program. Multi-tasking can be of two types: pre-emptive and co-operative. In
2
pre-emptive multitasking, the operating system slices the CPU time and dedicates one slot to each of
the programs. Unix-like operating systems such as Solaris and Linux support pre-emptive
multitasking, as does AmigaOS. Cooperative multitasking is achieved by relying on each process to
give time to the other processes in a defined manner. 16-bit versions of Microsoft Windows used
cooperative multi-tasking. 32-bit versions of both Windows NT and Win9x, used pre-emptive multi-
tasking. Mac OS prior to OS X used to support cooperative multitasking.
Distributed: A distributed operating system manages a group of independent computers and makes
them appear to be a single computer. The development of networked computers that could be linked
and communicate with each other gave rise to distributed computing. Distributed computations are
carried out on more than one machine. When computers in a group work in cooperation, they make a
distributed system.
Template: In an o/s, distributed and cloud computing context, templating refers to creating a single
virtual machine image as a guest operating system, then saving it as a tool for multiple running
virtual machines (Gagne, 2012, p. 716). The technique is used both in virtualization and cloud
computing management, and is common in large server warehouses.
Embedded: Embedded operating systems are designed to be used in embedded computer systems.
They are designed to operate on small machines like PDAs with less autonomy. They are able to
operate with a limited number of resources. They are very compact and extremely efficient by
design. Windows CE and Minix 3 are some examples of embedded operating systems.
History of OS
Early computers were built to perform a series of single tasks, like a calculator. Basic operating system
features were developed in the 1950s, such as resident monitor functions that could automatically run
different programs in succession to speed up processing. Operating systems did not exist in their modern
and more complex forms until the early 1960s. Hardware features were added, that enabled use
of runtime libraries, interrupts, and parallel processing. When personal computers became popular in the
1980s, operating systems were made for them similar in concept to those used on larger computers.
In the 1940s, the earliest electronic digital systems had no operating systems. Electronic systems of this
time were programmed on rows of mechanical switches or by jumper wires on plug boards. These were
special-purpose systems that, for example, generated ballistics tables for the military or controlled the
printing of payroll checks from data on punched paper cards. After programmable general purpose
computers were invented, machine languages (consisting of strings of the binary digits 0 and 1 on
punched paper tape) were introduced that sped up the programming process (Stern, 1981).
OS/360 was used on most IBM mainframe computers beginning in 1966, including computers utilized
by the Apollo program.
3
In the early 1950s, a computer could execute only one program at a time. Each user had sole use of the
computer for a limited period of time and would arrive at a scheduled time with program and data on
punched paper cards and/or punched tape. The program would be loaded into the machine, and the
machine would be set to work until the program completed or crashed. Programs could generally be
debugged via a front panel using toggle switches and panel lights. It is said that Alan Turing was a
master of this on the early Manchester Mark 1 machine, and he was already deriving the primitive
conception of an operating system from the principles of the Universal Turing machine.
Later machines came with libraries of programs, which would be linked to a user's program to assist in
operations such as input and output and generating computer code from human-readable symbolic code.
This was the genesis of the modern-day operating system. However, machines still ran a single job at a
time. At Cambridge University in England the job queue was at one time a washing line from which
tapes were hung with different colored clothes-pegs to indicate job-priority.
Linux vs. Windows
What is it?
Linux is an example of Open Source
software development and Free
Operating System (OS).
Windows is the family of operating
system (OS) from Microsoft, which is the
most famous OS in the world.
Cost
Linux can be freely distributed,
downloaded freely, distributed through
magazines, Books etc. There are priced
versions for Linux also, but they are
normally cheaper than Windows.
For desktop or home use, Windows can be
expensive. A single copy can cost around
$50 to $ 450 depending on the version of
Windows.
User
Everyone. From home users to
developers and computer enthusiasts
alike.
Everyone. From home users to developers
and computer enthusiasts alike.
Manufacturer
Linux kernel is developed by the
community. Linus Torvalds oversees
things.
Microsoft created the Windows operating
system, but allows other computer
manufactures to distribute their own
computers with Windows pre-installed.
Usage
Linux can be installed on a wide variety
of computer hardware, ranging from
mobile phones, tablet computers
and video game consoles, to mainframes
On PC's desktops, laptops, servers and
some phones.
4
and supercomputers.
Development
and
Distribution
Linux is developed by Open Source
development i.e. through sharing and
collaboration of code and features
through forums etc. and it is distributed
by various vendors.
Windows is developed and distributed by
Microsoft.
GUI
Linux typically provides two GUIs, KDE
and Gnome. But there are millions of
alternatives such as LXDE, Xfce, Unity,
Mate, twm, etc.
The Windows GUI is an integral
component of the OS and is not
replaceable. This can be a con when it
comes to Windows 8's Metro.
File system
support
Ext2, Ext3, Ext4, Jfs, ReiserFS, Xfs,
Btrfs, FAT, FAT32, NTFS
FAT, FAT32, NTFS, exFAT
Text mode
interface
BASH (Bourne Again SHell) is the
Linux default shell. It can support
multiple command interpreters.
Windows uses a command shell and each
version of Windows has a single
command interpreter with dos-like
commands, recently there is the addition
of the optional PowerShell that uses more
Unix-like commands.
Price Free but support is available for a price. $50-$450
Security
Linux has had about 60-100 viruses
listed till date. None of them actively
spreading nowadays.
According to Dr. Nic Peeling and Dr.
Julian Satchell's “Analysis of the Impact
of Open Source Software” there have been
more than 60,000 viruses in Windows.
Anti-Virus cost about $20 to $400
Threat
detection and
solution
In case of Linux, threat detection and
solution is very fast, as Linux is mainly
community driven and whenever any
Linux user posts any kind of threat,
several developers start working on it
from different parts of the world
After detecting a major threat in Windows
OS, Microsoft generally releases a patch
that can fix the problem and it can take
more than 2/3 months. Sometimes sooner,
Microsoft releases patches and updates
weekly.
Processors Dozens of different kinds. Limited but most (80%)
5
Examples Ubuntu, Fedora, Red Hat, Debian,
Archlinux, Android etc.
Windows 8, 8.1, 7, Vista, XP
Gaming
Very few games available natively.
Some games can be played through
Wine, but often not all features are
available.
Almost all games are compatible with
Windows. Some CPU intensive and
graphics intensive games are exclusive to
Windows PC's.
User
experience
Although there are many GUI
applications, most of the work is done
through Terminal (a console window),
and if a problem arises GUI is rarely
usable to fix them.
Everything can be controlled through GUI
and incompatibility problems are rare.
Graphics
performance
Because hardware manufacturers, such
as NVidia, often do not provide
documentation for Linux developers,
drivers cannot use full card performance.
Combined with newest DirectX versions
and full graphics card support the
performance is almost as good as it can
get.
Company /
developer
Linus Torvalds Microsoft
Introduction
(from
Wikipedia)
Linux is a Unix-like and POSIX-
compliant computer operating system
assembled under the model of free and
open source software development and
distribution. The defining component of
Linux is the Linux kernel, an operating
system kernel first released
Microsoft Windows is a series of
graphical interface operating systems
developed, marketed, and sold by
Microsoft. Microsoft introduced an
operating environment named Windows
on November 20, 1985 as a graphical
operating system shell for MS-DOS.
Available
language(s)
Multilingual Multilingual
License GNU/Free Proprietary
Supported
platforms
All PowerPC: versions 1.0 - NT 4.0; DEC
Alpha: versions 1.0 - NT 4.0; MIPS
R4000: versions 1.0 - NT 4.0; IA-32:
versions 1.0 - 8; IA-64: version XP; x86-
6
64: versions XP - 8; ARM: version RT;
Default user
interface
Gnome or KDE (Depends on distro) Graphical (Windows Aero)
Preceded by Basic Terminal (CLI) MS-DOS
Source model Open Source Closed / Shared source
Update method Many Windows Update
OS Layers
Base Hardware: Computer hardware is the collection of physical elements that constitutes
a computer system. Computer hardware refers to the physical parts or components of a computer
such as the monitor, mouse, keyboard, computer data storage, hard drive disk (HDD), system unit
(graphic cards, sound cards, memory, motherboard and chips), etc. all of which are physical objects
that can be touched. In contrast, software is instructions that can be stored and run by hardware.
Software is any set of machine-readable instructions that directs a computer's processor to perform
specific operations. A combination of hardware and software forms a usable computing system.
7
Device Driver: In computing, a device driver (commonly referred to as simply a driver) is
a computer program that operates or controls a particular type of device that is attached to a
computer. A driver provides a software interface to hardware devices, enabling operating systems
and other computer programs to access hardware functions without needing to know precise details
of the hardware being used. A driver typically communicates with the device through the computer
bus or communications subsystem to which the hardware connects. When a calling program invokes
a routine in the driver, the driver issues commands to the device. Once the device sends data back to
the driver, the driver may invoke routines in the original calling program. Drivers are hardware-
dependent and operating-system-specific. They usually provide the interrupt handling required for
any necessary asynchronous time-dependent hardware interface.
Shell: In computing, a shell is a user interface for access to an operating system's services. In
general, operating system shells use either a command-line interface (CLI) or graphical user
interface (GUI), depending on a computer's role and particular operation. The design of a shell is
guided by cognitive ergonomics and the goal is to achieve the best workflow possible for the
intended tasks; the design can be constricted by the available computing power (for example, of
the GPU) or the available amount of graphics memory. The design of a shell is also dictated by the
employed computer periphery, such as computer keyboard, pointing device (a mouse with one
button, or one with five buttons, or a 3D mouse) or touchscreen, which is the direct human–machine
interface. CLI shells allow some operations to be performed faster, for example rearranging large
blocks of data. However, they require the user to memorize all commands and their calling syntax,
and also to learn the shell-specific scripting language, for example bash script. CLIs are also easier to
be operated via refreshable braille display and provide certain advantages to screen readers.
Graphical shells have a low burden to start using a computer, and they are characterized as being
simple and easy to use. With the widespread adoption of programs with GUIs, the use of graphical
shells has gained greater adoption. Since graphical shells come with certain disadvantages (for
example, lack of support for easy automation of operation sequences), most GUI-enabled operating
systems also provide additional CLI shells.
Compilers: A compiler is a programming tool, a computer program (or set of programs), that
transforms source code written in a programming language (the source language) into another
computer language (the target language, often having a binary form known as object code). The most
common reason for wanting to transform source code is to create an executable program. The name
"compiler" is primarily used for programs that translate source code from a high-level programming
language to a lower level language (e.g., assembly language or machine code). If the compiled
program can run on a computer whose CPU or operating system is different from the one on which
the compiler runs, the compiler is known as a cross-compiler. More generally, compilers are a
specific type of translators. A program that translates from a low level language to a higher level one
8
is a decompiler. A program that translates between high-level languages is usually called a source-
to-source compiler or transpiler. A language rewriter is usually a program that translates the form of
expressions without a change of language. The term compiler-compiler is sometimes used to refer to
a parser generator, a tool often used to help create the laxer and parser. A compiler is likely to
perform many or all of the following operations: lexical analysis, preprocessing, parsing, semantic
analysis (Syntax-directed translation), code generation, and code optimization. Program faults
caused by incorrect compiler behavior can be very difficult to track down and work around;
therefore, compiler implementers invest significant effort to ensure compiler correctness.
Command Interpreter: A command interpreter is the part of a computer operating system that
understands and executes commands that are entered interactively by a human being or from a
program. In some operating systems, the command interpreter is called the shell.
Daemon: In multitasking computer operating systems, a daemon is a computer program that runs as
a background process, rather than being under the direct control of an interactive user. Traditionally
daemon names end with the letter d: for example, syslog is the daemon that implements the system
logging facility and sshd is a daemon that services incoming SSH connections. In
a Unix environment, the parent process of a daemon is often, but not always, the init process. A
daemon is usually either created by a process forking a child process and then immediately exiting,
thus causing init to adopt the child process, or by the init process directly launching the daemon. In
addition, a daemon launched by forking and exiting typically must perform other operations, such as
dissociating the process from any controlling terminal (tty). Such procedures are often implemented
in various convenience routines such as daemon(3) in Unix. Systems often start daemons
at boot time and serve the function of responding to network requests, hardware activity, or other
programs by performing some task. Daemons can also configure hardware (like udevd on
some GNU/Linux systems), run scheduled tasks (like cron), and perform a variety of other tasks.
Utilities: Utility software is system software designed to help analyse, configure, optimize or
maintain a computer. Utility software usually focuses on how the computer infrastructure (including
the computer hardware, software and data storage) operates.
Applications: Application software is a set of one or more programs designed to carry out
operations for a specific application. Application software cannot run on itself but is dependent on
system software to execute. Examples of application software include MS Word, MS Excel, a
console game, a library management system, a spread sheet system etc. The term is used to
distinguish such software from another type of computer program referred to as system software,
which manages and integrates a computer's capabilities but does not directly perform tasks that
benefit the user. The system software serves the application, which in turn serves the user. Examples
of types of application software may include accounting software, media players, and office suites.
Many application programs deal principally with documents. Applications may be bundled with the
9
computer and its system software or published separately, and may be coded as
e.g. proprietary, open-source or university projects.
Linux Commands
For a person new to Linux, finding Linux functional is still not very easy even after the emergence of
user friendly Linux distribution like Ubuntu and Mint. The thing remains that there will always be some
configuration on user’s part to be done manually.
Just to start with, the first thing a user should know is the basic commands in terminal. Linux GUI runs
on Shell. When GUI is not running but Shell is running, Linux is running. If Shell is not running, nothing
is running. Commands in Linux are a means of interaction with Shell. For beginners some of the basic
computational task is to:
o View the contents of a directory: A directory may contain visible and invisible files with different
file permissions.
o Viewing blocks, HDD partition, External HDD
o Checking the integrity of Downloaded/Transferred Packages
o Converting and copying a file
o Know your machine name, OS and Kernel
o Viewing history
o Being root
o Make Directory
o Make Files
o Changing the file permission
o Own a file
o Install, Update and maintain Packages
o Uncompressing a file
o See current date, time and calendar
o Print contents of a file
o Copy and Move
o See the working directory for easy navigation
o Change the working directory, etc…
And we have described the entire above basic computational task in our First Article.
Part I – Switching From Windows to Nix or a Newbie to Linux – 20 Useful Commands for
Linux Newbies
This was the first article of this series. We tried to provide you with detailed description of these
commands with explicit examples which was highly appreciated by our reader in terms of likes,
comments and traffic.
10
What after these initial commands? Obviously we moved to the next part of this article where we
provided commands for computational tasks like:
o Finding a file in a given directory
o Searching a file with the given keywords
o Finding online documentation
o See the current running processes
o Kill a running process
o See the location of installed Binaries
o Starting, Ending, Restarting a service
o Making and removing of aliases
o View the disk and space usages
o Removing a file and/or directory
o Print/echo a custom output on standard output
o Changing password of on-self and others, if you are root.
o View Printing queue
o Compare two files
o Download a file, the Linux way (wget)
o Mount a block / partition / external HDD
o Compile and Run a code written in ‘C’, ‘C++’ and ‘Java’ Programming Language
This Second Article was again highly appreciated by the readers of Tecmint.com. The article was nicely
elaborated with suitable examples and output.
Part II – 20 Advanced Commands for Middle Level Linux Users
After providing the users with the glimpse of Commands used by a Middle Level User we thought to
give our effort in a nice write-up for a list of command used by an user of System Administrator Level.
In our Third and last article of this series, we tried to cover the commands that would be required for the
computational task like:
o Configuring Network Interface
o Viewing custom Network Related information
o Getting information about Internet Server with customizable switches and Results
o Digging DNS
o Knowing Your System uptime
o Sending an occasional Information to all other logged-in users
o Send text messages directly to a user
o Combination of commands
11
o Renaming a file
o Seeing the processes of a CPU
o Creating newly formatted ext4 partition
o Text File editors like vi, emacs and nano
o Copying a large file/folder with progress bar
o Keeping track of free and available memory
o Backup a mysql database
o Make difficult to guess – random password
o Merge two text files
o List of all the opened files
Part III – 20 Advanced Commands for Linux Experts
Writing this article and the list of command that needs to go with the article was a little cumbersome. We
chose 20 commands with each article and hence gave a lot of thought for which command should be
included and which should be excluded from the particular post. I personally selected the commands on
the basis of their usability (as I use and get used to) from a user point of view and an Administrator point
of view.
This Articles aims to concatenate all the articles of its series and provide you with all the functionality in
commands you can perform in our this very series of articles.
There are too long lists of commands available in Linux. But we provided the list of 60 commands which
is generally and most commonly used and a user having knowledge of these 60 commands as a whole
can work in terminal very much smoothly.
Command Description
adduser Add a new user
arch Print machine architecture
awk Find and Replace text within file(s)
bc An arbitrary precision calculator language
cal Display a calendar
Cat Concatenate files and print on the standard output
Chdir Change working directory
Chgrp Change the group ownership of files
chkconfig Tool for maintaining the /etc/rc[0-6].d directory hierarchy
chmod Change the access permissions of files and directories
12
Chown Change the user and group ownership of files
Chroot Change root directory
Cksum Print CRC checksum and byte counts
Clear Clear terminal screen
Cmp Compare two files
Comm Compare two sorted files line by line
Cp Copy one or more files to another location
Cron Daemon to execute scheduled commands
crontab Schedule a command to run at a later time
Csplit Split a file into context-determined pieces
Cut Divide a file into several parts
Date Display or change the date & time
Dc Desk Calculator
Dd Data Dump - Convert and copy a file
Df Display free disk space
Diff Display the differences between two files
diff3 Show differences among three files
Dir Briefly list directory contents
dircolors Colour setup for ls'
dirname Convert a full pathname to just a path
Du Estimate file space usage
Echo Display message on screen
Ed A line-oriented text editor (edlin)
Egrep Search file(s) for lines that match an extended expression
Eject Eject CD-ROM
Env Display, set, or remove environment variables
Expand Convert tabs to spaces
Expr Evaluate expressions
13
Factor Print prime factors
False Do nothing, unsuccessfully
fdformat Low-level format a floppy disk
Fdisk Partition table manipulator for Linux
Fgrep Search file(s) for lines that match a fixed string
Find Search for files that meet a desired criteria
Fmt Reformat paragraph text
Fold Wrap text to fit a specified width
Format Format disks or tapes
Free Display memory usage
Fsck Filesystem consistency check and repair
Gawk Find and Replace text within file(s)
Grep Search file(s) for lines that match a given pattern
Groups Print group names a user is in
Gzip Compress or decompress named file(s)
Head Output the first part of file(s)
hostname Print or set system name
Id Print user and group id's
Info Help info
Install Copy files and set attributes
Join Join lines on a common field
Kill Stop a process from running
Less Display output one screen at a time
Ln Make links between files
Locate Find files
logname Print current login name
Lpc Line printer control program
Lpr Off line print
14
Lprm Remove jobs from the print queue
Ls List information about file(s)
Man Help manual
Mkdir Create new folder(s)
mkfifo Make FIFOs (named pipes)
mknod Make block or character special files
more Display output one screen at a time
mount Mount a file system
mv Move or rename files or directories
nice Set the priority of a command or job
Nl Number lines and write files
nohup Run a command immune to hangups
passwd Modify a user password
paste Merge lines of files
pathchk Check file name portability
pr Convert text files for printing
printcap Printer capability database
printenv Print environment variables
printf Format and print data
ps Process status
Pwd Print Working Directory
quota Display disk usage and limits
quotacheck Scan a file system for disk usage
quotactl Set disk quotas
Ram ram disk device
Rcp Copy files between two machines
Rm Remove files
rmdir Remove folder(s)
15
Rpm Remote Package Manager
rsync Remote file copy (Synchronize file trees)
screen Terminal window manager
Sdiff Merge two files interactively
Sed Stream Editor
select Accept keyboard input
Seq Print numeric sequences
shutdown Shutdown or restart linux
sleep Delay for a specified time
Sort Sort text files
Split Split a file into fixed-size pieces
Su Substitute user identity
Sum Print a checksum for a file
symlink Make a new name for a file
Sync Synchronize data on disk with memory
Tac Concatenate and write files in reverse
Tail Output the last part of files
Tar Tape Archiver
Tee Redirect output to multiple files
Test Evaluate a conditional expression
Time Measure Program Resource Use
touch Change file timestamps
Top List processes running on the system
traceroute Trace Route to Host
Tr Translate, squeeze, and/or delete characters
True Do nothing, successfully
Tsort Topological sort
Tty Print filename of terminal on stdin
16
umount Unmount a device
uname Print system information
unexpand Convert spaces to tabs
Uniq Uniquify files
Units Convert units from one scale to another
unshar Unpack shell archive scripts
useradd Create new user account
usermod Modify user account
users List users currently logged in
uuencode Encode a binary file
uudecode Decode a file created by uuencode
Vdir Verbosely list directory contents ( ls -l -b')
watch Execute/display a program periodically
Wc Print byte, word, and line counts
whereis Report all known instances of a command
Which Locate a program file in the user's path
Who Print all usernames currently logged in
Whoami Print the current user id and name ( id -un')
prints the value of x, preceded by the file and line number to the error stream, allowing quick access to
which line the message was produced on. Note that the WHERESTRargument is concatenated with the
string following it. The values of __FILE__ and __LINE__ can be manipulated with the #line directive.
The #line directive determines the line number and the file name of the line below. E.g.:
#line 314 "pi.c"
puts("line=" #__LINE__ " file=" __FILE__);
generates the puts function:
55
puts("line=314 file=pi.c");
Source code debuggers refer also to the source position defined with __FILE__ and __LINE__. This
allows source code debugging, when C is used as target language of a compiler, for a totally different
language. The first C Standard specified that the macro __STDC__ be defined to 1 if the implementation
conforms to the ISO Standard and 0 otherwise, and the macro __STDC_VERSION__ defined as a
numeric literal specifying the version of the Standard supported by the implementation. Standard C++
compilers support the __cplusplus macro. Compilers running in non-standard mode must not set these
macros, or must define others to signal the differences.
Other Standard macros include __DATE__, the current date, and __TIME__, the current time.
The second edition of the C Standard, C99, added support for __func__, which contains the name of the
function definition within which it is contained, but because the preprocessor is agnostic to the grammar
of C, this must be done in the compiler itself using a variable local to the function.
Macros that can take a varying number of arguments (variadic macros) are not allowed in C89, but were
introduced by a number of compilers and standardized in C99. Variadic macros are particularly useful
when writing wrappers to functions taking a variable number of parameters, such as printf, for example
when logging warnings and errors.
One little-known usage pattern of the C preprocessor is known as X-Macros. An X-Macro is a header
file. Commonly these use the extension ".def" instead of the traditional ".h". This file contains a list of
similar macro calls, which can be referred to as "component macros". The include file is then referenced
repeatedly.
Many compilers define additional, non-standard, macros, although these are often poorly documented. A
common reference for these macros is the Pre-defined C/C++ Compiler Macros project, which lists
"various pre-defined compiler macros that can be used to identify standards, compilers, operating
systems, hardware architectures, and even basic run-time libraries at compile-time".
Microcontroller
A microcontroller (sometimes abbreviated µC, uC or MCU) is a small computer on a single integrated
circuit containing a processor core, memory, and programmable input/output peripherals. Program
memory in the form of NOR flash or OTP ROM is also often included on chip, as well as a typically
small amount of RAM. Microcontrollers are designed for embedded applications, in contrast to the
microprocessors used in personal computers or other general purpose applications.
Microcontrollers are used in automatically controlled products and devices, such as automobile engine
control systems, implantable medical devices, remote controls, office machines, appliances, power tools,
toys and other embedded systems. By reducing the size and cost compared to a design that uses a
separate microprocessor, memory, and input/output devices, microcontrollers make it economical to
56
digitally control even more devices and processes. Mixed signal microcontrollers are common,
integrating analog components needed to control non-digital electronic systems.
Some microcontrollers may use four-bit words and operate at clock rate frequencies as low as 4 kHz, for
low power consumption (single-digit milliwatts or microwatts). They will generally have the ability to
retain functionality while waiting for an event such as a button press or other interrupt; power
consumption while sleeping (CPU clock and most peripherals off) may be just nanowatts, making many
of them well suited for long lasting battery applications. Other microcontrollers may serve performance-
critical roles, where they may need to act more like a digital signal processor (DSP), with higher clock
speeds and power consumption.
Embedded design
A microcontroller can be considered a self-contained system with a processor, memory and peripherals
and can be used as an embedded system. The majority of microcontrollers in use today are embedded in
other machinery, such as automobiles, telephones, appliances, and peripherals for computer systems.
While some embedded systems are very sophisticated, many have minimal requirements for memory and
program length, with no operating system, and low software complexity. Typical input and output
devices include switches, relays, solenoids, LEDs, small or custom LCD displays, radio frequency
devices, and sensors for data such as temperature, humidity, light level etc. Embedded systems usually
have no keyboard, screen, disks, printers, or other recognizable I/O devices of a personal computer, and
may lack human interaction devices of any kind.
Interrupts:
Microcontrollers must provide real time (predictable, though not necessarily fast) response to events in
the embedded system they are controlling. When certain events occur, an interrupt system can signal the
processor to suspend processing the current instruction sequence and to begin an interrupt service
routine (ISR, or "interrupt handler"). The ISR will perform any processing required based on the source
of the interrupt, before returning to the original instruction sequence. Possible interrupt sources are
device dependent, and often include events such as an internal timer overflow, completing an analog to
digital conversion, a logic level change on an input such as from a button being pressed, and data
received on a communication link. Where power consumption is important as in battery operated
devices, interrupts may also wake a microcontroller from a low power sleep state where the processor is
halted until required to do something by a peripheral event.
Programs:
Typically microcontroller programs must fit in the available on-chip program memory, since it would be
costly to provide a system with external, expandable, memory. Compilers and assemblers are used to
57
convert high-level language and assembler language codes into a compact machine code for storage in
the microcontroller's memory. Depending on the device, the program memory may be permanent, read-
only memory that can only be programmed at the factory, or program memory that may be field-alterable
flash or erasable read-only memory.
Manufacturers have often produced special versions of their microcontrollers in order to help the
hardware and software development of the target system. Originally these included EPROM versions
that have a "window" on the top of the device through which program memory can be erased
by ultraviolet light, ready for reprogramming after a programming ("burn") and test cycle. Since 1998,
EPROM versions are rare and have been replaced by EEPROM and flash, which are easier to use (can be
erased electronically) and cheaper to manufacture.
Other versions may be available where the ROM is accessed as an external device rather than as internal
memory, however these are becoming increasingly rare due to the widespread availability of cheap
microcontroller programmers.
The use of field-programmable devices on a microcontroller may allow field update of the firmware or
permit late factory revisions to products that have been assembled but not yet shipped. Programmable
memory also reduces the lead time required for deployment of a new product.
Where hundreds of thousands of identical devices are required, using parts programmed at the time of
manufacture can be an economical option. These "mask programmed" parts have the program laid down
in the same way as the logic of the chip, at the same time.
A customizable microcontroller incorporates a block of digital logic that can be personalized in order to
provide additional processing capability, peripherals and interfaces that are adapted to the requirements
of the application. For example, the AT91CAP from Atmel has a block of logic that can be customized
during manufacture according to user requirements.
Other microcontroller features:
Microcontrollers usually contain from several to dozens of general purpose input/output pins (GPIO).
GPIO pins are software configurable to either an input or an output state. When GPIO pins are
configured to an input state, they are often used to read sensors or external signals. Configured to the
output state, GPIO pins can drive external devices such as LEDs or motors.
Many embedded systems need to read sensors that produce analog signals. This is the purpose of
the analog-to-digital converter (ADC). Since processors are built to interpret and process digital data, i.e.
1s and 0s, they are not able to do anything with the analog signals that may be sent to it by a device. So
the analog to digital converter is used to convert the incoming data into a form that the processor can
recognize. A less common feature on some microcontrollers is a digital-to-analog converter (DAC) that
allows the processor to output analog signals or voltage levels.
58
In addition to the converters, many embedded microprocessors include a variety of timers as well. One
of the most common types of timers is the Programmable Interval Timer(PIT). A PIT may either count
down from some value to zero, or up to the capacity of the count register, overflowing to zero. Once it
reaches zero, it sends an interrupt to the processor indicating that it has finished counting. This is useful
for devices such as thermostats, which periodically test the temperature around them to see if they need
to turn the air conditioner on, the heater on, etc.
A dedicated Pulse Width Modulation (PWM) block makes it possible for the CPU to control power
converters, resistive loads, motors, etc., without using lots of CPU resources in tight timer loops.
Universal Asynchronous Receiver/Transmitter (UART) block makes it possible to receive and transmit
data over a serial line with very little load on the CPU. Dedicated on-chip hardware also often includes
capabilities to communicate with other devices (chips) in digital formats such as I²C and Serial
Peripheral Interface (SPI).
CHAPTER – 4
Communication And Network Concepts Network:-Network is an interconnected collection of autonomous computer. Two computers
are said to be interconnected if they are capable to exchanging information. Autonomous means
that no computer on network can start, stop, or control another.
Network
Need for Networking:-
59
(a) Resource sharing (b) Reliability(c) Cost factor (d) Communication medium (e) Access to Remote Database Evolution of Networking:- Evolution of networking started way back in 1969 by the development of first network called
APRANET, which led to the development of Internet. (i) ARPANET:- The acronym of ARPANET is Advanced Research Projects NETwork, was started to
connect computers at U.S. Department of Defense and Universities. In 1980s, National Science Foundation started to make a high capacity network called NSFnet to be
used strictly for academic and engineering research.
In 1990s the internetworking of ARPANET, NSFnet and other private networks resulted into Internet. (ii)The Internet:-The Internet is a super-network which connects the worldwide smaller networks
together and allows all the computers to exchange the information. Internet uses TCP/IP protocols
(Transmission control Protocol/ Internet Protocol) for communication. (iii)The Interspace: - Interspace is a client/server software program that allows multiple users to
communicate online with real-time audio, video and text chat in dynamic 3-D environments.
Switching Techniques There are a number of ways to perform switching:
Circuit Switching
Packet Switching
Message Switching
Cell Switching Circuit Switching- This method involves the physical interconnection of two devices. A good example of circuit switching
involves the Public phone network. A data example would be the classic A/B switch!
Packet Switching-
Packet Switching techniques switch packets of data between destinations. Traditionally, this applied to
X.25 techniques, but this also applies to TCP/IP and IPX/SPX routers also. Proprietary Frame Relay
switches can switch voice signals.
Message Switching-
60
Message Switching techniques were originally used in data communications. An example would be
early "store and forward" paper tape relay systems. E-Mail delivery is another example of message
switching. In voice systems, you can find Voice Mail delivery systems on the Internet. The classic
"forward voice mail" example.
Cell Switching- Cell Switching is similar to packet switching, except that the switching does not necessarily occur on
packet boundaries. This is ideal for an integrated environment and is found within Cell-based networks,
such as ATM. Cell-switching can handle both digital voice and data signals.
Transmission media: -
It means the physical materials that are used to transmit data between computers. Communication media are categorized into two types
. 1.Guided Media(Cables)
2.Unguided Media(Waves)
Guided Media-
Twisted Pair Cable:-it consist of two identical wires wraped together in a double helix . it is of two
types
Unshielded twisted pair cable
Shielded twisted pair cable
Coaxial cable:-it consist of solid wire core .data transfer rate is high compare to twisted pair
cable.
Fiber:- it is guided medium cable .where data rate and weight all are good.
2.Unguided Media-
Broadcast
For longer distances or when cables are not practical, other transmission media come into play. We're
getting really high tech here.
It may seem odd to call microwaves, radio waves, or light a "physical" medium. All are electromagnetic
in nature. Sometimes they are treated by scientists like streams of teeny, tiny particles and other times
like waves on the beach. In their "particle" life, they do behave like a bunch of physical particles. So it's
61
not quite as odd as it first appears. (But all those electromagnetic things are plenty odd.)
Radio wave:- Any Radio setup has two parts. i) Transmitter. ii) Receiver Both transmitter & Receiver
use antennas to radiate & capture the radio signal.
Advantage: Flexible
Cheaper
Portable
Ease of communica tion
Microwave:- Microwave signals are used to transmit data without the use of cables. It is similar
to radio & television signals for long distance communication. It consists of transmitter,reciver,
Different topologies:- There are four basic types of LAN topology.
STAR
BUS
TREE
Linear Bus- A linear bus topology consists of a main run of cable with a terminator at each end (See fig. 1). All nodes
(file server, workstations, and peripherals) are connected to the linear cable. Ethernet and Local Talk
networks use a linear bus topology.
Fig. 1. Linear Bus topology
62
Advantages of a Linear Bus Topology Easy to connect a computer or peripheral to a linear bus.
Requires less cable length than a star topology.
Disadvantages of a Linear Bus Topology Entire network shuts down if there is a break in the main cable.
Terminators are required at both ends of the backbone cable.
Difficult to identify the problem if the entire network shuts down.
Not meant to be used as a stand-alone solution in a large building.
Star - A star topology is designed with each node (file server, workstations, and peripherals) connected directly
to a central network hub or concentrator (See fig. 2).Data on a star network passes through the hub or
concentrator before continuing to its destination. The hub or concentrator manages and controls all
functions of the network. It also acts as a repeater for the data flow. This configuration is common with
twisted pair cable; however, it can also be used with coaxial cable or fiber optic cable.
Fig. 2. Star topology
Advantages of a Star Topology Easy to install and wire. No disruptions to the network then connecting or removing devices.
Easy to detect faults and to remove parts.
63
Disadvantages of a Star Topology
Requires more cable length than a linear topology. If the hub or concentrator fails, nodes attached are disabled. More expensive than linear bus topologies because of the cost of the concentrators.
The protocols used with star configurations are usually Ethernet or LocalTalk. Token Ring uses a similar
topology, called the star-wired ring.
Tree- A tree topology combines characteristics of linear bus and star topologies. It consists of groups of star-
configured workstations connected to a linear bus backbone cable (See fig. 4). Tree topologies allow for
the expansion of an existing network, and enable schools to configure a network to meet their needs.
Fig. 4. Tree topology
Advantages of a Tree Topology Point-to-point wiring for individual segments. Supported by several hardware and software venders.
64
Disadvantages of a Tree Topology
Overall length of each segment is limited by the type of cabling used.
If the backbone line breaks, the entire segment goes down.
More difficult to configure and wire than other topologies.
65
CONCLUSION
This training focussed upon increasing our knowledge and interest in toward the ever
increasing world of Embedded Systems and Linux. We learnt how to manage the software
involved, had our hands on the tools used which was a great experience. These tools were
never used by us before and we were provided with the opportunity to increase our practical
skills and have our hands on the newly introduced tools to us. Thus, we believe that our
training will be beneficial for various purposes & hence our efforts will be fruitful.
66
BIBLIOGRAPHY
Internet Search
Google – www.google.co.in
Wikipedia – www.wikipedia.com
NIIT Website – www.niit.com
Engineers Garage – www.engineersgarage.com
Embedded System – www.embeddedsystems.blogspot.in
Books
Linux – Unix concepts and applications, By Sumitabha Das