Command-Line and Git.pdf
Command-Line and Git.pdf
Binary Representation
Number System
Decimal Notation
Decimal is a notation in which we have learned most of the mathematics. The unique digits used to represent
numbers in decimal notation are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
1
The decimal notation has a base of 10 which means the number of unique symbols or digits used to represent
numbers in that notation is 10.
Binary Notation
The only notation that computers understand is Binary Notation. The unique digits used to represent numbers
in that notation are 0, 1. It has base 2.
1101 = 1 x 23 + 1 x 22 + 0 x 21 + 1 x 20
2
=8+4+1
= 1310
2
Decimal to Binary Conversion
16 different types of information can be represented in 4 - bit. The numbers can be represented from 0 to 15.
3
n-Bit Binary Number
2n distinct combinations are possible.
Can represent numbers from 0 to 2n- 1.
One bit is represented for the sign, and the remaining bits represent numbers. If the bit contains zero, it
represents a positive value, and if it has one, it represents a negative number.
4
Representing Images
Image is made up of pixels. Pixel is the smallest unit in the picture. Each pixel has a specific colour.
5
Representing Colors
The colours are represented using different models. The basic one used in a lot of computers is the RGB or
red, green, and blue model.
Based on the intensity of RGB, colours are represented as a number. Now, this number is represented as
binary in computers.
Representing Text
ASCII
American Standard Code for Information Interchange(ASCII) represents the English alphabet, digits, and
punctuation marks and requires only one byte to store a character. It means it represents 256 different things.
There is a limit on no. of characters that can be represented.
6
UNICODE
UTF - 8
UTF-8 (Unicode Transformation Format - 8) is capable of storing 1,112,064 different characters and it has
the same values for ASCII characters.
7
How Computer Gets Zero's and One's
Imagine we have a light bulb and a switch that turns the state of the light on or off. If we turn the light on, we
can denote that the state is one. If the light bulb is off, we can represent the state is zero. In a similar way, the
computer gets zero's and one's.
8
Computer Hardware
Computer hardware is the physical components that a computer system requires to function. It can be categorized as having either
internal or external components.
Internal Components
Component parts that are found inside the computer's CPU case are
Motherboard
Processor & RAM
Graphics Card (GPU)
Fans
Hard Disk etc.,
External Components
External hardware components or peripherals are usually input/output devices that are
Ports
Connectors or Ports allow us to plug in different components to a computer to enhance its capabilities.
Instead of having ports for different things, we can use USB (Universal Serial Bus) Port. USB is Designed to standardize many peripheral
connections. In addition to audio and video, it allows data transfer and power. Recent mostly using USB is USB Type C which allows
charging, data transfer, extend audio, video projection, etc.
Motherboard
The motherboard is the computer's central communication's backbone connectivity point through which all components and external
components connect.
CPU
The CPU (Central Processing Unit or processor) is responsible for processing all information from programs. It processes many
instructions from different programs every second.
10
CPU Instruction Set
Programs on the computer are broken down into very small and simple instructions.
For example,
CPU will only perform small operations in binary but lakhs of these operations are done in a single second.
One of the performance matrices is clock speed which measures the number of instructions that the CPU can execute per second.
The CPU speed measured in gigahertz (GHz).
1 GHz = a Billion instructions per second
A higher clock speed means a faster CPU.
CPU Cores
A CPU core is a CPU's processor. A core can work on one task. Modern-day devices have multiple cores. 8 core processor means 8 cores
and similar to other cores. Each core of a CPU can perform operations separately from the others. They may work together to perform
parallel operations.
11
Hard Drive
The hard drive is Non-volatile storage which is responsible for storing permanent and temporary data.
SSD (Solid-state drives) is 25 times faster than regular HDDs (Hard-disk drives)
RAM
RAM is also another type of storage. we can store photos, videos, etc. The RAM is measured in GB we might have heard a lot of
times that 2GB RAM, 4GB RAM in Phones, Laptops, etc.
RAM is volatile memory means the data remains in RAM if the computer is on, but it's lost when the computer is turned off.
RAM is much faster to read and write than other types of storage.
Registers
12
Registers are another type of storage. Many times much faster than regular storage devices and even RAM which is placed very
close to the CPU.
They are extremely fast and extremely expensive.
They are available in very little storage. Usually in MBs.
They are used to quickly accept, store, and transfer data and instructions that are being used immediately by the CPU.
Running Applications
All applications and programs are stored in a hard drive. As the hard drive is slow the running applications are loaded into RAM and as
registers are faster than RAM the data required for current computation loaded to register are quickly accessible by the CPU. If the RAM
is less, we can’t store much data while running multiple programs the system gets slow.
Graphics Card
13
Graphics Card is a Specialized processor designed to deal with specific types of instructions efficiently. It is used for 3D Rendering,
Games, Deep Learning, and so on.
CPU vs GPU
CPU GPU
A CPU can perform a variety of different instructions GPU can perform a specialized set of instructions.
BIOS
Basic Input Output Services (BIOS) initializes the hardware and gets our operating system up and running.
After system power on the first BIOS tests, the hardware is working or not. you will hear a combination of beeps indicating what is
the hardware status(Having any error or not). If you didn't hear beep sounds it means there are no built-in speakers in the system.
If the test is a success then it handovers hardware to the operating system.
UEFI
UEFI (Unified Extensible Firmware Interface) is similar to BIOS, which supports the latest hardware
14
It performs a secure boot
It performs faster boot
15
Boot Process
1. Power on
2. Computers run a test to make sure all the hardware is working correctly this is called a Power On Self
Test(POST).
3. Based on the BIOS configuration, a boot device(HDD, CD, or USB) that contains OS is selected for a
program known as a boot loader which then loads the operating system.
4. Once OS gets loaded the essential part of OS Kernel16
is started and appropriately set for us to use.
OS Kernel
The Kernel is the core component of OS. As users, we don't interact with the kernel directly.
It interacts directly with the hardware.
It manages the hardware resources.
Linux Kernel
Linux is a free and open-source OS Kernel developed by Linus Torvalds.
Operating Systems made from software based on Linux Kernel are referred to as Linux Distributions (or
Linux Distros).
18
Components of OS
Userspace
Kernel
All apps interact with the kernel. The kernel will interact with hardware
Userspace
Userspace is everything outside the kernel. Programs we interact with directly are part of Userspace which are
Text Editors, Music Players, User
Interfaces, etc.
Userspace can include some OS programs like the GUI etc.
19
Responsibilities of OS
Abstraction
Abstraction means hiding the unnecessary complex inner details and showing only the relevant features. Once
the operating system is up we no longer deal with the internals. For example, consider a car driver he does need
to know how the engine works in the car. he/she simply needs to know few things like steering, gear, and so on.
Operating System abstracts away the complex deta2il0s of the underlying hardware.
Resource Management
Resource management is one of the important tasks for OS. power, memory, CPU, and so on are resources. For
example, Mobile/laptop use multiple applications at the same time like chrome, music app, chat app. These
applications required CPU, ram, GPU resources.
Multi-User System
In Laptops, computers, multiple users can access at the same time. Resource management between the apps used
by each user is the responsibility of the operating system.
Memory Management
We generally run multiple applications at a time like Whatsapp, Spotify. How much memory should be allotted
to the applications in ram is taken care of by Operating System. CPU resources are also allocated by OS.
21
Process Management
Many times, we have more running applications than the number of CPU cores. even our Chrome Window has
multiple tabs, and you can simultaneously play video in one tab, solve questions in another, Kernel continuously
switches and gives different applications to use CPU. The switching is so fast that they all seem to run parallelly.
Similarly, all of the RAM is not being used by a single app. OS kernel allocates the required amount of RAM to
each app as and when required.
Here, the time slicing concept is applied. A time slice is a very short interval of time that gets allocated to a
process for CPU execution.
CPU runs billions of instructions per second. So in the same second, let’s say, first few instructions for Word
document next few instructions for Music, similarly Web browsing and Calculator. CPU will run billions of
instructions per sec. We can't exactly see the difference this is called process management.
22
File Extensions
Files may have an extension that is used to denote the type of file.
Programs open and operate files based on the file extension.
Image & Video Extensions: .jpeg, .png, .tiff, .mp4, .mov
24
File and File Systems
The kernel handles file storage on our machines. There are three main components to handling files on an OS.
File System
File Data
File Metadata
File Data
The data of a file is broken down into pieces of data blocks of a fixed size before storing in a disk.
Default Block Size is 4 KB. So, the size occupied by a file on the disk will be in multiples of 4 KB.
Block storage improves faster handling of data because the data isn't stored on one long piece and it can be
accessed quicker. It's also better for utilizing storage space.
File Content
Text Files
Non - Text Files
Text Files
Consists of plain, unformatted words, letters, and punctuation (Unicode Characters) intended to be readable by
humans. The text files can be opened by any text editor.
The line ending character when Enter is typed is different in different Operating Systems.
Consists of non-textual data meant primarily to be read by applications that translate those content into
something useful by humans.
File Metadata
Owner of File
Permissions (Read, Write, Execute)
File Size
Creation Date Time
Last Modified Date Time
Non-Text Files 26
File Systems
Responsible for managing files on the disk.
Provides a mechanism to store the data and access the file contents including data and programs.
Case Sensitivity
Each File System has its own rules, preferences, etc. Similarly, some File Systems are case sensitive. A case-
sensitive file system distinguishes between uppercase and lowercase letters in file names and treats them as
different files.
27
Overview of Process Management
Process
Process Memory
Each process has process memory. Process Memory is divided as follows.
Stack:
It stores temporary data like function parameters, returns addresses, and local variables. The stack grows and shrink.
Heap:
Data:
It contains constants.
Text:
Process State
When a process executes, it passes through different states. These stages may differ in different operating systems.
30
New:
Ready:
Running:
The process is chosen by the CPU for execution and the instructions within the process are executed.
Waiting:
Process wait for a resource, such as waiting for user input, or waiting for a file to become available.
Terminated:
31
CPU Scheduling
Process of determining which process will own CPU for execution while another process is on hold.
The aim of CPU scheduling is to make the system efficient, fast, and fair.
Whenever the CPU becomes idle, the OS must select one of the processes in the ready queue to be executed.
The selection process is carried out by the CPU scheduler using different algorithms they are
32
CPU Scheduling Terminology
Arrival Time:
Completion Time:
Burst Time:
Turnaround Time:
Waiting Time:
Example:
P1 0 21
P2 1 3
P3 2 6
P4 3 2
33
The process p1, p2, p3, and p4 are schedule with First Come First Serve are as follows.
So, the Completion time, Turnaround time, Waiting time of the process(p1, p2, p3 & p4) are as follows.
Process Arrival Time Burst Time Completion Time Turn Around Time Waiting Time
P1 0 21 21 21 0
P2 1 3 24 23 20
P3 2 6 30 28 22
P4 3 2 32 29 27
P1 0 21
P2 1 3
P3 2 6
P4 0 2
The shortest job first scheduling for process p1, p2, p3, and p4 is as follows.
34
Priority Scheduling
Priority Scheduling Algorithm works on the process with the higher priority. Processes with the same priority are executed in an FCFS
manner.
P1 0 21 2
P2 1 3 1
P3 2 6 4
P4 3 2 3
The processes(p1, p2, p3, and p4) scheduled based on Priority Scheduling are as follows.
Example:
P1 0 21
P2 1 3
P3 2 6
P4 3 2
35
Suppose the Time Slice is 5 units and the process p1, p2, p3, and p4 are scheduled in Round Robin Scheduling are as follows.
Shared Memory
Message passing
Shared Memory
A particular region of memory is shared between the cooperating process.
Exchanging information by reading and writing data to this shared region.
Message Passing
Communication takes place by exchanging messages directly between the cooperating process.
36
Threads & Concurrency
Process Execution State
Threads
A program counter
A register set
A stack space
37
Multi-Threaded Process
Each thread can run on a separate processor, thus utilizing multiple cores of the CPU
Single-Thread Process
38
Process vs Threads
Example
Google Chrome
In Chrome, each and every tab you open gets its own content process.
Each of those processes has its own memory.
Maximizes performance
Ten tabs, 10 processes. One hundred tabs, 100 processes.
39
Mozilla Firefox
Four different processes. Multiple tabs run as threads within these processes.
Advantages of Multi-Thread
Responsiveness
Resource Sharing
Economy
Thread Concurrency
Concurrency is the execution of the multiple instruction sequences at the same time.
Advantages
Responsive applications
40
Better resource utilization & performance.
Disadvantages
Multi-threaded programs are harder to develop and can have bugs that are difficult to debug.
Example:
Let
Thread A
PYTHON
If the above operation is executing in the Thread A, and after the execution of four line of code Thread B comes with priority. So
context switching happens in middle of the bank operation.
Thread B
PYTHON
Solution
The critical section is a code segment where the shared data is operated.
Ensuring that only one process/thread can be in its critical section at a time eliminates concurrency issues.
Locks allow us to limit number of threads running the critical section at a given time. Ensure all threads have to
42
Deadlock
A situation where a set of processes are blocked because each process is holding a resource and waiting for another resource
acquired by some other process.
Deadlock Conditions
Hold and wait : A process can hold multiple resources and still request more resources from other processes which are
holding them.
No preemption : A resource cannot be acquired from a process by force. A process can only release a resource voluntarily.
Terminology
The terms Primary Memory, Main Memory & Physical Memory refer to RAM
Secondary Memory refers to storage devices, such as hard drives and solid state drives.
Memory Allocation
Ensure that each process can only access the address space allocated to it
45
Memory allocation is a process by which computer programs are assigned memory.
Contiguous Memory Allocation
A single contiguous section of memory blocks is assigned to the process according to its requirement.
46
Fragmentation
Memory is used inefficiently, reducing capacity & performance.
Types of Fragmentation:
External Fragmentation
Internal Fragmentation
External Fragmentation
Total memory space is enough to satisfy a request, but cannot be used as it is not contiguous.
Internal Fragmentation
Process is allocated a memory block of size more than the size of that process. Due to this some part of the
memory is left unused and this cause internal fragmentation.
47
Non-Contigous Memory Allocation
Paging
Segmentation
49
Paging
Logical Memory is divided into equal fixed size partitions called pages.
50
Logical Address
The generated logical address can be broken into two parts
Page Number
Page Offset
51
Different parts of the same process can be stored at different places in the main memory.
52
Page Table
Maps the page number referenced by the CPU to the frame number where that page is stored.
Paging
Frame number specifies the specific frame where the required page is stored.
Page Offset specifies the specific word that has to be read from that page
Virtual Memory
Virtual memory is a memory management technique that creates an illusion to users of larger physical
memory.
When using virtual memory, logical address is also referred as virtual address.
Moving memory of a process between Primary Memory and Secondary Memory is called Swapping
55
Demand Paging
Page referred for the first time in the main memory, then that page will be found in the secondary memory.
If a process requests for page and that page is found in the main memory then it is called page hit.
56
LRU Algorithm
It replaces the page that has not been used for the longest period of time.
LFU Algorithm
Page with the minimum no. of previous hits is selected for replacement.
57
Understanding Computer Networks
Internet
Computer network that interconnects billions of computing devices throughout the world
Billions of Users
Billions of Devices
Millions of Applications
Network Model
To reduce the complexity, networks are organized as a stack of layers.
Each layer offers certain services to the layers above it and abstracts the layers below it.
60
The header (and footer) and the data together form the PDU for the next layer. The process continues until reaching the lowest-level layer
(physical layer or network access layer), from which the data is transmitted to the receiving device. The receiving device reverses the
process, de-encapsulating the data at each layer with the header and footer information directing the operations. Then the application
finally uses the data. The process is continued until all data is transmitted and received.
Physical Layer
It represents the physical devices that interconnect computers and the technologies that develop them
Networking Cables
Wi-Fi and Cellular Hardware
Data link layer is responsible for defining a common way of interpreting signals.
Network Layer
Network Layer is responsible for getting data delivered across a collection of networks.
Transport Layer
Transport Layer is responsible for ensuring that data gets to the right process (application).
61
Application Layer
The protocols in Application Layer are used to allow you to browse the web or send receive email are some common ones.
You can think of layers like different aspects of a package being delivered. The physical layer is the delivery truck and the roads. The data
link layer is how the delivery trucks get from one intersection to the next over and over. The network layer identifies which roads need to
be taken to get from address A to address B. The transport layer ensures that delivery driver knows how to knock on your door and
deliver the package to appropriate person. And the application layer is the contents of the package itself.
62
Protocol
A protocol is a standard set of rules that allow electronic devices to communicate and understand one another.
Format of message
Order of messages
Network IP
Network Port
Network ports are generally directly attached to the devices that make up a computer network.
63
Two computers can communicate across the cable connected between them.
Hub
Transfers data to every other port connected to the hub
The System needs to determine if the incoming data was meant for them or not.
How does the system knows which data is meant for them?
MAC Address
Media Access Control (MAC) address is a globally unique identifier attached to an individual network interface (hardware).
48-bit number
00 1A 3F F1 4C C6
MAC address are same for your system no matter where you use it.
64
Data Collisions
When two computers were to send data across the wire at the same time, the data signals can interfere.
Collision Domain is a network where collisions can occur.
CSMA used to determine when the communications channels are clear and when the device is free to transmit data.
Listen-Before-Talking
Collision domain
The electrical pulses sent across the cable can interfere with each other.
Systems to have to wait for long time before they try sending their data again.
Network Switch
Switch determine which system the data is intended for and send that data to that one system.
65
Hub Switch
They operate in the physical layer They operate in the data link layer
Collisions occur mostly in setups using hubs. Less collisions occur in switch.
A network hub can't store MAC addresses. Switch stores the MAC addresses
Hub Vs Switch 66
Network Layer
IP Address
IP addresses belong to the networks, not the devices attached to those networks.
Example: 172.16.254.1
IPv4 Addressing
8 bits of data or a single octet can represent all decimal numbers from 0 to 255. This format is known as dotted decimal
notation.
IPv6 Addressing
IPv6 IP addresses are a 128 bit long numbers made up of eight groups of four hexadecimal digits,
68
IP addresses belong to the networks, not the devices attached to those networks.your laptop will always have the same MAC
address no matter where you use it, but it will have a different IP address assigned to it at an office than it would when you're
at home. The LAN at the office, or the LAN at your house would each be individually responsible for handing out an IP address
to your laptop if you power it on there.
Router
Forward data between independent networks.
Store route information for different networks all over the world.
Wireless Router
69
Router
Switch
Wireless access point (WAP): Allows other Wi-Fi devices to connect to a wired network.
Router
Network of Networks
Route
The sequence of communication links and packet switches traversed by a packet from the sending end system to the
receiving end system is known as a route or path.
70
The routers are constantly trying to balance the load across whataevere routes they know to ensure speedy and reliable
delivery which is conjunction control.
Subnetting
Subnetting is the process of splitting a large network into many smaller sub-networks or subnets
Network Efficiency
Security
Easier Management
71
Subnetting IP Address
Network ID: Used to identify the network.
IP Address 223 1 1 2
CIDR Notation
The slash notation (a.b.c.d/x) is also known as CIDR notation. It can represent an IP and a subnet mask.
CIDR 223.1.1.2/23
IP Address 223.1.1.2
We know that the octet available for host IDs can contain the numbers 0-255, but zero is generally not used and 255 is
normally reserved as a broadcast address for the subnet. This means that, really, only the numbers 1-254 are available for
assignment to a host.
223.1.1.0
223.1.1.0/24 11011111 00000001 00000001 00000000 254
to223.1.1.255
223.2.0.0
223.2.1.0/23 11011111 00000010 00000001 00000000 to223.2.1.255 510
223.3.0.0
223.3.1.0/22 11011111 00000011 00000001 00000000 to223.3.3.255 1022
Note
For warding
Basic routing has just a few steps
3. the router then looks up the destination network of this IP in its routing table.
4. the router forwards that out though the interface that's closest to the remote network. As determined by additional info within the
routing table.
5. These steps are repeated as often as needed until the traffic reaches its destination.
Routing Table
Router maintain a routing table which contain the information about where to forward the incoming packet.
73
Destination Next Hop
9.1.1.0/24 172.16.5.10
223.1.1.0/24 172.16.5.11
64.0.10.0/24 172.16.5.12
* 172.16.5.10
Destination Network : Row for each network that the router knows about. Network ID and Net Mask.
Example consider three network that data need to be sent data from computer on network A to computer on network c.the
third Network C has an address space of 172.16.1.0/23. There is a second router connecting network B and network C. It's
interface on network B has an IP of 172.16.254.8 and its interface on Network C has an IP of 121.30.56.78.
The computer at 200.23.16.100 knows that 121.30.56.100 is not on its local network, so it sends a packet to its gateway, the
router between Network A and Network B. Again, the router inspects the content of this packet. It sees a destination address
of 121.30.56.100 and through a lookup of its routing table, it knows that the quickest way to get to the 121.30.56.0/20 network
is via another router. With an IP of 121.30.56.100 The router decrements the TTL field and sends it along to the router of
172.16.254.8. This router then goes through the motions, knows that the destination IP of 121.30.56.100 is directly connected
and forwards the packet to its final destination. That's the basics of routing. The only difference between our examples and
how things work on the Internet is scale. Routers are usually connected to many more than just two networks. Very often, your
traffic may have to cross a dozen routers before it reaches its final destination. And finally, in order to protect against
breakages, core Internet routers are typically connected in a mesh, meaning that there might be many different paths for a
packet to take.
74
Hop
A hop occurs when a packet is passed from one network segment to the next.
Time to Live
The Time to Live or TTL indicates how many router hops a datagram can traverse before it reaches destination.
75
Transferring Data Over Network
The header (and footer) and the data together form the PDU for the next layer. The process continues until reaching the
lowest-level layer (physical layer or network access layer), from which the data is transmitted to the receiving device. The
receiving device reverses the process, de-encapsulating the data at each layer with the header and footer information
directing the operations. Then the application finally uses the data. The process is continued until all data is transmitted and
received.
76
Transport Layer
Processes
You might run an email program and a web browser, both client applications, on your PC at the same time, and your email and web
server might both run on the same server. Even so, emails end up in your email application and web pages end up in your web browser.
Port Numbers
A port is a 16-bit number that's used to direct traffic to specific services running on a networked computer.
Socket Address
78
IP + Port = Socket Address
Multiplexing in the transport layer means that nodes on the network have the ability to direct traffic toward many different
receiving services.
Demultiplexing is the same concept, just at the receiving end, it's taking traffic that's all aimed at the same node and delivering i
to the proper receiving service.
Header
Protocols
Protocols used in transport layer:
Packets
Sending smaller messages is more efficient than sending a large message over a network.
The sending end system breaks the data into smaller parts known as packets
Route
ANALOGY: Transportation Network
The sequence of communication links and packet switches traversed by a packet from the sending end system to the receiving end
system is known as a route or path
The routers are constantly trying to balance the load across whichever routes they know to ensure speedy and reliable delivery which
is conjunction control
80
Sequence Numbers
TCP ensure the packets reassembled in right order.
Packet Loss
Data Packets can be lost in transit over the network.
TTL Expired
Network Congestion
81
Transmission Control Protocol
TCP provides mechanisms to ensure that data is reliably delivered.
Acknowledgement
TCP protocol ensure reliable data transfer by sending acknowledgement for each message received
The acknowledgment includes the sequence number of the next expected segment.
TCP Connection
SYN (Synchronize): Used to initiate and establish a connection. It also helps you to synchronize sequence numbers between devices.
FIN (Finish): Used to terminate a connection when the transmitting computer doesn't have any more data to send.
A handshake is a way for two devices to ensure that they're speaking the same protocol and will be able to understand each other.
Data Transmission
Operation With No Loss
Once the three-way handshake is complete, the application data can begin to flow between the client and the server.
The client can send a data packet immediately after the ACK packet
When a packet of data is sent over TCP, the recipient must always acknowledge what they received.
The first computer sends a packet with data and a sequence number.
The second computer acknowledges it by setting the ACK bit and increasing the acknowledgement number by the length of the
received data.
Those two numbers help the computers to keep track of which data was successfully received, which data was lost, and which data
was accidentally sent twice.
82
Lost Packet
TCP connections can detect lost packets using a timeout.
After sending off a packet, the sender starts a timer and puts the packet in a retransmission queue.
If the timer runs out and the sender has not yet received an ACK from the recipient, it sends the packet again.
83
Premature timeout
The retransmission may lead to the recipient receiving duplicate packets, if a packet was not actually lost but just very slow to arrive
or be acknowledged.
If so, AS recipient has sequence it can simply discard duplicate packets.
85
Terminating TCP Connection: Four - Way Handshake
Internet traffic
2. Congestion Avoidance
Slow Start Phase: When connection begins increases rate exponentially(1, 2, 4, 8, 16…) until first packet loss. due to overload or
congestion that packets may be dropped. Packets lost will trigger a timeout at the sender. When this happens, the sender goes into
congestion avoidance phase
Example : first 1 packet is sent and got 1 ack , next doubles 2 packets is sent and after successful two acks it now send four packets th
process goes on until the packet got lost.
Congestion Avoidance Phase: In the Congestion Avoidance. It increase rate linearly. If congestion was indicated by a timeout, the
congestion window is reset to one segment, which automatically puts the sender into Slow Start mode.
Example: the packet was lost at 4 segments in slow start so, in congestion avoidance phase it send again 4 segments after successful
acks it increment by one and so the next it sends 5 segments . if the packet was lost. It reset with one segment it automatically puts the
sender into Slow Start mode.
86
Transmission Control Protocol
TCP vs UDP
Let's imagine that each UDP datagram is a single frame of a video. For the best viewing experience, you might hope that every
single frame makes it to the viewer, but it doesn't really matter if a few get lost along the way. A video will still be pretty watchable
unless it's missing a lot of its frames.
So, in Most video chats like skype and game streaming, video and music streaming, etc. uses UDP. That’s if you are on bad internet
connection skype get all gitchy. Not all UDP packets are delivered to your system.
But this approach doesn’t work for other application like it doesn't really work if you send an email and shows up with the middle
part missing. The whole message really needs to get there correctly.when it absolutely, correctly needs to get there programs uses
TCP ( Transmission Control Protocol)
Less Overhead
IP Addresses
Internet Assigned Numbers Authority (IANA) assigns different IP ranges to different organizations and Internet Service Providers
87
Certain range of IPs are reserved for Private Usage
Network Layer
Non-Routable Address Space
This IP address are used only internally like home network or business
NAT is a technology that allows a gateway, usually a router, to rewrite the source IP of an outgoing IP datagram while retaining the
original IP in order to rewrite it into the response.
Here, we have two networks. Network A consists of the 10.1.1.0/24 address space and network B consists of the 138.76.29.0/24
address space. Sitting between these networks is a router that has an interface on network A with an IP of 10.1.1.1 and an interface
on network B of 138.76.29.7. Computer 1 is on network A and has an IP of 10.1.1.100. And computer 2 is on network B and has an
IP of 138.76.29.100.
Computer 1 wants to communicate with a web server on computer 2.
So it crafts the appropriate packet at all layers and sends this to its primary gateway, the router sitting between the two networks.
So far, this is a lot like many of our earlier examples, but in this instance,
90
The router is configured to perform NAT for any outbound packets.
Normally, a router will inspect the contents of an IP datagram, decrement the TTL by 1, and forward the rest of the data at the
network layer without touching it.
But with NAT, the router will also rewrite the source IP address, which in this instance, becomes the router's IP on network B or
138.76.29.7. When the datagram gets to computer 2, it'll look like it originated from the router, not from computer 1.
Now, computer 2 crafts its response and sends it back to the router. The router, knowing that this traffic is actually intended for computer
1, rewrites the destination IP field before forwarding it along.
91
Application Layer
Protocols
IP Address
92
Accessing Websites
URL - Uniform Resource Locator
Every object (image, html document) has a unique path (URL) on the web server
Domain Name
93
Domain Registrars
Domain Name Registrars manage the reservation of internet domain names.
DNS Server
There are five primary types of DNS servers:
4. Caching and Recursive Name Servers are provided by ISP. These reduce the load on the root, tld, authoritative name servers.
Root Server
Any domain name registered in the DNS is a domain name.
Domain names are organized in subordinate levels (subdomains) of the DNS root domain, which is nameless.
DNS Resolution
The root servers will respond to a local DNS server with the TLD name server that should be queried like (.in). For each TLD in
existence, there is a TLD name server.
The TLD name servers will respond again to the Local DNS server with what authoritative DNS server(.ccbp.in) to contact.
The Local DNS server could be redirected at the authoritative server for ccbp.in which would finally provide the actual IP of the
server in question.
95
Recursive & Caching Name Servers
Recursive name servers are ones that perform full DNS resolution requests.
Performs a fully recursive resolution to discover the correct IP for www.facebook.com. This involves a bunch of steps we'll cover in
just a moment.
Since the domain name learning.ccbp.in had just been looked up, the local name server still has the IP that it resolved to stored and is able
to deliver that back to your computer without having to perform a full lookup.
96
DNS
DNS uses UDP for the transport layer instead of TCP.
UDP is connectionless.
A single DNS request and its response can usually fit inside of a single UDP datagram.
It provides important information about a domain or hostname, particularly its current IP address.
DNS record type allows for different kinds of DNS resolutions to take place.
A Address Mapping record A record is used to point a certain domain name at a certain IPv4 IP address.
AAAA IP Version 6 Address record A record is used to point a certain domain name at a certain IPv6 IP address.
CNAME Canonical Name record A CNAME record is used to redirect traffic from one domain to another
MX Mail exchanger record Mx record is used in order to deliver email to the correct server.
NS Name Server records It allows you to delegate the DNS of one of your subdomains to a different nameserver.
A single A record is configured for a single domain name. But, a single domain name can have multiple A records, too.
Web
Web is a "Client-Server Application".
Web Browsers.
Web Servers.
Client-Server Architecture
In a client-server architecture, there is an always-on host, called the server, which services requests from many other hosts, called
clients.
A classic example is the “Web application” for which an always-on Web server services requests from browsers running on client
hosts.
Web Servers
They host Web objects, each addressable by a URL.
98
A Web server is always ON, with a fixed IP address.
HTTP
Request & Response
The messages sent by the client usually a Web browser, are called requests.
Request
99
HTTP Method
Response
HTTP Message Format - Response
Content Length.
101
Computer Networks
Transferring Data Over Network
The header (and footer) and the data together form the Protocol Data Unit (PDU) for the next layer.
The process continues until reaching the lowest-level layer (physical layer or network access layer), from which the data is
transmitted to the receiving device.
The receiving device reverses the process, de-encapsulating the data at each layer with the header and footer information directing
the operations.
Then the application finally uses the data.
The process is continued until all data is transmitted and received.
HTTPS Protocol
HTTP Secure Protocol encrypts the data between the Browser and Server.
Graphical User Interface (GUI) commonly referred as the User Interface (UI).
What is Shell?
Shell is the software that interprets and executes the various commands that we provide.
Different Shells
104
C Shell (csh)
Z Shell (zsh)
Opening Terminal
105
For Windows Operating System
Note
Note: It is suggested to try the commands taught bash. As they will not work in Windows Powershell & Command Prompt.
106
Using Cloud
https://shell.cloud.google.com/
Bash
Commands
Listing Files & Directories
Inputs : KB , MB
1 ls --help
This Command will be helpful when you don’t know about its parameters and return type etc.
1 clear
Get User Manual for Commands
man displays the user manual of a command .
Here we pass the command as an argument.
Syntax:
1 man <command>
Example:
1 man ls
1 date
1 whoami
Previous Commands
Shell keeps track of the commands you have typed in.
Use up ( ⬆) and down ( ⬇) arrows to access the commands.
History
history display the history of the commands you have typed in so far.
By default, It shows the last 500 recent commands.
1 history 109
Bash History
1 cat .bash_history
exit
exit
to close/end a shell session.
1 exit
Summary
Command Description
Command Description
history It will show you the last five hundred commands you have entered.
System Requirements
4 GB system RAM.
BIOS-level hardware virtualization support must be enabled in the BIOS settings.
A 64-bit Windows 10, Version 1903 or higher, with Build 18363.1049 or higher.
A 15 GB free space on C: Drive after the installation of all the recent Windows Updates.
Quick Tip
To check your version and build number, select Windows logo key + R, type
Note
If you are running an older version of Windows 10, open "Settings" from your Windows menu,
navigate to "Update & Security" and select "Check for Updates". Install all available
updates and feature updates. You may need to restart multiple times in the process.
112
Setup WSL
Enable WSL Feature
Open PowerShell as Administrator and run:
Enable the Virtual Machine Platform feature. Your system will require BIOS-level hardware virtualization
support which must be enabled in the BIOS settings.
You can check whether virtualization support is enabled by checking your Task Manager.
Powershell
Download the latest WSL2 Linux kernel update package for x64 PCs
Run the update package downloaded in the previous step. (Double-click to run - you will be prompted for
elevated permissions, select ‘yes’ to approve this installation.)
Open PowerShell and run this command to set WSL 2 as the default version.
1 wsl --set-default-version 2
Powershell
1 touch filename
1 cat filename
Echo
echo
output/prints a string in the terminal.
1 echo "content"
Using > operator we can redirect the output of echo command to a file.
Renaming a File
mv renames the file names.
Syntax
115
1 mv source destination
Example:
1 mv practice.txt exam.txt
Copying Files
cp copies src_file to dest_file.
Syntax
1 cp src_file dest_file
Example:
1 cp exam.txt fun_text.txt
Deleting a File
rm removes (delete) files.
Syntax
1 rm filename
Example
1 rm exam.txt
Hidden Files
Linux, by default, hides many of the sensitive system files, in order to avoid accidental changes.
1 ls -a
Summary
Command Description
Creating A Directory
mkdir creates a directory.
1 mkdir directory_path
117
Changing the Current Working Directory
cd changes the current working directory.
1 cd directory_path
1 mkdir directory_name
1 cd ..
File Paths
There are two notations for file paths:
1. Absolute Path
2. Relative Path
Relative Path:
Home Directory
Each user in the computer is given a separate directory to work with - called home directory.
119
1 cd ~
cd (cd and space) command can also be used to switch to home directory.
1 cd
Renaming a directory
mv renames the directory name
Syntax
1 mv source destination
Example
1 mv tutorial commands
Moving a directory
mv moves files or directories from source to destination paths.
Syntax
1 mv source destination
Example
1 mv welcome.txt commands
Syntax
120
1 cp file_path directory_name
Example
1 cp welcome.txt commands
Copying Directory
cp -r can be used to copy a directory.
Syntax
1 cp -r source_path destination_path
Example
1 cp -r commands linux
Common Mistake
Raises an error if destination path have any non existing directories in between.
Deleting a Directory
rm -r removes(deletes) directories.
Syntax
121
1 rm -r directory_name
Example:
1 rm -r commands
Summary
Command Description
rm -r Deletes a directory
Text Editor
A text editor is used for editing text files.
Notepad++
Sublime Text
gEdit
Nano
Nano is an easy to use command line text editor for Unix and Linux-based operating systems.
122
Open file
1 nano filename
Updating File
Saving File
To save a file,
Exit Nano
PRESS Ctrl+X.
1 cat filename
Filtering
123
We can filter the contents of a file using the following filter commands.
head
tail
grep
head
Syntax:
Example:
1 head -2 sentences.txt
tail
Syntax:
Example:
1 tail -2 sentences.txt
Counting
Word Count
124
wc is used to find out number of lines, word count and characters count in the files.
Piping
Pipe is used to combine two or more commands
Output of one command is passed as an input to the command followed and so on.
Using ‘|’
Syntax:
Example:
Grep
Syntax:
Example:
126
1 cat sentences.txt | grep "morning"
Example 1
Number of lines that contain the word morning in the given file.
Example 2
Occurrences of the word "morning" in the given file from the lines 10 to 15
Output Redirection
127
">" takes the standard output of the command and redirects it to the file.
Syntax:
Example:
File compression is a reduction in the number of bits needed to store the data of a file.
Files are stored in such a way that, it uses less disk space than all the individual files and directories combined
Advantages of compressing files are:
gzip
zip
tar
128
tar
Compression
Syntax:
Example:
Extract/ Uncompress
Syntax:
Example: 129
1 tar -xzvf my_collection.tar.gz -C collections
zip
It is used to package all the files into one file with .zip extension
Syntax:
Example:
unzip
The unzip command extracts all files from the specified ZIP archive
Syntax:
Example:
Summary
Command Description
wc Used to find out number of lines, word count and characters count in the files
grep Searches a file or files for lines that have a certain pattern
zip Used to package all the files into one file with .zip extension
Miscellaneous Commands
Super User & File Permissions
Linux Users
The root user , also known as the superuser or administrator , has access to all commands and files.
Root User
sudo command temporarily elevates the privileges allowing users to complete sensitive tasks without logging in as the root user.
1 sudo command
Linux Commands
Executable Path
Syntax :
1 which command
Example :
1 $ which sudo
2 /usr/bin/sudo
Syntax :
132
Example :
Syntax :
Example :
1 su user
1 su -c command user
File Permissions
Authorization Levels
Multi-user operating systems like linux provide two levels of authorization in securing the files
Ownership
Permission
User Ownership
Others Any other users who doesn’t belong to the above two types
Permissions Description
Changing Permissions
Syntax :
Example :
134
1 chmod 764 sample.txt
Changing Ownership
For changing the user of a file/directory
Syntax :
Example :
135
1 sudo chown root sample.txt
Syntax :
Example :
Packaging
Package & Repository
A package file is a compressed collection of files that comprise the software package
Package Managers
apt
Syntax :
1 sudo apt
Installing Package
Syntax :
136
1 sudo apt install package_name
brew
Installing Package
Syntax :
yum
yum is a graphical based package management tool for RPM (RedHat Package Manager) based Linux systems.
Installing Package
Syntax :
1 yum package_name
wget
wget is a command-line utility for downloading files from the web.
To install
wget :
apt
brew :
137
yum:
wget will download the resource specified in the url to the current directory.
Syntax :
1 wget "URL"
Example :
1 wget "https://www.lifewire.com/uses-of-command-wget-2201085"
curl
curl is a command-line utility for transferring data from or to a server designed to work without user interaction.
To install
curl :
apt:
brew :
yum :
Syntax :
138
1 curl "URL"
Example :
1 curl "wttr.in"
Searching a Package
apt-cache command is used to searches for a particular package.
Syntax :
Example :
Updating Packages
If newer version available of the program it will update the information about the existing packages and their versions available.
upgrade
update
update will simply update the information about the existing packages and their versions available
139
Listing Installed Packages
dpkg -l : It is used to list all installed packages
1 sudo dpkg -l
Adding Repository
PPA (Personal Package Archive) is an application repository that can be used to upgrade and install packages from third parties.
Syntax :
Your Linux device can use that signature to check the authenticity of the packages.
Syntax :
Removing a Package
remove : removes the installed packages
Syntax :
Summary
Command Description
Warning
apt package from a PPA, there is a change in one of the MongoDB installation steps, due to the changes made by the
MongoDB website.
to
141
Miscellaneous Commands
Networking Commands
Network Connectivity
ping checks the network connectivity between the host and server/host.
Syntax :
Example :
1 ping google.com
Route Path
traceroute prints the route a packet takes to reach the host.
Syntax :
1 traceroute host_address
Example :
1 traceroute google.com
Network Interface
142
Ethernet
Loopback etc.
1 ifconfig
Ethernet Interface
143
Loopback Interface
Environment Setup
Environment Variables
Linux environment variables act as placeholders for information stored within the system.
Listing
env command can be used to print all environment variables.
1 env
Syntax :
1 export VARIABLE_NAME=variable_value
144
Example :
1 export CUSTOM_ENV_VARIABLE=10
Syntax :
1 echo $VARIABLE_NAME
Example :
1 echoCUSTOM_ENV_VARIABLE
1 unset VARIABLE_NAME
PATH variable holds a colon-separated list of folder paths where executables are located.
1 echo $PATH
Aliasing Command
alias is a (usually short) name that the shell translates into another name or command.
Syntax :
145
1 alias name=value
Example :
1 alias t=traceroute
2 t google.com
Un-aliasing Command
unalias removing an existing alias is known as unaliasing.
1 unalias alias_name
Persistent Variables
Environment variables defined in a shell are deleted as soon as you exit the terminal.
Editing .bashrc
Syntax :
1 export VARIABLE_NAME=variable_value
Example :
Expand
146
To immediately apply all changes in .bashrc,
use the
source command
1 source ~/.bashrc
time
Syntax:
1 time command
Example:
1 time ls
Monitoring System
top
top command is used to monitor the system's vital statistics and view the currently running processes.
1 top
Remote Operations
ssh
147
ssh (Secure Shell) is a protocol to log into another computer over a network, execute commands in a remote machine, and move
files from one machine to another.
Syntax:
1 ssh username@hostname
Example:
1 ssh user@localhost
poweroff
poweroff command is used to shut down the system.
1 poweroff
reboot
reboot command is used to reboot the system.
1 reboot
File Comparison
diff
diff command is used to find differences between two files.
Syntax:
Example:
148
1 diff text1.txt text2.txt
Getting Started with Git
Working on a Project
Managing Versions of a Document
We keep making many changes when building software or even writing anything.
Advantages of Versioning
We can quickly revert back to any of the older versions or pick up changes from an older version.
When working on a software project, we keep making changes to existing files to add new features and fix existing bugs
Collaboration
When working on a huge project with many files which is being developed by multiple people it is hard to manually keep track of
the changes.
Versioning
Version Control System simplifies tracking changes to the project and allow us switch back to any previous version.
There are several tools that help us manage versions of the source code of software.
Git
Subversion
Mercurial
Git
Git is a free, open-source and most widely used distributed version control system.
Repository
A Git Repository (Repo) is like a database which maintains different versions of the project files.
Snapshots
Git allows us to take a snapshot of our project files to create versions of the project.
Tracking Files
By default, Git doesn’t track changes to a file and doesn’t maintain versions automatically.
We have to explicitly specify git to track file changes and save versions.
151
Most of the times we want to have a selective set of changes as part of the snapshot.
Git creates a snapshot of all the changes that are part of staging area.
Untracked Files : The set of files whose changes are not tracked by Git.
Tracked Files : The set of files which are watched by Git for any changes.
Modified Files : These are the files which are modified after the latest snapshot.
Staged Files : The set of files which are about to be committed to create a new snapshot.
Committed Files : These are the unmodified files which are same since the latest commit.
Everyone has a copy of the entire repository with the entire version history.
Git Repository
There are several cloud-based repository hosting services which let you maintain a copy of repository
GitHub
Bitbucket
Create Account
152
Create Github account by visiting https://github.com
Creating a Repository
Create a new Github repository using + button at top right corner of website.
After clicking on New repository button you can see screen similar to below.
153
After creating github repository you can be able to see screen similar to below.
154
Sharing Repository
You can invite collaborators by visiting settings > Manage access and clicking on Invite a collaborator.
155
Git Client
Installing git in your system to manage & work with Git Repositories.
In Linux :
In MAC :
Configure who gets credit for the changes made from your device by setting the author details from your terminal.
To set automatic command line coloring for Git for easy reviewing.
git config -l .
Sample output :
1 user.name=User
2
3 [email protected]
4
5 color.ui=auto
Cloning Repository
git clone creates a copy of remote repository on your computer.
Cloning a repository downloads all versions of the files that ever existed to your computer.
The
.git/ folder present in the repository contains all these versions and information required for version control.
Example :
1 git remote -v
157
Sample output :
Apart from cloning a repo, you can also initialize a git repo in an existing folder.
Useful when you want to convert an existing, unversioned project to a Git repository or initialize a new, empty repository.
Syntax :
1 git init
Syntax :
Example :
Warning
git clone, git push and git pull commands with password. You need to create a personal access token and use
it for git commands instead of password. The steps to create your personal access token are mentioned in this link:
Creating a Personal Access Token
158
Staging Area & Commits
Creating a Commit
Working Directory
1 touch alice.txt
2 touch bob.txt
Making Changes
alice.txt:
1 Hi
2 What about your learning
3 Is it going good?
bob.txt:
1 Hi
2 What's your name?
Syntax :
Example :
Syntax :
Here
message provide useful information about what has changed and why.
Example :
1 git log
Sample output :
Commit Id
Commit IDs are unique strings(hashes) that are created whenever a new commit is recorded.
162
Unstaged Changes
1 git diff
Sample output :
Uncommitted Changes
git push command is used to publish new commits from local to a remote repository.
Syntax :
Warning
git clone, git push and git pull commands with password. You need to create a personal access token and use
it for git commands instead of password. The steps to create your personal access token are mentioned in this link:
Creating a Personal Access Token
You can also edit file and commit changes through github Website
163
Editing File
Commit Changes
164
Get Commit Link
165
Copy the url and share.
Pull Commits
git pull is used to pull latest commits from a remote repository to your local repository.
Warning
git clone, git push and git pull commands with password. You need to create a personal access token and use
it for git commands instead of password. The steps to create your personal access token are mentioned in this link:
Creating a Personal Access Token
166