SlideShare una empresa de Scribd logo
1 de 56
Descargar para leer sin conexión
Programming in Linux
Self learning with Linux
Team Emertxe
Linux Introduction
Let us ponder…
 What exactly is an Operating System (OS)?
 Why do we need OS?
 How would the OS would look like?
 Is it possible for a team of us (in the room) to create an OS of our
own?
 Is it necessary to have an OS running in a Embedded System?
 Will the OS ever stop at all?
Operating System
System and application programs
Operating System
Computer
hardware
User 1 User 2 User 3
Compiler Assembler Text editor Database system
Humans
Program
interface
User
Programs
OS
interface
OS
Hardware
interface/
privileged
instructions
Disk/memory
What is Linux ?
 Linux is a free and open source operating system that is
causing a revolution in the computer world.
 Originally created by Linus Torvalds with the assistance
of developers called community
 This operating system in only a few short years is
beginning to dominate markets worldwide.
Why use Linux?
 Free & Open Source
 Reliability
 Secure
 Scalability
Freedom of
software
Freedom of
redistribute
Freedom of
copy
Freedom of
modify
Freedom of
use
What is Open Source?
How it all started?
 With GNU (GNU is not UNIX)
 Richard Stallman made the initial announcement in 1983, Free Software
Foundation (FSF) got formed during 1984
 Volunteer driven GNU started developing multiple projects, but making it as
an operating system was always a challenge
 During 1991 a Finnish Engineer Linus Torvalds developed core OS
functionality, called it as “Linux Kernel”
 Linux Kernel got licensed under GPL, which laid strong platform for the
success of Open Source
 Rest is history!
How it evolved?
Kernel
Applications
Customization
 Multiple Linux distributions started emerging around the Kernel
 Some applications became platform independent
 Community driven software development started picking up
 Initially seen as a “geek-phenomenon”, eventually turned out to be an
engineering marvel
 Centered around Internet
 Building a business around open source started becoming viable
 Redhat set the initial trend in the OS business
Where it stands now?
OS Databases Server/Cloud Enterprise
Consumer Education CMS eCommerce
More details
OSS Freeware
 Users have the right to access &
modify the source codes
 In case original programmer
disappeared, users & developer
group of the S/W usually keep its
support to the S/W.
 OSS usually has the strong users &
developers group that manage and
maintain the project
 Freeware is usually distributed in a
form of binary at ‘Free of Charge’,
but does not open source codes
itself.
 Developer of freeware could
abandon development at any time
and then final version will be the
last version of the freeware. No
enhancements will be made by
others.
 Possibility of changing its licensing
policy
Open Source SW vs. Freeware
GPL
 Basic rights under the GPL – access to source code,
right to make derivative works
 Reciprocity/Copy-left
 Purpose is to increase amount of publicly available
software and ensure compatibility
 Licensees have right to modify, use or distribute
software, and to access the source code
Problems with the GPL
 Linking to GPL programs
 No explicit patent grant
 Does no discuss trademark rights
 Does not discuss duration
 Silent on sub-licensing
 Relies exclusively on license law, not contract
Linux: Properties
 Multitasking
 Multi-user
 Multiprocessing
 Protected Memory
 Hierarchical File System
/
/boot/
/dev/
/bin/
/etc/
/home/
/lib/
/media/
/mnt/
/opt/
/sbin/
/tmp/
/usr/
/var/
/root/
/proc/
Directory structure
Static files for boot loader
Device files
Essential user command binaries
Host specific system configuration
User home directories
Essentilal shared libraries and kernal modules
Mount point for removable media
Mount point for temporarily mounted file systems
Add-on application software package
User specific system binaries
Temporary files
Multi-user utilities and applications
Variable file (logs)
Home directory for root user
Virtual file system documenting kernel and process status
x86 Booting
Kernel structure
 Hardware Controllers: This subsystem is comprised of all
the possible physical devices in a Linux installation
 Linux Kernel: The kernel abstracts and mediates access
to the hardware resources, including the CPU. A kernel is
the core of the operating system
 O/S Services: These are services that are typically
considered part of the operating system (e.g. shell)
 User Applications: The set of applications in use on a
particular Linux system. (e.g. web-browser)
Kernel structure
Command Line Interface
Command Line
Interface
• CLI
• Textual mode
• Executes requested command
• GUI
• Mouse, keypad
The Shell
 What is a shell?
 Different types of shells
