Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
56 views

System Programming With Linux Debugging Using C and C++ Programming Topics

C,C++ preparation in depth!!

Uploaded by

RAMU
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

System Programming With Linux Debugging Using C and C++ Programming Topics

C,C++ preparation in depth!!

Uploaded by

RAMU
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Advanced C

The C Language Memory


C Program Compilation Dynamic Memory Allocations
Execution Process malloc, calloc, realloc, free
Tokens of C Program Heap Memory
C Instructions Stack Memory – Pitfalls
Constants, Variables Dangling Pointers
Identifiers and Keywords DMA – Errors
Primitive Data Types Best Practices for malloc() & free()
Structures – The Definition DMA – Unspecified Behaviour
Structures – Declaration & Type
Accessing Elements of Structure Functions & Pointers
Range of Signed/Unsigned Data-types Invoking Functions
Efficient way of Printing Pointer Passing Arguments to Functions
Compiler Memory Allocation for Data-types Call by Value & Reference
Compiler Memory Allocation for Structures Is C call by Value?
Data-type Alignments Is C call by Reference?
Compiler Memory Allocation for Unions Array as Function Argument
Union – Data Corruption Rules for Array Argument Passing
Practical Usage of Unions Multi-dimensional Array Argument
Practical Usage of Bitfields Passing
Printing every byte of an Integer Structure as Function Argument
Enumeration Static Vs Dynamic Runtime Environment
Typedef Statements Function Call and Runtime Stack
Practical example of Typedef Usage Rules for Evaluation of Function
Bit-Fields in Structure Arguments
Practical examples of Bitfield Usage Memory Organization
Structure Padding & Pitfalls Code Segment
Programming Model & Memory Sizes Data Segment
Why Sizeof Int and Long is 4 or 8? Heap Segment
IA-32, IA-64, ILP-32, LP64, x86-64 Stack Segment
Array – Representation free space
Array – Memory Allocation register space
Array – Declaration & Initialization Stack Frames
Two Dimensional Arrays Calling Sequence
View of Runtime Stack with Example
Pointers Access to Local Variable in Stack
Accessing a Variable Through Pointer Local Temporaries
Pointer – Memory Allocation Function Pointers
Pointer – Declaration & Initialization Declaration and Usage of Function
Pointer – Dereferencing Pointers
Pointers & Arrays Function Pointers as Function Parameters
Character Arrays using Pointers Practical Example of Function Pointers
Array of Character Pointers Pointer to an Integer Array
Memory Diagram – Array of Char Pointers
Arrays as Pointers – a[i] == i[a]?

1
Constant Pointers C Pointers Complexity Chart
Pointer Arithmetic int **p
String Handling Functions int (*p)()
String Conversion Functions int (*p)[]
Efficient usage of sscanf()/sprintf() int *p()
int *(*p[])()
Computing Basic int *(**p)[]
Binary & Octal Systems
Decimal & Hexadecimal Systems Preprocessor
Signed Representations in Memory Preprocessor – #include statements
Binary Shifts – Right & Left Preprocessor – #define statements
Sign Bits and Bit-Shift Operations Preprocessor – Conditional Compilation
ASCII Representations Preprocessor – Nested Macros
Endian-ness – Little Vs Big Preprocessor – Multiline Macros
Endian-ness – Portability Issues Preprocessor – Stringizer
Operators Preprocessor – Token Concatenation
Bitwise Operations Preprocessor – Useful Directives
Logical Operators – Short Circuit Conditional Directives for Debugging
Bitwise Vs Logical Operations Where Macros are Heavily Used
sizeof() operator Practical Examples of Macros
Pitfalls/Issues with sizeof() usage Macros Pitfalls
Pointer Increment & Scaling Macros Vs Enums
Operator Precedence Inline Functions
Operator Associativity Macros Vs Inline
True meaning of Associativity Inline Recursive Functions
Examples of Precedence & Associativity
Ternary Operator Associativity Rule Command Line Argument
Data-type Conversion Rules Environment Variables in C Programs
Float to Int to Float Conversions Recursion Example
Printf Idiosynchracies Recursion Vs Iteration
Signed Vs Unsigned – Pitfalls Code/Space/Time Complexity
Evaluation of i = ++i + ++i
Evaluation of i = ++i + ++i + ++i Standard I/O Library
Concept of Sequence Points Files & Streams
Example of Sequence Points Streams Buffers
No Buffer, Line Buffer and Full Buffer
Storage Classes Setting & Flushing Buffers
Storage Class Specifiers File Access
Scope of a Variable File Access Modes
Register, Auto, Static, Extern Sequential Vs Random Access
Why Register Class and Practical Examples Concept of File Offsets
Automatic Variables and Stack File Operation Errors
Static Variables and Functions End-of-File Condition?
True meaning of Extern Return Values and Error Values
How to Use extern across Multiple Files with Character Based File I/O
Examples Line Based File I/O

