Sunteți pe pagina 1din 32


Introduction to Linux & C-Programming Language

Contents of Unit-1
1. 1 Brief History of C 1.2 Program Development Life Cycle 1. 3 Getting Started with Linux

1.4 Linux File System

1.5 Basic Linux Commands
3/4/2012 2

History of C
C is structured, machine independent language ALGOL: -- introduced in 1960. -- root of all modern languages -- gave the concept of structured programming BCPL: Dennis Ritchie -- introduced in 1967. -- Basic combined programming language. -- used for writing system software.
3/4/2012 3

introduced in 1970. used to create early versions of UNIX operating system both BCPL & B could deal with only specific problems C evolved from ALGOL, BCPL & B by Denis Ritchie at Bell laboratories in 1972 Today C is running under a variety of operating systems and hardware platforms.



C as a programming language
The basic characteristics of C are: Simple language loose typing (lots of freedom, error prone) structured (extensive use of functions) designed for systems programming close to the hardware. C as middle level language. can implement very efficient programs in a compact manner Case sensetive



Its ubiquitous (present anywhere) c is powerful and fast Low level functions yet provide high level language features Portable Modular Pointers and no type checking Very stable language (derivatives like c++, c#, Java) Favorite quote: c is its own virus.
3/4/2012 7

What c lacks
Automatic garbage collection Classes or objects with behavior Overloading and operator overloading Native support for multithreading and networking


Program Development life cycle

Problem definition Program Design Program Coding Program compilation and Execution Program testing and Debugging Program Documentation


Problem definition
What must the program do? What outputs are required and in what form? What inputs are available and in what form? The complete set of requirements and assumptions constitute the problem definition.

Program Design
Involves devising an algorithm Divide and conquer Top down approach used Each successive subdivision is referred to as a stepwise refinement

Program Coding
Program coding is the process of expressing the algorithm developed for solving a problem as a computer program in a programming language Use of structured programming improves understandability Use of combination of only three control structures: sequential, selective, and repetitive

Program compilation and Execution

Two steps: compilation and linking. The compilation step converts your source program into an intermediate form, called object code The linking step combines this object code with other code to produce an executable program

Program testing and Debugging

There are four levels of debugging desk checking compile-time errors run-time, or execution-time, errors Logical errors

Program Documentation
Refers to information about the program that specifies what is being done and how. It includes detailed --requirements of program -- layout of all output reports and input data -- top down decomposition -- algorithm for each component --input data used for testing --output of the test run.

Getting started with Linux



What is Linux?
Linux is an operating system Provides the interface between hardware (processor, peripherals, etc.), applications and the user
3/4/2012 17

History of Linux
Linux is an operating system that evolved from a kernel created by Linus Torvalds when he was a student at the University of Helsinki. Linus Torvalds decided to create his own operating system that would take into account users' comments and suggestions for improvements.
3/4/2012 18

Common Linux Features

Multiuser Multitasking Hardware support Networking connectivity Network servers Graphical user Interface Application support


Why Linux ?

Security Offloading job to a remote server Software availability Flexibility Performance Powerful command line
3/4/2012 20

Components of a Linux System



Components of a Linux System (Cont.)

Like most UNIX implementations, Linux is composed of three main bodies of code; the most important distinction between the kernel and all other components The kernel is responsible for maintaining the important abstractions of the operating system Kernel code executes in kernel mode with full access to all the physical resources of the computer All kernel code and data structures are kept in the same single address space



Components of a Linux System (Cont.)

The system libraries define a standard set of functions through which applications interact with the kernel, and which implement much of the operating-system functionality that does not need the full privileges of kernel code The system utilities perform individual specialized management tasks
3/4/2012 23

File System
File System is developed for
create/store/load/delete/seek file on media Media example
Magnetic Media
Tape Floppy disk Hard disk

Optical Media
Cdrom Dvd



File System in Linux

File System in Linux is divided into 2 type
Linux Swap
is used in virtual memory system

Linux File System

is used to store file there is various type of file system
ext2 ( is first introduced in kernel 2.0.x ) reiserfs ( is first introduced in kernel 2.2.x ) ext3 ( is first introduced in kernel 2.4.x )



Different between Linux and Windows File System

File System Reference Root of each partition point

NTFS, FAT Each partition will be own root Ex. C:, D:, F:

ext2,ext3 Each partitions is mounted under /



Linux File System Layout



- first of mount point in linux /etc - keep linux default configuration /boot - keep important linux booting files /dev - keep all device files /usr - keep all user binary and X library /home - keep user home directory /proc - is pseudo file system for tracking running process and state of linux system /var - keeping mail, log file and printer spooling /lib - contain shared library that is required by system program /tmp - contain system temporary file

Linux file system is organized as a hierarchy of directories




etc/ home/







personal/ memos/



File Types in linux

File Types

Ordinary Files

Directory Files

Special Files

Character Device Files

Block Device Files

Hard Links

Symbolic Links



Basic Commands
$ pwd

$ cd usr/bin $ cd .. $ cd or cd ~ =>takes to home dir $ cd ~/btech $ cd ../mbatech => to switchover betnween 2 dirs $ mkdir sbpatil $ rmdir sbpatil $ ls $ ls /home/sbpatil


$ ls -l

1. 2. 3. 4. 5. 6. 7.

Detailed list
-rw-rw-r 1 sbpatil sbpatil 134 aug 27 11:45 btechcomputer D=directory, l / s=symbolic link File type, access permissions No. of links File owner Group owner (gp name) File size (in bytes) Day and time of last modification Name of file -a=includes hidden files -F=file type / dir, * exe -R=recursive listing-subdirs -r= reverse order -s=sort by file size
Exa. => $ ls -l a or $ ls -la



$ cat file1 $ cat file1 file2 $ cp file1 file2 $ cp -r dir1 dir2 => recursively dir -all files $ rm file1 file2 $ rm r dir1 $ mv file1 file2 or dir1 dir2 => rename -i prompts before overwrite or remove $ more file1 $ less file1

$ cat c* $ cat c*.* $ ls *.c $ ls *.? $ cat a[123] => a1 a2 a3