• Login-shell
• Non-login shell
• Sh
• Bash
• Ksh
• Csh
 Hands-on:
• echo $0
• cat /etc/shells
How Shell Invokes
The main task of a shell is providing a user environment
Input (ls)
Shell
Error
List all the
files
Bash Files
 Bash
• Command interpreter
• .bash_profile (During login)
• .bashrc (New instance)
• .bash_logout (Logout)
• .bash_history (Command history)
 Hands-on:
• Enter ls -a in your home directory
• Display contents of all files mentioned above
Environment Variables
 Login-shell's responsibility is to set the non-login shell and
it will set the environment variables
 Environment variables are set for every shell and
generally at login time
 Environmental variables are set by the system.
 Environmental variables hold special values. For instance
,$ echo $SHELL
 Environmental variables are defined in /etc/profile,
/etc/profile.d/ and ~/.bash_profile.
 When a login shell exits, bash reads ~/.bash_logout
The 'bash' variables &
Friends
Name Meaning
env Lists shell environment variable/value pairs
export [var_name] Exports/sets a shell variable
HOME Path of user’s home directory
PATH Executable search path
PWD Present working directory
PS1 Command prompt
N=10 Assigning the variable. This a temporary variable
effective only inside the current shell
unset N Unset the environment variable N
Basic Shell Commands
Command Meaning
ls Lists all the files
pwd Gives present working directory
cd Change directory
man Gives information about command
exit Exits from the shell
which Shows full path of command
Shell: Built-in Commands
 Built-in commands are contained with in the shell
itself, means shell executes the command directly,
without creating a new process
 Built-in commands:
break,cd,exit,pwd,export,return,unset,alias,echo,print
f,read,logout,help,man
VIsual editor
VIsual editor
 vi or vim
 To open a file
$ vi <filename> or vim <filename>
VIsual editor…
 vi opens a file in command mode while starting
 The power of vi comes from its 3 modes
• Escape mode (Command mode)
Search mode
File mode
• Editing mode
Insert mode
Append mode
Open mode
Replace mode
• Visual mode.
Cursor Movement
 You will clearly need to move the cursor around your file.
You can move the cursor in command mode.
 vi has many different cursor movement commands. The four
basic keys appear below
 Yes! Arrow keys also do work. But these makes typing faster
Character Meaning
k Move up one line
h Move one character to the left
l Move one character to the right
j Move down one line
Basic vi commands
 How to exit
 Already looks too complicated?
 Try by yourself, let us write a C program
 Try out vimtutor. Go to shell and type vimtutor
Command Meaning
:q Quit without saving
:wq Close the file with saving
:q! Quit the file forcefully without saving
Escape mode or
Command mode
 In command mode, characters you perform actions like moving the
cursor, cutting or copying text, or searching for some particular
text
• Search mode
• vi can search the entire file for a given string of text. A
string is a sequence of characters. vi searches forward with
the slash (/) key and string to search.
• To cancel the search, press ESC .You can search again by
typing n (forward) or N (backward).
• Also, when vi reaches the end of the text, it continues
searching from the beginning. This feature is called wrap
scan. Instead of (/), you may also use question (?). That
would have direction reversed
• Now, try out. Start vi as usual and try a simple search. Type
/<string> and press n and N a few times to see where the
cursor goes.
Escape mode...
 File mode
• Changing (Replacing) Text
Command Meaning
:%s/first/sec Replaces the first by second every where in the file
%s/old/new/gc For all lines in a file, find string “old" and replace with
string “new" for each instance on a line
:e filename Open another file without closing the current
set all Display all settings of your session
:r filename Reads file named filename in place
Editing Modes...
Command Mode name Insertion point
a Append Just after the current character
A Append End of the current line
i Insert Just before the current character
I Insert Beginning of the current line
o Open New line below the current line
O Open New line above the current line
Editing Text
 Deleting Text Sometimes you will want to delete some
of the text you are editing.
 To do so, first move the cursor so that it covers the first