2
Best Practices for Extern Usage Formatted File I/O
Local/Block/Global Scope Block File I/O
Nesting of Scope File
Lifetime of a Variable
Linkage of a Variable
What is Const?
Practical Examples of Const Qualifier
What is Volatile?
Practical Examples of Volatile Qualifier
Const Volatile Together?
Practical Examples of Const Volatile
Pointer Aliasing
What is Restrict Qualifier?
Examples of Restrict Qualifier

Linux & C Debugging Techniques

 C program to Process  Object Dump


 Compilation Steps  Stack Frames
 Preprocessor  Mapping Assembly to C
 Compiler  Managing Heap
 Assembler  Pmap / Pstack
 Linker / Loader  Strace
 GCC options  Debugging Tools
 Fixing Warnings in the Code  GDB Debugger
 Include Files  Debugging Running Process
 Libraries  Core dump analysis
 Static Vs Dynamic Library  Symbols & Optimizations
 Static Library Generation  Default Optimization Levels
 Dynamic Library Generation  Common Failures
 Linking with Libraries  Failure Notifications
 File Formats  Common Faults
 ELF Format  Segmentation Violation
 Symbol Tables  Stack Overflow
 Anatomy of a Process  Heap Overflow
 Process Map  Arithmetic Overflow
 Memory Layout  Illegal code execution
 Code Segment  Stack Issue
 Data Segment  Endian-ness issue
 Stack Segment  C library assertion
 Heap Segment  Data Type mismatch

3
Linux Kernel Introduction Process Focus
Linux System Viewing Processes
Linux Organization Process Tree & Process Status
Linux Version Identifying System & Daemon Processes
Basic OS Concept Foreground and Background Processes
Linux N+1 System Tuning Process Scheduling
Linux Filesystem Process Priority
File Types nice & renice commands
Processes & File Objects Killing / Terminating a Processes
File Object Access Max Processes per User – ulimit
The Process/Kernel Model Per Process Resource Limits
Re-entrant Kernel Stack Sizes
Interleaved Kernel Control Paths Core File Limits
Preemptive Kernel IPCs Consumption and Limits
Preemptive Context Switch
Synchronization Process Internals
Deadlock Anatomy of a Process
Memory Management Process Map in Linux
Memory Layout
Memory Addressing Code Segment
Logical, Linear & Physical Addresses Data Segment
Translating a Logical Address Stack Segment
Segmentation in Linux Heap Segment
Paging in Linux Decoding Process Map Lab
Large Pages
Physical Page Extension(PAE) System Focus
Hardware Cache Performance Monitoring & Troubleshooting
Cache Coherency System Status – Resource Consumption
Translation Lookaside Buffers (TLBs) System Status – Memory Usage
Linux 4 Table Paging Model System Status – I/O Activity
Physical Memory Layout System Status – CPU Usage
Kernel Physical Memory Variables Resource Usage – Trends
Process Page Tables top, iostat, vmstat, sar commands
Kernel Page Tables Sample Programs to Consume CPU and
TLB Management Memory
Memory Eater Lab
Processes in Linux Kernel CPU Loader Lab
Process
Lightweight Process Troubleshooting Methods
Threads & Thread Groups Process Syscall Tracing – strace
Process Descriptions Process Libcall Tracing – ltrace
The task_struct Process Kernel/User Space Time Check
Linux Process States Profiling Data using System & Library Traces
Thread Group Leader
The Process List GDB Debugging
Waiting Processes GDB Deep Dive Lab

4
Wait Queues Debugging a Live Process
Awakening Processes Starting a Program with GDB
Process Creation Debugging a Memory/Core Dump
Kernel Threads Stack Traces
Process 0 & Process 1 Common Failures
Destroying Processes Failure Notifications
Process Removal Common Faults
Segmentation Violation
Process Scheduling Stack Overflow
Process Preemption Heap Overflow
Quantum Duration
Scheduling Policies Linux Kernel Crash Dump Analysis
Scheduling of Conventional Processes Crash Dump Process
Dynamic Priority How kexec / kdump Works
Realtime Processes Settinp up Kexec/Kdump
Realtime Process Scheduling crashkernel parameter
Runqueue Balancing in Multiprocessing Set up, Testing and Running Crash
Systems Crash Analysis
Scheduling Domains
Load Balancing
CPU Binding

