<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Beldinemoturi on Medium]]></title>
        <description><![CDATA[Stories by Beldinemoturi on Medium]]></description>
        <link>https://medium.com/@beldinemoturi?source=rss-4511335ba1c6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*iZ8H9fVIL9AakQB2</url>
            <title>Stories by Beldinemoturi on Medium</title>
            <link>https://medium.com/@beldinemoturi?source=rss-4511335ba1c6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 05:54:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@beldinemoturi/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to: Incident report/Postmortem]]></title>
            <link>https://medium.com/@beldinemoturi/how-to-incident-report-postmortem-858d8de57d32?source=rss-4511335ba1c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/858d8de57d32</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[technical-writing]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Beldinemoturi]]></dc:creator>
            <pubDate>Fri, 17 Jun 2022 04:05:49 GMT</pubDate>
            <atom:updated>2022-06-17T04:05:49.772Z</atom:updated>
            <content:encoded><![CDATA[<p>An example of a postmortem report on a web server setup with a huge amount of failed requests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*xVbdNsgTuKyOsZPjpf6jmA.gif" /></figure><h3>Introduction</h3><p>Any software system will eventually fail, and that failure can come stem from a wide range of possible factors: bugs, traffic spikes, security issues, hardware failures, natural disasters, human error… Failing is normal and failing is actually a great opportunity to learn and improve.</p><p>After any outage, the team(s) in charge of the system will write a <a href="https://www.fiixsoftware.com/blog/4-questions-effective-technical-post-mortem/#:~:text=A%20technical%20postmortem%20is%20a,done%20to%20prevent%20future%20failures"><strong>postmortem report</strong></a> (a summary) that has 2 main goals:</p><ul><li>To provide the rest of the company’s employees easy access to information detailing the cause of the outage. Often outages can have a huge impact on a company, so managers and executives have to understand what happened and how it will impact their work.</li><li>And to ensure that the root cause(s) of the outage has been discovered and that measures are taken to make sure it will be fixed.</li></ul><h3>An example postmortem report:</h3><p>Below is an example of a postmortem report on why a web server setup featuring Nginx is doing poorly under pressure: I got a huge amount of failed requests.</p><h4>Incident Summary</h4><p>Between the time of 6:20 AM EAT and 6:30 AM EAT on 2022–06–16, roughly 50% of requests being sent to our website failed.</p><p>The event was caused by an incredibly low number configuration on the system’s ULIMIT value.</p><h4>Timeline</h4><ul><li><strong>2022–06–16, 6: 20 AM EAT:</strong> For the purpose of benchmarking, I used ApacheBench to simulate HTTP requests to our web server. I made 2000 requests to my server with 100 requests at a time.</li><li><strong>2022–06–16, 6: 25 AM EAT:</strong> To investigate the cause of the issue, I looked into the error log file and found that everything was okay.</li><li><strong>2022–06–16, 6: 27 AM EAT:</strong> I Increased the limit on Nginx worker_processes directive: Having Suspected a constriction on the maximum number of worker_processes that can spawn simultaneously: Problem still occurred but with less failed requests than before .</li><li><strong>2022–06–16, 6: 30 AM EAT:</strong> I Found that the problem was with the system’s ULIMIT value which was ridiculously low — 15; I increased it to 2000, reran the simulation with ApacheBench and problem was fixed</li></ul><h4>Root cause and resolution</h4><ul><li><strong>Cause:</strong> There seemed to have been changes made to the system’s configuration files — specifically the default Nginx configuration file on the ULIMIT value which restricted a high volume of requests to our website at a go.</li><li><strong>Fix:</strong> Increasing the ULIMIT value to a reasonable number on the /etc/default/nginx configuration file.</li></ul><h4><strong>Corrective and Preventative measures</strong></h4><ul><li>Assign and revoke the appropriate permission rights to users/ developers on our system to avoid a repeat on the same.</li><li>Changes made to configuration files can now only be done by the appropriate teams.</li><li>Install monitoring tool and on-call managing system on our server for more effective monitoring and alerting.</li></ul><h3>Conclusion</h3><p><em>For beginners, the above report is an example of a format you can use to get you acquainted with writing postmortem reports. Another format I find efficient is this </em><a href="https://www.atlassian.com/incident-management/postmortem/templates"><em>template by Atlassian</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=858d8de57d32" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Web Infrastructure Design]]></title>
            <link>https://medium.com/@beldinemoturi/web-infrastructure-design-80da33de9480?source=rss-4511335ba1c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/80da33de9480</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-infrastructure]]></category>
            <category><![CDATA[internet]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Beldinemoturi]]></dc:creator>
            <pubDate>Mon, 04 Apr 2022 16:02:57 GMT</pubDate>
            <atom:updated>2022-04-04T16:02:57.434Z</atom:updated>
            <content:encoded><![CDATA[<p>What happens when you type <a href="https://www.google.com/">https://www.google.com</a> in your browser and press ENTER</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*oB7E0eNAngGZYOoNup4B_A.jpeg" /></figure><h3><strong>Context</strong></h3><p>The <strong>Internet</strong> is basically a network of networks. At home, at work or wherever, you are probably part of a <strong>Local Area Network(LAN)</strong> that is part of the network of your <strong>Internet Service Provider(ISP)</strong>. The ISP may then connect to a larger network and become part of their network. What we end up with is a <strong>global network</strong> of billions of computers which make up the internet.</p><p>Every <strong>website</strong> on the internet has its own servers that store all the files/information for that particular website/app. Accessing information on the internet means ; through your ISP, requesting to access a particular file on a website’s servers. Along the way, there are several steps and software that your request comes across before the file is loaded on your browser.</p><h3>The client-server architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*kRwyRO_3j_5kfdKaT7SaJQ.png" /></figure><p>In this model, many <a href="https://www.britannica.com/technology/client">clients</a> (remote processors) request and receive services from a centralized <a href="https://www.britannica.com/technology/server">server</a> (host computer). In the following sections, we will explore all the hardware and software on both sides of the model, and their functionality.</p><ul><li><strong>Clients </strong>are the typical web user’s internet-connected devices (for example, your computer connected to your Wi-Fi, or your phone connected to your mobile network) and web-accessing software available on those devices (usually a web browser like Firefox or Chrome).</li><li><strong>Servers</strong> are computers that store webpages, sites, or apps. When a client device wants to access a webpage, a copy of the webpage is downloaded from the server onto the client machine to be displayed in the user’s web browser.</li></ul><h3>Server-side</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-foktr0cUMOp3ZPC6ysLPQ.png" /></figure><p>When setting up a web application, there is a collection of software that you need. This collection is called a <strong>web stack</strong>. At a minimum, this collection includes:</p><ul><li>An <strong>operating system</strong> that your servers will be built on</li><li>A <a href="https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_is_a_web_server"><strong>Web server</strong></a> to host your static content</li><li>A <a href="https://www.techtarget.com/searchdatamanagement/definition/database"><strong>database</strong></a> to store all your data</li><li>A <strong>programming language</strong>/script to help realize dynamic web applications</li></ul><p><a href="https://en.wikipedia.org/wiki/LAMP_%28software_bundle%29"><strong>LAMP</strong></a> is the most commonly used web stack.</p><h4>Web server vs Application server</h4><p>Web servers are great for doing one thing; serving up files — static web pages. If our applications use any images, HTML, .pdf or .zip files, we like to keep all of those static files on the Web server. However, web servers cannot carry out any <strong>business logic </strong>or serve <strong>dynamic content</strong> to the web pages. Examples of business logic and dynamic content include:</p><ul><li>rules for authenticating user log in</li><li>rules for executing a transaction on the website such as a purchase</li><li>Calculating values such as discounts on an order</li><li>Deciding what pages to display to a user</li><li>Deciding when to send notifications to the user</li><li>processing data stored in the database on behalf of the user</li><li>etc..</li></ul><p>This is where the<strong> application server</strong> comes in.</p><p>All of the clients’ requests go through the web server. If the request is simply to access a file (i.e display static content), the web server carries out. However, if the request requires some sort of business logic, the web server forwards the request to the application server through an <em>application server plug-in</em> on the Web server.</p><h4>The database</h4><p>Databases typically store aggregations of <a href="https://www.techtarget.com/searchdatamanagement/definition/data">data</a> records or <a href="https://searchsqlserver.techtarget.com/definition/flat-file">files</a> that contain information, such as sales transactions, customer data, financials and product information. The <strong>application server</strong> queries the database to gather necessary data and make informed business decisions.</p><h4>Load balancer</h4><p>Large organizations like Google of Facebook usually have millions of users making requests at once. As such, these organizations will typically have their web applications hosted on thousands of servers to accommodate the large incoming traffic. This is where a load balancer comes in:</p><p>A<strong> load balancer </strong>distributes the network traffic(requests from users) of an organization across multiple servers, thus ensuring that no single server bears too much demand. This in turn increases the reliability, efficiency and availability of the enterprise application or website.</p><p>There are two types of load balancers:</p><ul><li>Software load balancers</li><li>Hardware load balancers</li></ul><p>Load balancers use different types of scheduling algorithms and routing mechanisms to distribute the traffic across servers. You can learn more about this <a href="https://www.thegeekstuff.com/2016/01/load-balancer-intro/">here.</a></p><h3>Client-side</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*0jW1eQ7tvRNISmP0qZZIRQ.png" /></figure><h4>DNS(Dynamic Name System) Request</h4><pre><em>Domain Name System is like an address book for websites. When you type a web address in your browser, the browser looks at the DNS to find the website’s IP address before it can retrieve the website.</em></pre><p>Every machine on the the Internet has a unique number assigned to it, called an <a href="https://en.wikipedia.org/wiki/IP_address"><strong>IP address</strong></a>. You can look at your IP address as if it were a postal address, each one being unique and used to identify a way to reach you and only you. We need the IP addresses of each website we try to access. And because it it impossible for us to memorize each of these IP addresses, every website also has a human readable <a href="https://www.wpbeginner.com/beginners-guide/beginners-guide-what-is-a-domain-name-and-how-do-domains-work/"><strong>domain name</strong></a> associated with it.</p><p>The <a href="https://www.techtarget.com/searchnetworking/definition/domain-name-system"><strong>DNS</strong></a> is a naming database server in which internet domain names are located and translated into IP addresses. When you search for a website on the your browser using the website’s domain name, for example <a href="http://www.example.com,/">example.com,</a> the DNS maps that name to the corresponding IP address and returns that IP address to your browser. Your browser is now able to make requests directly to that website’s servers to access the services you need from them.</p><h4>How DNS works</h4><p>When you type <a href="http://www.example.com/">example.com</a> on your browser, the following steps are taken to map/resolve that domain name to its corresponding IP address:</p><ol><li>Browser check its <a href="https://www.techtarget.com/searchstorage/definition/cache"><strong>cache</strong></a>, in case the website was visited before.</li><li>Then the OS cache is checked, in case information about the website domain name and it’s corresponding IP address were stored there</li><li>When the IP address isn&#39;t found during these first two steps, the browser makes a request to the<a href="https://whatis.techtarget.com/definition/recursive-DNS-server?_gl=1*6vsf71*_ga*MzEzNTc5NzU1LjE2NDUxODc0MTM.*_ga_TQKE4GS5P9*MTY0ODQ0NzMwMS4yMC4xLjE2NDg0NDg2NzMuMA..&amp;_ga=2.33016124.342848463.1648447303-313579755.1645187413"><strong> DNS resolver</strong></a> to find the IP address of this domain name.</li><li>The DNS resolver checks its cache</li><li>If not found, the DNS makes a request to the<a href="https://en.wikipedia.org/wiki/Root_name_server"><strong> root server</strong></a>.</li><li>The root server in return redirect this request to the .COM <a href="https://en.wikipedia.org/wiki/Top-level_domain"><strong>Top Level Domain</strong></a>(TLD) server. (If the domain name of this website was <a href="http://www.example.org---the/">example.org</a>, the redirection would be to the .ORG TLD server, and so on.)</li><li>The .COM TLD then finds the <a href="https://www.dnsknowledge.com/whatis/authoritative-name-server/"><strong>Authoritative name servers</strong></a> for the domain name example.com. This DNS query is finally answered at this point in the process, with the IP address of the website’s servers. (<strong>Note</strong>: There is usually more than one <strong>name server</strong> attached to any domain, depending on the services that the website offers e.g website, email, etc…)</li><li>The DNS resolver returns this IP address to your browser after which your browser is able to make a <strong>http/https request</strong> to that specific IP address server, and the server returns a <strong>http response</strong> with the information you requested.</li></ol><h4>HTTP and HTTPS request</h4><pre><em>HTTP defines a </em><strong><em>language</em></strong><em> for clients and servers to communicate with each other.</em></pre><p><strong>Hyper Text Transfer Protocol</strong> (<strong>HTTP</strong>) is the <a href="https://www.techtarget.com/searchnetworking/definition/protocol"><strong>protocol</strong></a> over which data is sent between your browser and the website that you are connected to. HTTP is a request-response protocol. It gives users a way to interact with web resources such as HTML files by transmitting hypertext messages between clients and servers. .</p><p><strong>Hyper Text Transfer Protocol Secure</strong> (<strong>HTTPS</strong>) is the secure version of HTTP. Secure in this case means all communications between your browser and the website are encrypted. Secure communications are sometimes needed to protect highly confidential online transactions like online banking and online shopping order forms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*PT8DKIzVTjxt8n31kUz5yg.png" /></figure><p><strong>How does HTTPS work?</strong></p><p>HTTP pages use the <strong>Secure Sockets Layer(SSL)</strong> protocol to encrypt communications. SSL uses the ‘asymmetric’ Public Key Infrastructure (PKI) system. An asymmetric system uses a ‘public’ key and a ‘private’ key to encrypt communications. Anything encrypted with the public key can only be decrypted by the private key and vice-versa.</p><p>When you request a HTTPS connection to a webpage, the website initially sends its<a href="https://www.kaspersky.com/resource-center/definitions/what-is-a-ssl-certificate"> <strong>SSL certificate</strong></a> to your browser. This certificate contains the public key needed to begin the secure session. Based on this initial exchange, your browser and the website then initiate the <a href="https://www.ibm.com/docs/en/ibm-mq/7.5?topic=ssl-overview-tls-handshake"><strong>‘SSL handshake’</strong>.</a> The SSL handshake involves the generation of shared secrets to establish a uniquely secure connection between yourself and the website.</p><p>HTTP clients generally use <a href="https://www.extrahop.com/resources/protocols/tcp/"><strong>Transmission Control Protocol (TCP)</strong></a> connections to communicate with servers.</p><h4>Transmission Control Protocol/Internet Protocol(TCP/IP)</h4><pre><em>TCP/IP are </em><strong><em>communication protocols</em></strong><em> define how data should travel across the internet.</em></pre><p>The TCP/IP is a set of rules and procedures that govern how devices are interconnected in a network. These rules identify how data being transmitted over a network should be broken into <a href="https://www.techtarget.com/searchnetworking/definition/packet">packets</a>, addressed, transmitted, routed and received at the destination.</p><p><strong>TCP</strong> defines how applications can create channels of communication across a network. It also manages how a message is assembled into smaller packets before they are then transmitted over the internet and reassembled in the right order at the destination address</p><p><strong>IP</strong> defines how to address and route each packet to make sure it reaches the right destination. Each gateway computer on the network <a href="https://www.techtarget.com/searchnetworking/answer/What-should-I-know-about-IP-address-management-systems">checks this IP address</a> to determine where to forward the message.</p><h3>Some other important Technologies</h3><h4>Firewall</h4><p>A firewall is a network security device that manages traffic passing between a private network and an outer network(e.g the internet). A firewall is implemented through either <a href="https://www.webopedia.com/definitions/hardware/">hardware</a> or <a href="https://www.webopedia.com/definitions/software/">software</a>. The firewall monitors incoming and outgoing network traffic and decides whether to allow or block specific traffic based on a defined set of security rules on the hardware or software. A firewall is also useful for allowing remote access to a private network through secure <a href="https://www.webopedia.com/definitions/authentication/">authentication</a> certificates and logins.</p><h4>Web Stack Monitoring</h4><p>In any efficient network system, there are software and hardware tools that track various metrics of the network and its operation(e.g such as traffic, bandwidth utilization, and uptime). These tools record computer metrics, and emit an alert if something unusual or that could make the computer not work properly, happens.</p><p>Web stack monitoring can be broken down into 2 categories:</p><ul><li><em>Application monitoring</em>: that gets data about <strong>your running software</strong> and makes sure it is behaving as expected</li><li><em>Server monitoring</em>: that gets data about <strong>your virtual or physical server </strong>and makes sure they are not overloaded (could be CPU, memory, disk or network overload)</li></ul><h3>So what happens when you type https://www.google.com and press ENTER?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*kt_JugH1Qu1nob0i7SkyXw.png" /></figure><p>In conclusion, when you type <a href="https://www.google.com/">https://www.google.com</a> in your web browser, the following steps will be taken to serve you the page requested:</p><ol><li><a href="#9ff5"><strong>DNS request</strong></a>: The browser makes a request to the DNS resolver to map the domain name (www.google.com) to its corresponding IP address. (recap on the steps taken to resolve this <a href="#9ff5">here</a>). The DNS resolver then returns this IP address to your browser for your browser to make the https request directly to the servers for this web page.</li><li><a href="#a311"><strong>HTTPS request to the server</strong></a>: The browser sends a http request to the server, using the TCP/IP protocol to communicate with the server. <strong>Note</strong>:When communicating via the Internet, the TCP/IP protocol establishes the connection, compiles data packages again after transfer, and then hand them over to the programs addressed on the recipient’s device. For this handover to work, the operating system must create entrances and open them for the transfer. <strong>Every entrance has a specific code number(</strong><a href="https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers"><strong>port numbers</strong></a><strong>). </strong>By default, the port numbers for http connections is <strong>80</strong> and for https connections is <strong>443</strong>. In our case, our request is a https request, so it will hit the google servers on port 443 and google will respond to our browser on the same port: 443.</li><li><a href="#3585"><strong>The firewall</strong></a>: Our request hits Google&#39;s firewalls which will determine whether to allow this traffic or not(in the case of a malicious request).</li><li><a href="#8db3"><strong>Load balancers</strong></a>: Google’s load balancers redistributes our request(along with millions of others that it gets every minute) to one of its many servers.</li><li><a href="#3131"><strong>Web server</strong></a>: Our request is for google.com landing page. This is a simple static webpage. When the request hits the web server, it will be packaged into a HTTPS response and sent back to our web browser. The https response will contain a header and body. The header contains metadata and the body contains the content that the browser will display.</li><li><a href="#3131"><strong>Application server</strong></a>: If our request was to display dynamic content or involved some sort of business logic (for example; if we needed to log in to an account or carry out a transaction online), the web server would communicate to the application server to execute this request. The application server, in turn, if need be, would communicate the the <a href="#2888"><strong>database</strong></a> to retrieve any data required on the webpage. (e.g retrieving product information for an online transaction). A https response is sent back to the web browser.</li></ol><h3>The End.</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80da33de9480" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The OSI Model Explained]]></title>
            <link>https://medium.com/@beldinemoturi/the-osi-model-explained-f9c132fc5b99?source=rss-4511335ba1c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9c132fc5b99</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[systems-engineering]]></category>
            <category><![CDATA[web-infrastructure]]></category>
            <dc:creator><![CDATA[Beldinemoturi]]></dc:creator>
            <pubDate>Tue, 22 Mar 2022 21:12:31 GMT</pubDate>
            <atom:updated>2022-03-22T21:12:31.797Z</atom:updated>
            <content:encoded><![CDATA[<p>How data transfers over the network from one computer to the other</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*wfxWv6wOjoZ09bZd5SqCGw.png" /><figcaption>OSI model illustration</figcaption></figure><h3>Background context</h3><p>The working of the internet can be summarized into one rudimentary statement: Computers in a <a href="https://www.javatpoint.com/types-of-computer-network"><strong>network</strong></a> communicating (i.e sending and receiving information/data) with each other back and forth. Now, different computers have different underlying logic in their software and hardware. In addition to that, there are several complex processes involved when information is passed from one computer to another over a network. This is where the <strong>OSI (Open Systems Interconnection)</strong>model comes into play:</p><ul><li><em>Definition</em>: The <strong>OSI model</strong> is a standardized, theoretical/conceptual reference model describing how computer networks operate; i.e how information from a software application on one computer is transferred to the software application in another computer over a network.</li><li><em>Purpose</em>: The OSI model facilitates communication between different systems without requiring changes to the logic of their underlying software and hardware.</li><li>Layers: The OSI model consists of<strong> 7 layers</strong>. Their purpose is to break down the processes of a computer network into more manageable components.</li></ul><p>To understand how computers in a network communicate, we need to go through the 7 layers of the OSI model one by one:</p><h3>Layers of the OSI Model</h3><p>Each layer is a package of <a href="https://www.techtarget.com/searchnetworking/definition/protocol"><strong>protocols </strong></a>that computers on both sides of a communication exchange must accept and follow in order to make the communication work properly. In networking, support these protocols can be built into software, hardware or both.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*iMkzV-eYGsVBzX71el_UQQ.png" /></figure><h4><strong>Layer 7: The Application layer</strong></h4><p>This layer includes application layer protocols that are needed to make various Network applications work correctly in the internet.</p><p>There are dozens of application layer protocols that form the basis for various network services. A few of these include:</p><ul><li>To transfer files over the internet — File Transfer Protocol(FTP)</li><li>Web surfing — HyperText Transfer Protocol(HTTP/s) protocol</li><li>Sending emails — Simple Mail Transfer Protocol(SMTP)</li><li>etc.</li></ul><h4>Layer 6: Presentation layer</h4><p>The presentation layer receives data from the application layer and formats it in a way that the receiving application can understand it.</p><p>The presentation layer is also responsible for encrypting data. It uses the <strong>Secure Sockets Layer protocol(SSL)</strong> to encrypt the data, thus preventing it from being interpreted in the event that it is intercepted by a malicious user on the network. At the receiver’s end, when the data gets to this layer, it is decrypted using the same protocol.</p><p>The presentation layer also compresses the data — -i.e reduces the number of bits used to represent the original data. Doing so reduces the amount of space used to store the data hence data transmission can be faster.</p><h4>Layer 5: Session layer</h4><p>The session layer is responsible for establishing, maintaining and terminating connections between computers in a network. It uses different <a href="https://www.mulesoft.com/resources/api/what-is-an-api"><strong>APIs</strong></a> that make it possible to connect to another computer in a network.</p><p>When establishing a connection to another computer, the session layer determines some exchange parameters that will be used during the connection. For example; what <a href="https://www.sciencedirect.com/topics/computer-science/registered-port"><strong>UDP port number</strong></a> will be used, method of encoding, etc.</p><p>In the case of maintaining connections, the session layer ensures that a connection is re-established if it drops during transmission.</p><p>And finally the session layer terminates the connection after communication is completed.</p><h4><strong>Layer 4: Transport layer</strong></h4><p>The transport layer controls the reliability of communication through:</p><ul><li><em>Segmentation</em>: The transport layer receives data from the session layer and divides it into smaller data units called <strong>segments</strong>. Each segment contains a source and destination <strong>port number</strong> — which helps to direct the segment to correct app on the receiver’s end — and a sequence number — which helps to rearrange the segments in the correct order to form the correct message at the receiver’s end.</li><li><em>Flow control</em>: Transport layer controls the amount of data being transmitted depending on the difference in speed at which devices can transport(source device) and receive(destination device) data — to maintain system performance.</li><li>Error control: For example; in the event that some data does not arrive at the destination.</li></ul><p>There are two types of transmission protocols associated with the transport layer:<br><strong>1. Transmission Control Protocol() TCP</strong></p><p>This is a connection-oriented transmission which provides feedback whether data was really delivered hence lost data can be retransmitted. This protocol is used where full data delivery is a must for example; email, file transfer etc.</p><p><strong>2. User Datagram Protocol(UDP)</strong></p><p>This is a connectionless transmission which is faster than TCP because it does not provide any feedback. This protocol is used in situations where it does not matter whether we have received all data; e.g when transmitting voice or video packets over a network in the case of online streaming services.</p><h4>Layer 3: Network layer</h4><ul><li>This is the layer responsible for logical addressing: The network layer receives data segments from the transport layer and assigns <a href="https://www.networkworld.com/article/3588315/what-is-an-ip-address-and-what-is-your-ip-address.html"><strong>IP addresses</strong></a> to each segment to form a <strong>packet</strong>. — Ensures that each packet reaches the correct device it was intended for on the network.</li><li>This is also the layer where <strong>routers</strong> operate: The network layer is also responsible for <strong>routing</strong> — A method of moving data packets from source to destination based on the logical address format in IP addressing.</li><li>Path determination: A computer can be connected to another in a network in a number of ways. Layer 3 devices use different protocols to determine the best path for data delivery from source to destination based on these different connections.</li></ul><h4>Layer 2: Data Link layer</h4><p>The data link layer has two main functions:</p><ol><li><em>Allow upper levels of the OSI model to access media(in this case media refers to ethernet cables, fiber optics or air) through </em><strong><em>Framing:</em></strong></li></ol><p>The data link layer receives data packets from the network layer and then it adds <strong>physical addressing</strong> to the packet to form a <strong>frame.</strong> Every computer has a <a href="https://www.tutorialspoint.com/what-is-network-interface-card-nic"><strong>Network Interface Card(NIC)</strong></a>. Each card is embedded with a<strong> </strong><a href="https://en.wikipedia.org/wiki/MAC_address#:~:text=A%20media%20access%20control%20address,Wi%2DFi%2C%20and%20Bluetooth."><strong>MAC address</strong></a> — a 12 digit alphanumeric number that uniquely identifies it. The data link layer adds this MAC address to data packets to identify where that specific packet will be sent to.</p><p><em>2. Control how data is placed and received from media:</em></p><p><strong>Media Access Control</strong>: Data link layer uses this technique — a specific protocol to determine how a <strong>frame</strong> gets on and off media. How is this useful? Well, as an example; when multiple computers connected to the same network send data at the same time, the Media Access Control protocol eliminates the possibility of collision between these various messages/data in the network. There are various media access control methods/protocols available. Check them out<a href="https://www.getkisi.com/blog/media-access-control"> here.</a></p><h4>Layer 1: Physical layer</h4><p>This layer is concerned with the actual physical connection between devices.</p><p>The Physical layer receives data from the data link layer in <strong>Bits</strong> — a sequence of Binary 1s and 0s. It then converts these bits to signals depending on the type of media used to connect the devices in that particular network, i.e:</p><ul><li>Electrical signals in the case of copper/LAN cables</li><li>Light signals in the case of fiber optic cables</li><li>Radio signals in the case of Air</li></ul><p>These signals then physically travel across these media to the desired computer at the other end of the communication exchange.</p><p>Now remember how each layer is a package of protocols? This applies to the physical layer as well — for example; one device that is associated with the physical layer is a RJ45 connector. Now the way wires are connected in the RJ45 connector, i.e the color coding, is based on a standard — a protocol that must be followed by all computers on a network in order for transfer of data between them to work. Besides this, there are several other protocols that define how signals in this layer are sent and received between devices.</p><p><strong>Receiver</strong></p><p>At the receiver:</p><ul><li>Physical layer receives signals from the sender through the media(ethernet cables, etc..)</li><li>Converts these signals to bits and passes it to the data link layer as a frame</li><li>This frame is further decapsulated as data moves to upper layers.</li><li>When the data gets to the application layer, application layer protocols make the sender’s message visible in the apps in the receiver’s computer screen.</li></ul><h4>Conclusion</h4><p>The OSI model is only a guideline. While many protocols fit neatly into one of the seven layers, others overlap various layers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9c132fc5b99" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How the Unix Shell Interprets and Executes Commands]]></title>
            <link>https://medium.com/@beldinemoturi/how-the-unix-shell-interprets-and-executes-commands-fc3351de0802?source=rss-4511335ba1c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc3351de0802</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[shell]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Beldinemoturi]]></dc:creator>
            <pubDate>Wed, 01 Dec 2021 09:20:34 GMT</pubDate>
            <atom:updated>2021-12-01T09:20:34.007Z</atom:updated>
            <content:encoded><![CDATA[<h4>How the Shell reads input from users, searches for commands and executes them</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7sw18xTgnFd6iatv" /><figcaption>Photo by <a href="https://unsplash.com/@florianolv?utm_source=medium&amp;utm_medium=referral">Florian Olivo</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>When you type commands on the terminal, how does the shell interpret you commands and know exactly which commands to execute? What is happening behind the scenes? If you have asked yourself these questions before, the this article should interest you as we dissect the processes happening behind the scenes when a command is being executed in the shell.</p><h3>What you will need</h3><p>In order to understand and follow along in this tutorial, you will need the following:</p><ul><li>Know how to program in C</li><li>Have interacted with the terminal and have basic knowledge and experience with simple shell commands.</li><li>A working GNU/Linux system</li><li>GCC to compile your code</li><li>A text editor to write your code in</li></ul><h3><strong>Introduction</strong></h3><h4><strong>What is the Shell?</strong></h4><p>The Shell is an interface between a computer user and the kernel . More specifically, the shell is a command line interpreter; it reads and interprets the commands that you type in and arranges for them to be executed. When you log in to your system, the shell is automatically started and we interact with it through the terminal- which is where we type in our commands.</p><h4><strong>How does the shell work</strong></h4><p>If you have interacted with the shell before, typing in basic commands and seeing what they do, then you can begin to break down the inner workings of the shell into a basic structure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VKJBF4WhQV1aHZLSDp8iUA.png" /></figure><p>Before we dive into the steps in this process, there are a few concepts we need to understand:</p><p><strong>What is a command</strong></p><p>From the user’s point of view, a command is anything you type into the terminal window, terminated by a new line. From the system’s point of view, a command is this input given by the user. Commands are themselves programs or executable files stored somewhere in the system; and when a user types something in the command line, the system looks for a matching executable file to run.</p><p><strong>The environment and PATH</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/0*a6RP9LkEZfPD7HJX.png" /><figcaption>Image from <a href="https://medium.com/@kidusmik">this</a> article</figcaption></figure><p>In Unix and Unix like systems, the <a href="https://ostoday.org/android/quick-answer-what-is-a-unix-environment.html">environment</a> is defined by environment variables. Environment variables are a set of dynamic named values in the format, “NAME=Value” as shown above, stored within the system and are used by applications launched in shells or subshells. Some environment variables are set by the system, others by you, and some by the shell or any program that loads another program.</p><p>The environment variable that we are most interested in for this article is the <a href="https://www.ibm.com/docs/en/aix/7.1?topic=accounts-path-environment-variable">PATH</a>. This variable contains a list of directories as shown below. The path specifies the list of directories to be searched to find a command.</p><h3><strong>What happens when you type ls -l *.c in the shell?</strong></h3><p>To demonstrate the behind the scenes workings of the shell, we will look at this simple command <em>ls -l *.c</em> and see how the command is executed, following the steps illustrated in the diagram we looked at earlier.</p><h4><strong>step 1: Display prompt</strong></h4><p>When you log into the terminal, the first thing you see is the prompt and it’s basically an input field in the terminal which lets you input commands.</p><pre>~/simpleshell$</pre><h4><strong>step 2: Fetching and parsing user input</strong></h4><p><strong>Fetching</strong></p><p>Once you type in your commands after the prompt and hit enter, the shell reads what you entered and stores this information. To do this, we’ll look at a function called <a href="https://man7.org/linux/man-pages/man3/getline.3.html"><strong>getline()</strong></a><strong>.</strong></p><pre><strong>ssize_t getline(char **restrict </strong><em>lineptr</em><strong>, size_t *restrict </strong><em>n</em><strong>,</strong><br>                       <strong>FILE *restrict </strong><em>stream</em><strong>);</strong></pre><p><em>lineptr</em>: is the buffer that stores your input</p><p><em>n:</em> is the size of the buffer</p><p><em>stream:</em> specifies where to read input from, and in our case, that’s the standard input.</p><p>In our case, the whole line <em>ls -l *.c</em> is read and stored in lineptr. In practice the whole function might look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a887ff223267693c6e8afb0de69fd695/href">https://medium.com/media/a887ff223267693c6e8afb0de69fd695/href</a></iframe><p><strong>Parsing</strong></p><p>In our command: <em>ls -l *.c</em>, the first part, ‘ls’ is the actual command, the ‘-l’ are the options we cant our command to be run with, and *.c is the argument to out command. To identify these parts of a command, the shell splits our input into individual words or <strong>tokens</strong>, separated by spaces. To do this, we’ll look at a function called <a href="https://man7.org/linux/man-pages/man3/strtok_r.3.html"><strong>strtok()</strong></a></p><pre><strong>char *strtok(char *restrict </strong><em>str</em><strong>, const char *restrict </strong><em>delim</em><strong>);</strong></pre><p>This function breaks the string specified in <strong>str</strong> into a sequence of zero or more non-empty tokens. The <strong>delim</strong> argument specifies what character will be use to separate the string <strong>str</strong>, in our case, the space which separates one word from the next in our input. A simple implementation of this would look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a2b503709a5a260c5f8f1b69f0a8f11/href">https://medium.com/media/3a2b503709a5a260c5f8f1b69f0a8f11/href</a></iframe><p>In our first function <strong>word_count()</strong>, we start by counting the number of words in our input string. In the second function <strong>split_string()</strong>, we allocate memory for an array of pointers to store each token split from the input string, based on the number of words we got. We then go ahead to split the string by the first token, which will be ls in our case, store that string in the first pointer in our array, and then initialize a loop to repeat this process, storing the subsequent tokens in the subsequent pointers in our array, until no more tokens are left, i.e token == NULL.</p><h4><strong>step 3: Finding the command</strong></h4><p>As we said earlier, the PATH variables stores a list of directories that are searched when looking for a command entered by a user. We would use the ‘ stat() <a href="https://en.wikipedia.org/wiki/System_call#:~:text=In%20computing%2C%20a%20system%20call,on%20which%20it%20is%20executed.&amp;text=System%20calls%20provide%20an%20essential,process%20and%20the%20operating%20system.">system call</a> to check whether the command exists.</p><pre><strong>int stat(const char *restrict </strong><em>pathname</em><strong>,</strong><br>                <strong>struct stat *restrict </strong><em>statbuf</em><strong>);</strong></pre><p>What we are most interested in in this function is the return value, if a file does not exist, -1 is returned. And so we can use this information to check whether a command entered by a user exits in the PATH directories or not, as shown below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c01df0a97f4db59ab1a2852508a26e8/href">https://medium.com/media/3c01df0a97f4db59ab1a2852508a26e8/href</a></iframe><p>In the first function <strong>getPATH()</strong>, we access the environment variables of our system using the external variable environ. We the access the PATH variable specifically and store each directory listed in PATH in an array .</p><p>In the second function <strong>get_abs_pathname()</strong>, is where we check for existing commands using stat(). We start by accessing each directory we got from the getPATH function, one by one, and each time, we append the command entered by the user to that directory, and the use the stat() system call to check if the command exists in that directory. If it does not, we go to the next directory and do the same until we have exhausted our list of directories.</p><h4><strong>step 4: Executing the command</strong></h4><p>After an executable file matching the keyword entered by the user has been found, the last step is to run that file and hence, execute the command. To do this, we would have to call these system calls;<a href="https://man7.org/linux/man-pages/man2/fork.2.html"><strong> fork()</strong></a>, <a href="https://man7.org/linux/man-pages/man2/execve.2.html"><strong>execve(),</strong></a> <a href="https://man7.org/linux/man-pages/man2/wait.2.html"><strong>wait()</strong></a><strong>.</strong></p><pre><strong>pid_t fork(void);</strong></pre><pre><strong>int execve(const char *</strong><em>pathname</em><strong>, char *const </strong><em>argv</em><strong>[],</strong><br>                  <strong>char *const </strong><em>envp</em><strong>[]);<br>pid_t wait(int *</strong><em>wstatus</em><strong>);</strong></pre><p>To demonstrate this in practice:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/538f580f9cff08850c2802438b64410a/href">https://medium.com/media/538f580f9cff08850c2802438b64410a/href</a></iframe><p>We start by creating a new<a href="https://en.wikipedia.org/wiki/Process_(computing)#:~:text=In%20computing%2C%20a%20process%20is,by%20one%20or%20many%20threads.&amp;text=Depending%20on%20the%20operating%20system,execution%20that%20execute%20instructions%20concurrently."><strong> process</strong></a> using fork(). In this new <a href="https://en.wikipedia.org/wiki/Child_process#:~:text=From%20Wikipedia%2C%20the%20free%20encyclopedia,subprocess%20or%20traditionally%20a%20subtask."><strong>child process,</strong></a> we the call the <strong>execve()</strong> system call, and pass the pathname we got from the <strong>get_abs_pathname()</strong> function as the first argument to execve, the list of words the user input at the second argument to this function and NULL as the third. Basically, using <strong>execve,</strong> we tell the system to execute the command specified in its first argument, with the list of options and arguments specified in its second argument and with no environment variables(NULL).</p><p>Lastly, in the parent process, we use the <strong>wait()</strong> system call to tell the system to wait for any child processes that are running to complete before continuing with the rest of the program in the parent process.</p><p>Output of command: <strong><em>ls -l *.c</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/0*dWk3nbB7tsKm_nLN.png" /><figcaption>Image from<a href="https://medium.com/@kidusmik"> this Article</a></figcaption></figure><p>The shell runs in a loop, i.e after executing a command, the prompt is displayed again until the user enters the exit as a command or ^C to exit the shell.</p><p><strong>And this concludes our simple overview or how the shell interprets and executes commands entered by the user.</strong></p><p>For practice, I challenge you to try and build your own Simple version of the Shell and try running simple commands on it. Happy coding!</p><p><em>To see the full list of functions and implementations highlighted in this articles, go to</em><a href="https://github.com/wanjaeliud/simple_shell"><strong><em> this</em></strong></a><em> GitHub repo.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc3351de0802" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>