character of the group you want to delete, then type
the desired command from the table below.
Command Meaning
dd For deleting a line
ndd For deleting a n lines
x To delete a single character
shift + d Delete contents of line after cursor
dw Delete word
ndw Delete ‘n’ words
Some Useful
Shortcuts
Command Meaning
shift-g Go to last line in file
shift-j Joining the two lines
. Repeat the previous command executed
ctrl+a Increment number under the cursor
ctrl+x Decrements numbers under the cursor
Visual Mode
Visual Mode
Visual mode helps to visually select some text, may
be seen as a sub mode of the command mode to switch
from the command mode to the visual mode type one of
• ctrl+v Go's to visual block mode.
• Only v for visual mode
• d or y Delete or Yank selected text
• I or A Insert or Append text in all lines (visual block
only)
File related commands
File redirection
 Out put redirection ( > )
 Redirecting to append ( >> )
 Redirecting the error (2>)
eg : $ls > /tmp/outputfile
eg : $ls -l >> /tmp/outputfile
eg : $ls 2> /tmp/outputfile
Piping
 A pipe is a form of redirection that is used in Linux
operating systems to send the output of one program to
another program for further processing.
 A pipe is designated in commands by the vertical bar
character
eg: $ ls -al /bin | less
File Related
commands
 Every thing is viewed as a file in Linux. Even a
Directory is a file.
 Basic Shell Command Set
Command Meaning
df Disk free space
du Disk usage
cp <source> <dest> Copy file from one to another
mv <source> <dest> Rename a file
rm <file> Remove a file
stat File related statistics (i-node)
ln Linking between files (-s option for soft link)
Continued
Command Meaning
mkdir <dir_name> Make directory
rmdir <dir_name> Remove a particular directory
touch Change file timestamps
wc Counts the number of lines in a file
cat Display contents of the file in standard output
more Display contents, navigate forward
head Display first 10 lines of the file (-n to change)
tail Display last 10 lines of the file (-n to change)
sort Sort lines of text files
File Detailed
Listing
permissions Owner
&
group
File
size
Created time
& Date Filename
Linux file types
1st column
• -
• d
• c
• b
• l
• s
• = or p
Meaning
• Plain text
• Directory
• Character driver
• Block driver
• Link file
• Socket file
• FIFO file
File permissions
 r or 4 -r--r--r-- Read
 w or 2 --w--w--w- Write
 x or 1 ---x--x--x Execute
rwx rwx rwx
421 421 421
user group others
Changing the File Permissions
$ chmod – Change file permessions
$ chown – Change file owner
$ chmod [ ug+r, 746 ] file.txt
$ chown -R user:group [ filename | dir ]
Linux kernel: Subsystems
Subsystems
 The Process Scheduler (SCHED)
 The Memory Manager (MM)
 The Virtual File System (VFS)
 The Network Interface (NET)
 The Inter-Process Communication (IPC)
Kernel Structure
Kernel design
 Most older operating systems are
monolithic, that is, the whole operating
system is a single executable file that
runs in 'kernel mode'
 This binary contains the process
management, memory management, file
system and the rest (Ex: UNIX)
 The alternative is a microkernel-based
system, in which most of the OS runs as
separate processes, mostly outside the
kernel
 They communicate by message passing.
The kernel's job is to handle the message
passing, interrupt handling, low-level
process management, and possibly the
I/O (Ex: Mach)
System Calls
System calls
 A set of interfaces to interact with hardware devices
such as the CPU, disks, and printers.
 Advantages:
• Freeing users from studying low-level programming
• It greatly increases system security
• These interfaces make programs more portable
System call
System Call...
Logically the system call and regular interrupt follow the same flow of steps. The
source (I/O device v/s user program) is very different for both of them. Since
system call is generated by user program they are called as ‘Soft interrupts’ or
‘traps’
Stay connected
About us: Emertxe is India’s one of the top IT finishing schools & self learning kits
provider. Our primary focus is on Embedded with diversification focus on Java,
Oracle and Android areas
Emertxe Information Technologies,
No-1, 9th Cross, 5th Main,
Jayamahal Extension,
Bangalore, Karnataka 560046
T: +91 80 6562 9666
E: training@emertxe.com
https://www.facebook.com/Emertxe https://twitter.com/EmertxeTweet https://www.slideshare.net/EmertxeSlides
THANK YOU

Más contenido relacionado

La actualidad más candente

Introduction Linux Device Drivers
Introduction Linux Device DriversIntroduction Linux Device Drivers
Introduction Linux Device DriversNEEVEE Technologies
 
LAS16-TR06: Remoteproc & rpmsg development
LAS16-TR06: Remoteproc & rpmsg developmentLAS16-TR06: Remoteproc & rpmsg development
LAS16-TR06: Remoteproc & rpmsg developmentLinaro
 