Signals in Linux
Signal Related System Calls
Signal Generation and Delivery
Pending Signals
Action Performed Upon Delivery
Signals @ Multithreaded Application
Delivering the Signal
Catching the Signal
Restarting System Calls
=====================================================================================

Linux Kernel Internals

Linux Kernel Introduction Getting Started with Kernel


Linux System Obtaining the Kernel Source
Linux Organization Installing the Kernel Source
Linux Version Using Patches
Basic OS Concept The Kernel Source Tree
Linux N+1 System Building the Kernel
Linux Filesystem Configuring the Kernel
File Types Efficient Kernel Building
Processes & File Objects Spawning Multiple Build Jobs
File Object Access Installing the New Kernel
The Process/Kernel Model Understanding Kernel Programming

5
Re-entrant Kernel C Library or Standard Headers?
Interleaved Kernel Control Paths GNU C Extensions
Preemptive Kernel Inline Functions
Preemptive Context Switch Inline Assembly
Synchronization Branch Annotation
Deadlock Memory Protection?
Memory Management Floating Point?
Stack Sizes
Processes in Linux Kernel
Process
Lightweight Process
Memory Addressing
Threads & Thread Groups
Logical, Linear & Physical Addresses
Process Descriptions
Translating a Logical Address
The task_struct
Segmentation in Linux
Linux Process States
Paging in Linux
Thread Group Leader
Large Pages
thread_info Structure
Physical Page Extension(PAE)
Kernel Stack Structure
Hardware Cache
The Process List
Cache Coherency
Waiting Processes
Translation Lookaside Buffers (TLBs)
Wait Queues
Linux 4 Table Paging Model
Awakening Processes
Physical Memory Layout
Process Creation
Kernel Physical Memory Variables
clone() / fork() / vfork()
Process Page Tables
Kernel Threads
Kernel Page Tables
Process 0 & Process 1
TLB Management
Destroying Processes
exit_group() / _exit()
Process Removal
Kernel Synchronization
Kernel Preemption
When Synchronization is Necessary
Timing Measurements in Linux
Interleaved Kernel Control Paths
Clocks and Timer Circuits
When Synchronization is Not Necessary
Linux Timekeeping Architecture
Synchronization Constraints
The jiffies Variable
Synchronization Primitives
Updating System Statistics
Per-CPU Variables
Software Timers
Atomic Operations
Dynamic Timer List Structure
Optimization & Memory Barriers
Timer List Data-Structure
Spin Locks
Per-CPU Timer List
Read/Write Spin Locks
Delay Functions
Seqlocks
udelay() and ndelay()
Read-Copy Update (RCU) Locks
System Calls for POSIX Timers and Clocks
Semaphores
Read/Write Semaphores
Local Interrupt Disabling

6
Disabling Deferrable Functions
Process Scheduling Memory Management
Process Preemption Page Frame / Page
Quantum Duration Memory Zones
Scheduling Policies Reserved Page Frames
Scheduling of Conventional Processes High Memory Page Frames
Dynamic Priority Temporary Kernel Mappings
Realtime Processes Dynamic Contigous Page Allocation
Realtime Process Scheduling Slab Allocator
Runqueue Data Structure Object Caches
Runqueue Balancing in Multiprocessing Systems Slab Cache Allocation
Scheduling Domains Object Allocation
Load Balancing General Purpose Allocation – kmalloc()
CPU Binding Non-contigous Memory Area Management
Process Address Space
Kernel Address Space
Process Address Space
System Calls for Memory Region System Calls
brk(), execve(), _exit(), fork() System Call Handler
mmap(), mmap2(), munmap(), Service Routines
shmat(), shmdt() Invoking a System Call
Page Faults Leaving a System Call
Valid & Invalid Addresses Arguments to System Call
The Memory Descriptor Arguments in Registers
The mem_struct Structure Verifying the Arguments
Memory Regions Accessing Process Address Space
Linear Address Intervals – do_mmap() Exception Tables
Page Fault Exception Handling Fixing Address Exceptions
Demand Paging Kernel Wrapper Routines
Copy on Write (COW)
Creating Process Address Space
Managing Heap Space
Signals in Linux Linux Page Cache
Signal Related System Calls Page Cache Contents
Signal Generation and Delivery Page Cache Requirements
Pending Signals The address_space Object
Action Performed Upon Delivery Block Buffers and Page Cache
Signals @ Multithreaded Application The Buffer Head
Data Structures for Signal Handling Buffer Pages
Delivering the Signal Writing Dirty Pages to Disk
Catching the Signal bdflush & pdflush
Restarting System Calls sync(), fsync() and fdatasync() calls
Page Frame Reclamation Linux Virtual Filesystem
Page Frame Reclaiming Algorithm VFS Role in File Operations
Unreclaimable pages VFS Supported Filesystem Classes