Bootloaders (U-Boot)
Bootloaders (U-Boot) Bootloaders (U-Boot)
Bootloaders (U-Boot) Omkar Rane
 

La actualidad más candente (20)

Embedded Linux on ARM
Embedded Linux on ARMEmbedded Linux on ARM
Embedded Linux on ARM
 
Linux-Internals-and-Networking
Linux-Internals-and-NetworkingLinux-Internals-and-Networking
Linux-Internals-and-Networking
 
Toolchain
ToolchainToolchain
Toolchain
 
Advanced C - Part 1
Advanced C - Part 1 Advanced C - Part 1
Advanced C - Part 1
 
Advanced C
Advanced C Advanced C
Advanced C
 
Linux Internals - Part II
Linux Internals - Part IILinux Internals - Part II
Linux Internals - Part II
 
Introduction Linux Device Drivers
Introduction Linux Device DriversIntroduction Linux Device Drivers
Introduction Linux Device Drivers
 
C Programming - Refresher - Part III
C Programming - Refresher - Part IIIC Programming - Refresher - Part III
C Programming - Refresher - Part III
 
Linux device drivers
Linux device drivers Linux device drivers
Linux device drivers
 
Embedded Operating System - Linux
Embedded Operating System - LinuxEmbedded Operating System - Linux
Embedded Operating System - Linux
 
Introduction to Linux Drivers
Introduction to Linux DriversIntroduction to Linux Drivers
Introduction to Linux Drivers
 
LAS16-TR06: Remoteproc & rpmsg development
LAS16-TR06: Remoteproc & rpmsg developmentLAS16-TR06: Remoteproc & rpmsg development
LAS16-TR06: Remoteproc & rpmsg development
 
C Programming - Refresher - Part II
C Programming - Refresher - Part II C Programming - Refresher - Part II
C Programming - Refresher - Part II
 
Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)
 
Bootloaders (U-Boot)
Bootloaders (U-Boot) Bootloaders (U-Boot)
Bootloaders (U-Boot)
 
U-Boot - An universal bootloader
U-Boot - An universal bootloader U-Boot - An universal bootloader
U-Boot - An universal bootloader
 
Embedded Android : System Development - Part IV
Embedded Android : System Development - Part IVEmbedded Android : System Development - Part IV
Embedded Android : System Development - Part IV
 
Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)
 
C Programming - Refresher - Part I
C Programming - Refresher - Part I C Programming - Refresher - Part I
C Programming - Refresher - Part I
 
Linux Programming
Linux ProgrammingLinux Programming
Linux Programming
 

Destacado

Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programmingsudhir singh yadav
 
Work Flow for Solo Developers and Small Teams
Work Flow for Solo Developers and Small TeamsWork Flow for Solo Developers and Small Teams
Work Flow for Solo Developers and Small TeamsEmma Jane Hogbin Westby
 
Perintah dasar linux
Perintah dasar linuxPerintah dasar linux
Perintah dasar linuxAcep Nugraha
 
Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsBinomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsAmrinder Arora
 
Struktur so dan basic command linux
Struktur so dan basic command linuxStruktur so dan basic command linux
Struktur so dan basic command linuxadam diarama
 

Destacado (20)

Linux Internals - Interview essentials 4.0
Linux Internals - Interview essentials 4.0Linux Internals - Interview essentials 4.0
Linux Internals - Interview essentials 4.0
 
Emertxe : Linux training portfolio
Emertxe : Linux training portfolioEmertxe : Linux training portfolio
Emertxe : Linux training portfolio
 
Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programming
 
sCode optimization
sCode optimizationsCode optimization
sCode optimization
 
States machine
States machineStates machine
States machine
 
Keyword Presentation
Keyword PresentationKeyword Presentation
Keyword Presentation
 
Types and roles
Types and rolesTypes and roles
Types and roles
 
Uml Common Mechanism
Uml Common MechanismUml Common Mechanism
Uml Common Mechanism
 
Processes and threads
Processes and threadsProcesses and threads
Processes and threads
 
Compilers
CompilersCompilers
Compilers
 
Work Flow for Solo Developers and Small Teams
Work Flow for Solo Developers and Small TeamsWork Flow for Solo Developers and Small Teams
Work Flow for Solo Developers and Small Teams
 