7
Swappable Pages Common File Model
Syncable Pages Process & VFS Object Interaction
Discardable Pages VFS Data Structures
Design of the Algorithm Super Block Object
Reclaimation Tigger Points Inode Object
Low on Memory File Object
Periodic Reclaiming Dentry Object
The Out-of-memory Killer Processes and Files
Swapping Features The fd array
Constraints on a Process
File System Types
Filesystem Type Registration
Filesystem Handling
Mounting a Filesystem
Pathname Lookup
Reads & Writes
Other File Operations

Linux Kernel Debugging

Intro to Kernel Debugging


Kernel OOPS
Kernel Hang

Kernel Helpers for Debugging


Ksysmoops
System.map
/proc/kallsyms
/proc/kcore
Objdump – s vmlinux
/var/log/messages
Syslogd
Magic SysRq

Kernel Debuggers
gdb analysis of Live Kernel
Limitations of gdb analysis
kdb analysis of Live Kernel
Limitations of kdb analysis
kgdb analysis of Live Kernel
Setting up kdb and kgdb
kexec / kdump
LKCD

8
Linux Kernel Crash Dump Analysis
Crash Dump Process
How kexec / kdump Works
Settinp up Kexec/Kdump
crashkernel parameter
Set up, Testing and Running Crash
Crash Analysis

Hands-on Lab
Configuring the Kernel for Debugging
Kernel Parameters for KDB and KGDB
Building Kernel for Debugging
Turning on Magic Sysrq Keys
Debugging a Live Kernel using gdb, kdb and kgdb
Printing Kernel Global Variables and Code
Loading a Debug Module using kdb and kgdb
Insert bug(s)
make system hang
Crash and Analyze

Basics about Linux Device Drivers

 What is Kernel  Ioctl command numbers


 Linux System Architecture  Capabilities & Restricted
 Linux Software Architecture Operations
 Basic Kernel Services  Driver Usage Count
 Linux Kernel Code  Kernel Synchronization
 What is a Device Driver Mechanisms
 Classes of Devices  Introduction to Race
 Device Driver Classification Conditions
 Concept of a Module  Sources of Race Conditions
 Fundamental Concepts  Preemption – User & Kernel
 Kernel Module Vs Application  Preemption APIs
 Namespace  Interrupt Handling APIs
 Major & Minor Numbers  Semaphores
 Reserved Major Numbers  Binary & Counting
 Module Parameters Semaphores
 Loading/Unloading Modules  Reader Writer Semaphores
 Current Process Information  Semaphore APIs
 Kernel Memory Allocations  Mutexes
 Driver Entry Points  Spinlocks
 Driver Switch Tables  Spinlock APIs
 Module Init & Exit  Atomic Operations
 Device Registration  Seqlocks
 Character Device Drivers  Seqlock APIs
 File Structure  Completions

9
 File Operations Structure  Deadlock – Sources
 Driver-User Data Transfer  Deadlock Prevention
 Driver-Kernel Communication  Waitqueues
 Driver-Device  Rules for Sleeping
Communication  Waitqueue APIs
 Device File Creation  Linux Kernel Tree
 Device File Control  Linux Source Code
Operations  Linux Kernel Configuration

Lab:

Lab1 – Identification of major and minor numbers for various popular (reserved) devices.
Lab2 – Writing simple kernel module with command line arguments.
Lab3 – Identification of currently allocated IO-ports, IO-memory & IRQs on your system/laptop.
Lab4 – Writing a memory based character device driver (DLKM Kernel Module) of fixed size
Lab5 – Writing an advanced memory based character device driver of dynamic size
Lab6 – Writing /dev/sanfd_zero device driver (reading any sized data from this device returns zero-filled
data).
Lab7 – Writing /dev/sanfd_null device driver (ala bit-bucket / black-hole driver).
Lab8 – Implementation of ioctls – RESET (it should reset the device to its default size and initial values),
GETSIZE (should return the current size of the device), EXPAND X (will expand the size of
/dev/sanfd_dynamic device by X bytes).
Lab9 – Writing a userspace program to get the device size.
Lab10 – Writing a userspace program to expand the dynamic device size by 1MB and verify the working
of the driver.
Lab11 – Writing user-space code to parallelly generate load on the devices, generate race conditions and
implement locks in the driver to fix all the issues.

===================================================================================

Linux Threads

 Introduction to Threads
 Parallelism
 Multi-cores
 Introduction to Thread
 Threads – Application
 User Level Threads (ULT)
 Advantage of ULT
 Disadvantage of ULT
 Kernel Level Threads (KLT)
 Advantage of KLT
 Disadvantage of KLT

10
 Threads Vs Processes
 Process Memory Layout
 Child Process Memory
 Threads Inside Processes
 Thread Memory Layout

 Thread Programming – I
 Introduction to Pthreads (POSIX Threads)
 Thread Creation
 Thread Termination
 Thread Id & Attributes
 Thread Joining & Detaching
 Thread Priorities
 Thread Cancellations
 Thread Cleanup Handling
 Passing Info to Threads

 Thread Programming – II
 Thread Synchronizations
 Mutual Exclusions
 Condition Variables
 Thread Safe Operations
 Thread Signal Handling
 Thread Signal Masking
 Issues @ Threads
 Races & Deadlocks
 Threads & Process Resources
 Threads – File Handling
 Threads – IPC Handling

LINUX Network/Socket Programming

 Intro to Network Programs


 TCP/IP Protocol Stacks
 Intro to Network Programming
 Sockets
 Port Numbers
 Common Port Numbers
 Common Protocol Numbers
 Unix Domain Socket
 Internet Domain Socket
 Socket Functions
 Socket System Calls
 Client Side Programming
 Server Side Programming
 Byte Ordering Requirements

11
 Concurrent Server Design
 Iterative Server Design
 Socket Debugging Techniques
 Advanced Socket Options
 Changing Socket Buffer Sizes
 Reusing Socket Addresses
 Keeping the Connections Alive
 TCP Socket Options
 Setting Max Segment Size
 Setting TCP No-Delay
 Advanced I/O Functions
 Socket Timeouts
 Vectored Read/Writes
 Netstat – Network Stat Utility
 Tcpdump – Packet Dump Utility

Linux / Unix System Programming

 Introduction to Unix
 Linux Layered Architecture  Why IPCs
 Bootup Sequence  Type of IPC Mechanisms
 File Tree & Types  Primitive IPCs
 File Systems  Pipes & FIFOs
 Super Block & Inode  Full Duplex Pipes
 System Vs Function Calls  Persistence of Pipes & FIFOs
 System Call Sequence  Pros and Cons of Pipes/FIFOs
 File descriptor table  Limitation of Pipes/FIFOs
 File Management  System V IPCs
 File related System Calls  IPC Attributes
 File Control Operations  IPC Persistence
 File Locking  Kernel Limits for these IPCs
 fcntl() calls  Shared Memory
 Process Management  Shared Memory System Calls
 Mode of Execution  Pros and Cons of Shared Memory
 Address Space  Message Queues
 Context Switching  Message Queue System Calls
 Process Structure & States  Pros and Cons of Message Queues
 Scheduling & Priority  Semaphores
 Process Creation & Exec  Classical P() & V() Operations
 fork()/exec() calls  Binary & Counting Semaphores
 Memory Management  Semaphore System Calls
 Virtual Memory  Pros and Cons of Semaphores
 Paging & Swapping  IPC Control Operations
 Memory Mapping  IPC Removal
 Demand Paging

12
 Signals Vs. Interrupts
 Signals in Unix
 Receiving a Signal
 Handling a Signal
 Signal System Calls
 User Vs Daemon Process
 Characteristics of a Daemon
 Writing a Daemon
 Timers & Resource Limits
 Interval Timers
 High Resolution Timers
 System calls for Timers
 Resource Limits
 Hard Limit / Soft Limit

Linux layered architecture