Sahul
SahulSahul
Sahul
 
Perintah dasar linux
Perintah dasar linuxPerintah dasar linux
Perintah dasar linux
 
BASIC COMMANDS OF LINUX
BASIC COMMANDS OF LINUXBASIC COMMANDS OF LINUX
BASIC COMMANDS OF LINUX
 
What is symbol table?
What is symbol table?What is symbol table?
What is symbol table?
 
Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsBinomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci Heaps
 
Single Pass Assembler
Single Pass AssemblerSingle Pass Assembler
Single Pass Assembler
 
Emertxe Certified Embedded Professional (ECEP) : Induction
Emertxe Certified Embedded Professional (ECEP) : InductionEmertxe Certified Embedded Professional (ECEP) : Induction
Emertxe Certified Embedded Professional (ECEP) : Induction
 
Struktur so dan basic command linux
Struktur so dan basic command linuxStruktur so dan basic command linux
Struktur so dan basic command linux
 
Fibonacci Heap
Fibonacci HeapFibonacci Heap
Fibonacci Heap
 

Similar a Linux programming - Getting self started

Similar a Linux programming - Getting self started (20)

Nithi
NithiNithi
Nithi
 
Linux Command Suumary
Linux Command SuumaryLinux Command Suumary
Linux Command Suumary
 
Unix_Introduction_BCA.pptx the very basi
Unix_Introduction_BCA.pptx the very basiUnix_Introduction_BCA.pptx the very basi
Unix_Introduction_BCA.pptx the very basi
 
Linuxs1
Linuxs1Linuxs1
Linuxs1
 
cisco
ciscocisco
cisco
 
3. intro
3. intro3. intro
3. intro
 
Linux Administration
Linux AdministrationLinux Administration
Linux Administration
 
Linux Administration
Linux AdministrationLinux Administration
Linux Administration
 
60761 linux
60761 linux60761 linux
60761 linux
 
Linuxppt
LinuxpptLinuxppt
Linuxppt
 
Linuxppt
LinuxpptLinuxppt
Linuxppt
 
Linux
LinuxLinux
Linux
 
Linuxppt
LinuxpptLinuxppt
Linuxppt
 
The structure of Linux - Introduction to Linux for bioinformatics
The structure of Linux - Introduction to Linux for bioinformaticsThe structure of Linux - Introduction to Linux for bioinformatics
The structure of Linux - Introduction to Linux for bioinformatics
 
Linux administration training
Linux administration trainingLinux administration training
Linux administration training
 
Linux Basics.pptx
Linux Basics.pptxLinux Basics.pptx
Linux Basics.pptx
 
Linux week 2
Linux week 2Linux week 2
Linux week 2
 
Using Unix
Using UnixUsing Unix
Using Unix
 
Linux
LinuxLinux
Linux
 
Tutorial 2
Tutorial 2Tutorial 2
Tutorial 2
 

Más de Emertxe Information Technologies Pvt Ltd

Más de Emertxe Information Technologies Pvt Ltd (20)

premium post (1).pdf
premium post (1).pdfpremium post (1).pdf
premium post (1).pdf
 
Career Transition (1).pdf
Career Transition (1).pdfCareer Transition (1).pdf
Career Transition (1).pdf
 
10_isxdigit.pdf
10_isxdigit.pdf10_isxdigit.pdf
10_isxdigit.pdf
 
01_student_record.pdf
01_student_record.pdf01_student_record.pdf
01_student_record.pdf
 
02_swap.pdf
02_swap.pdf02_swap.pdf
02_swap.pdf
 
01_sizeof.pdf
01_sizeof.pdf01_sizeof.pdf
01_sizeof.pdf
 
07_product_matrix.pdf
07_product_matrix.pdf07_product_matrix.pdf
07_product_matrix.pdf
 
06_sort_names.pdf
06_sort_names.pdf06_sort_names.pdf
06_sort_names.pdf
 
05_fragments.pdf
05_fragments.pdf05_fragments.pdf
05_fragments.pdf
 
04_magic_square.pdf
04_magic_square.pdf04_magic_square.pdf
04_magic_square.pdf
 
03_endianess.pdf
03_endianess.pdf03_endianess.pdf
03_endianess.pdf
 
02_variance.pdf
02_variance.pdf02_variance.pdf
02_variance.pdf
 
01_memory_manager.pdf
01_memory_manager.pdf01_memory_manager.pdf
01_memory_manager.pdf
 