The structure of Linux is that it has a layer that interacts with programs, a layer that interacts with the
hardware and there is not much I'm leaving out. With Windows there are so many virtual machines and
other things involved it's crazy. Answerfrom top:
3. Applications
2. Layer
1. Kernel
0. Hierachical file system

13
FINALLY

Advanced C++
Session – 1 – C++ Overview
Need for C++
Session – 2 – Class Details
Differences of C++ compared to C# and Java
Pointer to Members
C++ as a federation of many concepts
Nested Classes
Is C++ so big and complex?
The const function, the const Variable
Is there a sweet subset of C++ that everyone
The const Object, the const Argument
can learn?
Multi argument Constructors
Structure Extension and Introduction to
Overloaded Constructors
classes
Virtual Constructors
Modularity and Data Abstraction Evolution
Virtual Destructors
Classes, Constructors, Destructors and The
Order of calling constructors and destructors
this pointer
Uses of :: Scope Resolution Operator
Major and Minor Pillars of OO and how they
Pointer to class object as data members
are implemented in C++
Array of Class Objects
Object Initialization and Cleaning Up
Static Keyword in C and C++
The “this” Pointer
Static Data Members
Data Members and Member function
Static functions and static objects
Member Qualifications
Problem solving and lab session
Problem solving and exercises
Writing code in C++
Problem solving and lab session
Discussion
Writing code in C++
Discussion
Session – 3 – Compile time polymorphism Session – 4 – Compilation and Linkage
Compile time polymorphism Compile time polymorphism

14
Function overloading Function overloading
Operator overloading – with strings and Operator overloading
iostream What is a reference and how is reference different
When and how to use function overloading from a pointer?
When and how to use operator overloading Where is it used?
This Pointer in C++ Inline function and Default arguments
Void type Const modifier Introduction to Linkage
Prototyping a function Internal Linkage and External Linkage
Types of Operators Header files and Linkage to non-C++ code
Extension, Linkage & Compilation Compilation procedure and how to make to make
Problem solving and lab session C and C++ Libraries
Writing code in C++ Real examples of using operator overloading
Discussion Friend function and friend class
Solving problems on levels of inheritance Operator overloading and friend functions
Problems in function overloading Operator overloading and Input output streams in
C++
Problem solving and lab session
Writing code in C++
Discussion
Session – 6 – More C++ Conversions
Session – 5 – C++ Conversions
Conversions in C++
Conversion between basic data type and user
What is a conversion and the need for it
defined data type
Solving problems
Conversion using conversion function in the
Simple conversions
source class
Problems in built-in conversion
Conversion using overloading assignment
User defined data types
operator in the destination
Conversion between user defined to basic
Is the conversion code clean?
data type
Can we get away without using conversions?
Design Issues and Implementation issues
Variants of the design pattern
Problem solving and lab session
Problem solving and lab session
Writing code in C++
Writing code in C++
Discussion
Discussion
Session – 7 – Run time Polymorphism and Session – 8 – Run time Polymorphism and design
design guidelines guidelines
Run time polymorphism Back to polymorphism
How is this polymorphism runtime? How polymorphism is implemented in C++
The difference between runtime and compile VTable and its implementation
polymorphism Use of function pointers
Static and dynamic binding What does the C++ 11 and C++ 14 standard say?
Rectangle and Square problem What the instructions generated by the compiler
‘Is a’ and ‘has a’ relationship for runtime polymorphism?
‘whole part’ relationship Polymorphism – the fundamental building block
‘using’, ‘implemented in terms of’ and of Object Oriented Analysis,
‘realization’ relationship Design and Programming
Simple virtual functions Introduction to multithreading in C++

15
Pure Virtual functions Uses of multithreading
Non Virtual functions Thread pooling pattern
Difference between Abstract class and Active Object design pattern
interface in C++ Worker thread pattern
Problem solving and lab session Problem solving and lab session
Writing code in C++ Writing code in C++
Discussion Discussion
Session 9 : Templates and Exception
handling
Session 10: Introduction Generic Programming
Introduction to templates
with STL and Course Review
Templates and macros
Smart Pointers and their applications
Advantages of using templates
Smart Pointers and raw pointers
Are templates Turing complete?
Resource allocation
Template Specialization and partial
Introduction to Generic Programming
specialization
STL and its significance in clean and efficient
Template Meta Programming
programming
Usage of type names in template
Algorithms, Iterators and Containers
What are exceptions?
Types of Containers available and programming
Does exception handling against the idea of
using them
structured programming?
Iterator traits
try, catch and throw
Iterator types and how they are used
Nested Exceptions
Review of the course
Writing to code in C++ to understand
exceptions