09_nrps.pdf
09_nrps.pdf09_nrps.pdf
09_nrps.pdf
 
11_pangram.pdf
11_pangram.pdf11_pangram.pdf
11_pangram.pdf
 
10_combinations.pdf
10_combinations.pdf10_combinations.pdf
10_combinations.pdf
 
08_squeeze.pdf
08_squeeze.pdf08_squeeze.pdf
08_squeeze.pdf
 
07_strtok.pdf
07_strtok.pdf07_strtok.pdf
07_strtok.pdf
 
06_reverserec.pdf
06_reverserec.pdf06_reverserec.pdf
06_reverserec.pdf
 
05_reverseiter.pdf
05_reverseiter.pdf05_reverseiter.pdf
05_reverseiter.pdf
 

Último

Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfAarwolf Industries LLC
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 

Último (20)

Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdf
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
How Tech Giants Cut Corners to Harvest Data for A.I.
How Tech Giants Cut Corners to Harvest Data for A.I.How Tech Giants Cut Corners to Harvest Data for A.I.
How Tech Giants Cut Corners to Harvest Data for A.I.
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 

Linux programming - Getting self started

  • 1. Programming in Linux Self learning with Linux Team Emertxe
  • 3. Let us ponder…  What exactly is an Operating System (OS)?  Why do we need OS?  How would the OS would look like?  Is it possible for a team of us (in the room) to create an OS of our own?  Is it necessary to have an OS running in a Embedded System?  Will the OS ever stop at all?
  • 4. Operating System System and application programs Operating System Computer hardware User 1 User 2 User 3 Compiler Assembler Text editor Database system Humans Program interface User Programs OS interface OS Hardware interface/ privileged instructions Disk/memory
  • 5. What is Linux ?  Linux is a free and open source operating system that is causing a revolution in the computer world.  Originally created by Linus Torvalds with the assistance of developers called community  This operating system in only a few short years is beginning to dominate markets worldwide.
  • 6. Why use Linux?  Free & Open Source  Reliability  Secure  Scalability
  • 7. Freedom of software Freedom of redistribute Freedom of copy Freedom of modify Freedom of use What is Open Source?
  • 8. How it all started?  With GNU (GNU is not UNIX)  Richard Stallman made the initial announcement in 1983, Free Software Foundation (FSF) got formed during 1984  Volunteer driven GNU started developing multiple projects, but making it as an operating system was always a challenge  During 1991 a Finnish Engineer Linus Torvalds developed core OS functionality, called it as “Linux Kernel”  Linux Kernel got licensed under GPL, which laid strong platform for the success of Open Source  Rest is history!
  • 9. How it evolved? Kernel Applications Customization  Multiple Linux distributions started emerging around the Kernel  Some applications became platform independent  Community driven software development started picking up  Initially seen as a “geek-phenomenon”, eventually turned out to be an engineering marvel  Centered around Internet  Building a business around open source started becoming viable  Redhat set the initial trend in the OS business
  • 10. Where it stands now? OS Databases Server/Cloud Enterprise Consumer Education CMS eCommerce
  • 11. More details OSS Freeware  Users have the right to access & modify the source codes  In case original programmer disappeared, users & developer group of the S/W usually keep its support to the S/W.  OSS usually has the strong users & developers group that manage and maintain the project  Freeware is usually distributed in a form of binary at ‘Free of Charge’, but does not open source codes itself.  Developer of freeware could abandon development at any time and then final version will be the last version of the freeware. No enhancements will be made by others.  Possibility of changing its licensing policy Open Source SW vs. Freeware
  • 12. GPL  Basic rights under the GPL – access to source code, right to make derivative works  Reciprocity/Copy-left  Purpose is to increase amount of publicly available software and ensure compatibility  Licensees have right to modify, use or distribute software, and to access the source code
  • 13. Problems with the GPL  Linking to GPL programs  No explicit patent grant  Does no discuss trademark rights  Does not discuss duration  Silent on sub-licensing  Relies exclusively on license law, not contract
  • 14. Linux: Properties  Multitasking  Multi-user  Multiprocessing  Protected Memory  Hierarchical File System
  • 15. / /boot/ /dev/ /bin/ /etc/ /home/ /lib/ /media/ /mnt/ /opt/ /sbin/ /tmp/ /usr/ /var/ /root/ /proc/ Directory structure Static files for boot loader Device files Essential user command binaries Host specific system configuration User home directories Essentilal shared libraries and kernal modules Mount point for removable media Mount point for temporarily mounted file systems Add-on application software package User specific system binaries Temporary files Multi-user utilities and applications Variable file (logs) Home directory for root user Virtual file system documenting kernel and process status
  • 17. Kernel structure  Hardware Controllers: This subsystem is comprised of all the possible physical devices in a Linux installation  Linux Kernel: The kernel abstracts and mediates access to the hardware resources, including the CPU. A kernel is the core of the operating system  O/S Services: These are services that are typically considered part of the operating system (e.g. shell)  User Applications: The set of applications in use on a particular Linux system. (e.g. web-browser)
  • 20. Command Line Interface • CLI • Textual mode • Executes requested command • GUI • Mouse, keypad
  • 21. The Shell  What is a shell?  Different types of shells • Login-shell • Non-login shell • Sh • Bash • Ksh • Csh  Hands-on: • echo $0 • cat /etc/shells
  • 22. How Shell Invokes The main task of a shell is providing a user environment Input (ls) Shell Error List all the files
  • 23. Bash Files  Bash • Command interpreter • .bash_profile (During login) • .bashrc (New instance) • .bash_logout (Logout) • .bash_history (Command history)  Hands-on: • Enter ls -a in your home directory • Display contents of all files mentioned above
  • 24. Environment Variables  Login-shell's responsibility is to set the non-login shell and it will set the environment variables  Environment variables are set for every shell and generally at login time  Environmental variables are set by the system.  Environmental variables hold special values. For instance ,$ echo $SHELL  Environmental variables are defined in /etc/profile, /etc/profile.d/ and ~/.bash_profile.  When a login shell exits, bash reads ~/.bash_logout
  • 25. The 'bash' variables & Friends Name Meaning env Lists shell environment variable/value pairs export [var_name] Exports/sets a shell variable HOME Path of user’s home directory PATH Executable search path PWD Present working directory PS1 Command prompt N=10 Assigning the variable. This a temporary variable effective only inside the current shell unset N Unset the environment variable N
  • 26. Basic Shell Commands Command Meaning ls Lists all the files pwd Gives present working directory cd Change directory man Gives information about command exit Exits from the shell which Shows full path of command
  • 27. Shell: Built-in Commands  Built-in commands are contained with in the shell itself, means shell executes the command directly, without creating a new process  Built-in commands: break,cd,exit,pwd,export,return,unset,alias,echo,print f,read,logout,help,man
  • 29. VIsual editor  vi or vim  To open a file $ vi <filename> or vim <filename>
  • 30. VIsual editor…  vi opens a file in command mode while starting  The power of vi comes from its 3 modes • Escape mode (Command mode) Search mode File mode • Editing mode Insert mode Append mode Open mode Replace mode • Visual mode.
  • 31. Cursor Movement  You will clearly need to move the cursor around your file. You can move the cursor in command mode.  vi has many different cursor movement commands. The four basic keys appear below  Yes! Arrow keys also do work. But these makes typing faster Character Meaning k Move up one line h Move one character to the left l Move one character to the right j Move down one line
  • 32. Basic vi commands  How to exit  Already looks too complicated?  Try by yourself, let us write a C program  Try out vimtutor. Go to shell and type vimtutor Command Meaning :q Quit without saving :wq Close the file with saving :q! Quit the file forcefully without saving
  • 33. Escape mode or Command mode  In command mode, characters you perform actions like moving the cursor, cutting or copying text, or searching for some particular text • Search mode • vi can search the entire file for a given string of text. A string is a sequence of characters. vi searches forward with the slash (/) key and string to search. • To cancel the search, press ESC .You can search again by typing n (forward) or N (backward). • Also, when vi reaches the end of the text, it continues searching from the beginning. This feature is called wrap scan. Instead of (/), you may also use question (?). That would have direction reversed • Now, try out. Start vi as usual and try a simple search. Type /<string> and press n and N a few times to see where the cursor goes.
  • 34. Escape mode...  File mode • Changing (Replacing) Text Command Meaning :%s/first/sec Replaces the first by second every where in the file %s/old/new/gc For all lines in a file, find string “old" and replace with string “new" for each instance on a line :e filename Open another file without closing the current set all Display all settings of your session :r filename Reads file named filename in place
  • 35. Editing Modes... Command Mode name Insertion point a Append Just after the current character A Append End of the current line i Insert Just before the current character I Insert Beginning of the current line o Open New line below the current line O Open New line above the current line
  • 36. Editing Text  Deleting Text Sometimes you will want to delete some of the text you are editing.  To do so, first move the cursor so that it covers the first character of the group you want to delete, then type the desired command from the table below. Command Meaning dd For deleting a line ndd For deleting a n lines x To delete a single character shift + d Delete contents of line after cursor dw Delete word ndw Delete ‘n’ words
  • 37. Some Useful Shortcuts Command Meaning shift-g Go to last line in file shift-j Joining the two lines . Repeat the previous command executed ctrl+a Increment number under the cursor ctrl+x Decrements numbers under the cursor
  • 38. Visual Mode Visual Mode Visual mode helps to visually select some text, may be seen as a sub mode of the command mode to switch from the command mode to the visual mode type one of • ctrl+v Go's to visual block mode. • Only v for visual mode • d or y Delete or Yank selected text • I or A Insert or Append text in all lines (visual block only)
  • 40. File redirection  Out put redirection ( > )  Redirecting to append ( >> )  Redirecting the error (2>) eg : $ls > /tmp/outputfile eg : $ls -l >> /tmp/outputfile eg : $ls 2> /tmp/outputfile
  • 41. Piping  A pipe is a form of redirection that is used in Linux operating systems to send the output of one program to another program for further processing.  A pipe is designated in commands by the vertical bar character eg: $ ls -al /bin | less
  • 42. File Related commands  Every thing is viewed as a file in Linux. Even a Directory is a file.  Basic Shell Command Set Command Meaning df Disk free space du Disk usage cp <source> <dest> Copy file from one to another mv <source> <dest> Rename a file rm <file> Remove a file stat File related statistics (i-node) ln Linking between files (-s option for soft link)
  • 43. Continued Command Meaning mkdir <dir_name> Make directory rmdir <dir_name> Remove a particular directory touch Change file timestamps wc Counts the number of lines in a file cat Display contents of the file in standard output more Display contents, navigate forward head Display first 10 lines of the file (-n to change) tail Display last 10 lines of the file (-n to change) sort Sort lines of text files
  • 45. Linux file types 1st column • - • d • c • b • l • s • = or p Meaning • Plain text • Directory • Character driver • Block driver • Link file • Socket file • FIFO file
  • 46. File permissions  r or 4 -r--r--r-- Read  w or 2 --w--w--w- Write  x or 1 ---x--x--x Execute rwx rwx rwx 421 421 421 user group others Changing the File Permissions $ chmod – Change file permessions $ chown – Change file owner $ chmod [ ug+r, 746 ] file.txt $ chown -R user:group [ filename | dir ]
  • 48. Subsystems  The Process Scheduler (SCHED)  The Memory Manager (MM)  The Virtual File System (VFS)  The Network Interface (NET)  The Inter-Process Communication (IPC)
  • 50. Kernel design  Most older operating systems are monolithic, that is, the whole operating system is a single executable file that runs in 'kernel mode'  This binary contains the process management, memory management, file system and the rest (Ex: UNIX)  The alternative is a microkernel-based system, in which most of the OS runs as separate processes, mostly outside the kernel  They communicate by message passing. The kernel's job is to handle the message passing, interrupt handling, low-level process management, and possibly the I/O (Ex: Mach)
  • 52. System calls  A set of interfaces to interact with hardware devices such as the CPU, disks, and printers.  Advantages: • Freeing users from studying low-level programming • It greatly increases system security • These interfaces make programs more portable
  • 54. System Call... Logically the system call and regular interrupt follow the same flow of steps. The source (I/O device v/s user program) is very different for both of them. Since system call is generated by user program they are called as ‘Soft interrupts’ or ‘traps’
  • 55. Stay connected About us: Emertxe is India’s one of the top IT finishing schools & self learning kits provider. Our primary focus is on Embedded with diversification focus on Java, Oracle and Android areas Emertxe Information Technologies, No-1, 9th Cross, 5th Main, Jayamahal Extension, Bangalore, Karnataka 560046 T: +91 80 6562 9666 E: training@emertxe.com https://www.facebook.com/Emertxe https://twitter.com/EmertxeTweet https://www.slideshare.net/EmertxeSlides