16
ress the power button on your system, and after few moments you see the Linux login prompt.

Have you ever wondered what happens behind the scenes from the time you press the power
button until the Linux login prompt appears?

The following are the 6 high level stages of a typical Linux boot process.

1. BIOS

 BIOS stands for Basic Input/Output System


 Performs some system integrity checks
 Searches, loads, and executes the boot loader program.
 It looks for boot loader in floppy, cd-rom, or hard drive. You can press a key (typically F12 of F2,
but it depends on your system) during the BIOS startup to change the boot sequence.
 Once the boot loader program is detected and loaded into the memory, BIOS gives the control
to it.
 So, in simple terms BIOS loads and executes the MBR boot loader.

2. MBR

 MBR stands for Master Boot Record.


 It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda
 MBR is less than 512 bytes in size. This has three components 1) primary boot loader info in 1st
446 bytes 2) partition table info in next 64 bytes 3) mbr validation check in last 2 bytes.
 It contains information about GRUB (or LILO in old systems).
 So, in simple terms MBR loads and executes the GRUB boot loader.

17
3. GRUB

 GRUB stands for Grand Unified Bootloader.


 If you have multiple kernel images installed on your system, you can choose which one to be
executed.
 GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it loads the
default kernel image as specified in the grub configuration file.
 GRUB has the knowledge of the filesystem (the older Linux loader LILO didn’t understand
filesystem).
 Grub configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this). The following is
sample grub.conf of CentOS.

#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-194.el5PAE)
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-194.el5PAE ro root=LABEL=/
initrd /boot/initrd-2.6.18-194.el5PAE.img

 As you notice from the above info, it contains kernel and initrd image.
 So, in simple terms GRUB just loads and executes Kernel and initrd images.

4. Kernel

 Mounts the root file system as specified in the “root=” in grub.conf


 Kernel executes the /sbin/init program
 Since init was the 1st program to be executed by Linux Kernel, it has the process id (PID) of 1. Do
a ‘ps -ef | grep init’ and check the pid.
 initrd stands for Initial RAM Disk.
 initrd is used by kernel as temporary root file system until kernel is booted and the real root file
system is mounted. It also contains necessary drivers compiled inside, which helps it to access
the hard drive partitions, and other hardware.

5. Init

 Looks at the /etc/inittab file to decide the Linux run level.


 Following are the available run levels
o 0 – halt
o 1 – Single user mode
o 2 – Multiuser, without NFS
o 3 – Full multiuser mode
o 4 – unused
o 5 – X11
o 6 – reboot
 Init identifies the default initlevel from /etc/inittab and uses that to load all appropriate
program.

18
 Execute ‘grep initdefault /etc/inittab’ on your system to identify the default run level
 If you want to get into trouble, you can set the default run level to 0 or 6. Since you know what 0
and 6 means, probably you might not do that.
 Typically you would set the default run level to either 3 or 5.

6. Runlevel programs

 When the Linux system is booting up, you might see various services getting started. For
example, it might say “starting sendmail …. OK”. Those are the runlevel programs, executed
from the run level directory as defined by your run level.
 Depending on your default init level setting, the system will execute the programs from one of
the following directories.
o Run level 0 – /etc/rc.d/rc0.d/
o Run level 1 – /etc/rc.d/rc1.d/
o Run level 2 – /etc/rc.d/rc2.d/
o Run level 3 – /etc/rc.d/rc3.d/
o Run level 4 – /etc/rc.d/rc4.d/
o Run level 5 – /etc/rc.d/rc5.d/
o Run level 6 – /etc/rc.d/rc6.d/
 Please note that there are also symbolic links available for these directory under /etc directly.
So, /etc/rc0.d is linked to /etc/rc.d/rc0.d.
 Under the /etc/rc.d/rc*.d/ directories, you would see programs that start with S and K.
 Programs starts with S are used during startup. S for startup.
 Programs starts with K are used during shutdown. K for kill.
 There are numbers right next to S and K in the program names. Those are the sequence number
in which the programs should be started or killed.
 For example, S12syslog is to start the syslog deamon, which has the sequence number of 12.
S80sendmail is to start the sendmail daemon, which has the sequence number of 80. So, syslog
program will be started before sendmail.

19

You might also like