<?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 ghassenehedfi on Medium]]></title>
        <description><![CDATA[Stories by ghassenehedfi on Medium]]></description>
        <link>https://medium.com/@3681?source=rss-5729a8fdfd59------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Rb_EY9l2YOcPeDEE</url>
            <title>Stories by ghassenehedfi on Medium</title>
            <link>https://medium.com/@3681?source=rss-5729a8fdfd59------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 06:47:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@3681/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[Portfolio Project Blog post]]></title>
            <link>https://medium.com/@3681/portfolio-project-blog-post-98f8c12ee9ea?source=rss-5729a8fdfd59------2</link>
            <guid isPermaLink="false">https://medium.com/p/98f8c12ee9ea</guid>
            <dc:creator><![CDATA[ghassenehedfi]]></dc:creator>
            <pubDate>Mon, 04 Jul 2022 14:47:03 GMT</pubDate>
            <atom:updated>2022-07-04T14:47:03.678Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n9lQ_p-Lp2uqNloUVr0vqw.png" /></figure><p>The purpose of the project :</p><p>Our project ( sponsosite ) is a website designed to connect podcasts influencers, content creators and similar people/organization with companies looking for sponsorship marketing opportunities</p><p>Team members, Roles :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*tmQL_-sHGGEvL74IbRRu3A.png" /></figure><p>Timeline:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/1*2DsmSdiAfbf4kWivM_QkBw.png" /></figure><p>This Project is created for the companies who needs sponsorship and for people and infuluencers who need sponors</p><ul><li>My personal focus was on the Back-end and the Design of this website</li></ul><h3>Tell a story about yourself which relates to why you chose to work on this project!</h3><p>I chose to work on this project because it was an idea since 1 year ago</p><p>I used to be a member of clubs ( tunivision ) in the dep of sponsoring so all my focus was there back at University, we used to participate in events for organizations. We used to struggle with finding sponsors for our events and we wasted a lot of time.</p><p>This is how the idea of <strong>SPONSOSITE </strong>was inspired.</p><p>And this is why i choosed this project</p><h3>Summarize what you’ve accomplished with your project</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*0ijtcHJxK1GLlnBD688Vww.png" /></figure><p>HTML, JAVASCRIPT, PHP, BOOTSTRAP: because it was very simple and easy to manipulate</p><p>PHP, MYSQL: because i didn’t have much time to learn a new languages so php and mySQL was the easiest way to finish some of the Backend</p><p>features : the website is compatible with Mobiles, This means users can access the project from a mobile view!</p><p>Not a feature : The project does not have a full backend.</p><h3>Write about your most difficult technical challenge in depth</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*3mUHOLxmZGrHKViNJcNI_A.png" /></figure><p>The most difficult technical challenge that we succeeded in solving it was the connection of HTML to database with MySQL using PHP it was really hard to be honest</p><p>we started by using xamp and some youtube videos that helps me a lot to find a solution of my problem</p><p>also the animation of the front-end was really hard to solve it and to found a solution to make it happen</p><h3>Share what you’ve learned</h3><p>I learned a lot to be honest</p><p>1- I learned some new languages</p><p>2- I learned how alarge project can be divided between members of the team into small tasks.</p><p>3- Time management</p><p>4- Working with multiple languages</p><p>5- React was really hard but to be honest if we learn it we can have a chance to finish our project so fast</p><p>6- Testing and debugging skills</p><p>7- Learn something new</p><h3>Add a short paragraph about yourself after the concluding paragraph</h3><p><em>I would describe myself as positive, self-sufficient, supportive of other people, passionate about my work, and someone who can be relied upon to help a business achieve its commercial goals</em></p><p>GitHub link for the project : <a href="https://github.com/Ghassenhedfii/Portfolio-P">https://github.com/Ghassenhedfii/Portfolio-P</a></p><p>Link to your LinkedIn profile : <a href="https://www.linkedin.com/in/hedfi-ghassen-311302222/">https://www.linkedin.com/in/hedfi-ghassen-311302222/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98f8c12ee9ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Happens When You Type google.com Or Any Other URL In Your Browser And Press Enter]]></title>
            <link>https://medium.com/@3681/what-happens-when-you-type-google-com-or-any-other-url-in-your-browser-and-press-enter-5e46e5cfa957?source=rss-5729a8fdfd59------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e46e5cfa957</guid>
            <dc:creator><![CDATA[ghassenehedfi]]></dc:creator>
            <pubDate>Sun, 08 May 2022 22:12:48 GMT</pubDate>
            <atom:updated>2022-05-08T22:19:56.541Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hokWmzD4TALGq3Ev" /></figure><h3>Introduction</h3><ol><li>As soon as we enter the web address name(<a href="http://google.com/">Google</a>) in our browser (chrome) and press enter the browser will send this web address name i.e(Domain name) to the <strong>ISP</strong>(internet service provider like airtel , hatway etc) asking for the <strong>IP address</strong> of the webpage.</li></ol><p>2. Since ISP doesnt have the IP address it will in turn send a request to <strong>DNS</strong>(<strong>Domain Name Server</strong>) asking for the IP address. DNS will search for the IP address mapped with the webpage and will return that to the ISP who in turn will return it to the browser.</p><p>3. Browser now will dial in the IP address of the particular website and this will directly send request from your system to web page server(google server) through your ISP where the google server will send you back the required information to display on your browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/0*UU9C-IeZXKzo0VNe" /></figure><p>Nowadays in the digital era, we use the internet for just about everything. We can study, connect with our friends and relatives through social media, play online games with people all over the world, listen to music and watch funny cat videos, share your presentations with your coworkers, have business meetings through video conferencing sites, etc.</p><p>Ever since the internet became available to everyone, many people have wondered exactly how we can go from the comfort of our own houses, to just about anywhere in the world with just one click. For years that has been a question, that for many, has remained a mystery. In this article, I want to take you a step further into what happens when you type any URL in your web browser and press enter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VAMqdpzmaDZ8K9gBzQ4SBg.png" /></figure><h3>Beginning Concepts</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*-9Eph_aLnu-SoZ6ZwqMwpg.jpeg" /></figure><p>Before getting started, I want to first explain what a webpage is. A webpage is basically a text file formatted a certain way so that your browser (ie. Chrome, Firefox, Safari, etc) can understand it; this format is called HyperText Markup Language (HTML). These files are located in computers that provide the service of storing said files and wait for someone to need them to deliver them. They are called servers because they serve the content that they hold to whoever needs it.</p><p>These servers can vary in classes, the most common and the one that we’ll be talking about in the main portion of this article is a web server, the one that serves web pages. We can also find application servers, which are the ones that hold an application base code that will then be used to interact with a web browser or other applications. Database servers are also out there, which are the ones that hold a database that can be updated and consulted when needed.</p><p>These servers in order to deliver their content, much like in physical courier services, need to have an address so that the person needing said content can make a “letter” requesting the delivery; the person requesting the content in turn also has an address where the server can deliver the content to. These addresses are called IP (Internet Protocol) Address, a set of 4 numbers that range from 0 to 255 (one byte) separated by periods (ie. 127.0.0.1).</p><p>Another concept that is important to know is that the courier service traffic for the delivery can be one of two: Transmission Control Protocol (TCP) and User Datagram Protocol (UDP). Each one determines the way the content of a server is served, or delivered.</p><p>TCP is usually used to deliver static websites such as Wikipedia or Google and also email services and to download files to your computer because TCP makes sure that all the content that is needed gets delivered. It accomplishes this by sending the file in small packets of data and along with each packet a confirmation to know that the packet was delivered; that’s why if you are ever downloading something and your internet connection suddenly drops when it comes back up you don’t have to start over because the server would know exactly how many packets you have and how many you still need to receive. The downside to TCP is that because it has to confirm whether you got the packet or not before sending the next, it tends to be slower.</p><p>UDP, on the other hand, is usually used to serve live videos or online games. This is because UDP is a lot faster than TCP since UDP does not check if the information was received or not; it is not important. The only thing UDP cares about is sending the information. That is the reason why if you’ve ever watched a live video and if either your internet connection or the host’s drops, you would just stop seeing the content; and when the connection comes back up you will only see the current stream of the broadcast and what was missed is forever lost. This is also true for online videogames (if you’ve played them you know exactly what this means)</p><h3>What actually happens…</h3><p>So back to the main question of what happens when you type <a href="http://www.google.com/">www.google.com</a> or any other URL (Uniform Resource Locator) in your web browser and press Enter. So the first thing that happens is that your browser looks up in its cache to see if that website was visited before and the IP address is known. If it can’t find the IP address for the URL requested then it asks your operating system to locate the web site. The first place your operating system is going to check for the address of the URL you specified is in the hosts file (/etc/hosts in Linux and Mac, c:\windows\system32\drivers\etc\hosts in Windows). If the URL is not found inside this file, then the OS will make a DNS request to find the IP Address of the web page. The first step is to ask the Resolver (or Internet Service Provider) server to look up in its cache to see if it knows the IP Address, if the Resolver does not know then it asks the root server to ask the .COM TLD (Top Level Domain) server — if your URL ends in .net then the TLD server would be .NET and so on — the TLD server will again check in its cache to see if the requested IP Address is there. If not, then it will have at least one of the authoritative name servers associated with that URL, and after going to the Name Server, it will return the IP Address associated with your URL. All this was done in a matter of milliseconds WOW!</p><p>After the OS has the IP Address and gives it to the browser, it then makes a GET (a type of HTTP Method) to said IP Address. When the request is made the browser again makes the request to the OS which then, in turn, packs the request in the TCP traffic protocol we discussed earlier, and it is sent to the IP Address. On its way, it is checked by both the OS’ and the server’s firewall to make sure that there are no security violations. And upon receiving the request the server (usually a load balancer that directs traffic to all available server for that website) sends a response with the IP Address of the chosen server along with the SSL (Secure Sockets Layer) certificate to initiate a secure session (HTTPS). Finally, the chosen server then sends the HTML, CSS, and Javascript files (If any) back to the OS who in turn gives it to the browser to interpret it. And then you get your website as you know it.</p><h3>The server sends out an HTTP response.</h3><p>The server response contains the web page you requested as well as the status code, compression type (<em>Content-Encoding)</em>, how to cache the page (<em>Cache-Control</em>), any cookies to set, privacy information, etc.</p><p>Example HTTP server response:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*TAnfF0T_EwPhwhaM.png" /></figure><p>If you look at the above response, the first line shows a status code. This is quite important as it tells us the status of the response. There are five types of statuses detailed using a numerical code.</p><p>● 1xx indicates an informational message only</p><p>● 2xx indicates success of some kind</p><p>● 3xx redirects the client to another URL</p><p>● 4xx indicates an error on the client’s part</p><p>● 5xx indicates an error on the server’s part</p><p>So, if you encountered an error, you can take a look at the HTTP response to check what type of status code you have received.Conclusion</p><p>In our modern society when everything is online, it is amazing to know the complexity that takes place in order for us to be able to get to a website. Yet, it is done so fast that very few would even begin to fathom the amazing process that takes place.</p><p>I hope this brief article has given you more insight of everything that happens “under the hood” when you type <a href="http://www.google.com/">www.google.com</a> in your browser and hit Enter.</p><h3>WHAT IS HTTPS :</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*w_d6Y1dVoNHkB_cEW3DZGA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*TdN-a0msHBLg8Q82GhbxsQ.png" /></figure><p>Cela garantit la confidentialité, l’intégrité et l’authentification de la grande majorité du trafic WWW actuel. Tout site Web qui affiche une icône de verrouillage dans la barre d’adresse utilise HTTPS .</p><h3>Table of Contents</h3><ul><li>DNS request</li><li>TCP/IP</li><li>Firewall</li><li>HTTPS/SSL</li><li>Load-balancer</li><li>Web server</li><li>Application server</li><li>Database</li></ul><p>Server (computing) <a href="https://en.wikipedia.org/wiki/Server_(computing)#Hardware_requirement">https://en.wikipedia.org/wiki/Server_(computing)#Hardware_requirement</a></p><p>How DNS works <a href="https://howdns.works/">https://howdns.works/</a></p><p>TCP vs UDP <a href="https://www.diffen.com/difference/TCP_vs_UDP">https://www.diffen.com/difference/TCP_vs_UDP</a></p><p>How to edit your hosts file <a href="https://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-your-hosts-file/">https://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-your-hosts-file/</a></p><p>firewall :</p><p>a <a href="https://dictionary.cambridge.org/dictionary/english/computer">computer</a> <a href="https://dictionary.cambridge.org/dictionary/english/system">system</a> or <a href="https://dictionary.cambridge.org/dictionary/english/program">program</a> that <a href="https://dictionary.cambridge.org/dictionary/english/prevent">prevents</a> someone from <a href="https://dictionary.cambridge.org/dictionary/english/see">seeing</a> or using <a href="https://dictionary.cambridge.org/dictionary/english/information">information</a> on a <a href="https://dictionary.cambridge.org/dictionary/english/computer">computer</a> without <a href="https://dictionary.cambridge.org/dictionary/english/permission">permission</a>, <a href="https://dictionary.cambridge.org/dictionary/english/especially">especially</a> someone using the <a href="https://dictionary.cambridge.org/dictionary/english/internet">internet</a>:</p><p><em>Without a firewall, all </em><a href="https://dictionary.cambridge.org/dictionary/english/your"><em>your</em></a><em> </em><a href="https://dictionary.cambridge.org/dictionary/english/file"><em>files</em></a><em> could be </em><a href="https://dictionary.cambridge.org/dictionary/english/instantly"><em>instantly</em></a><em> </em><a href="https://dictionary.cambridge.org/dictionary/english/accessible"><em>accessible</em></a><em> to any </em><a href="https://dictionary.cambridge.org/dictionary/english/competent"><em>competent</em></a><em> </em><a href="https://dictionary.cambridge.org/dictionary/english/hacker"><em>hacker</em></a><em> from </em><a href="https://dictionary.cambridge.org/dictionary/english/anywhere"><em>anywhere</em></a><em> in the </em><a href="https://dictionary.cambridge.org/dictionary/english/world"><em>world</em></a><em>.</em></p><p>HTTPS/SSL :</p><p><strong>Hypertext Transfer Protocol Secure</strong> (<strong>HTTPS</strong>) : is an extension of the <a href="https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol">Hypertext Transfer Protocol</a> (HTTP). It is used for <a href="https://en.wikipedia.org/wiki/Secure_communications">secure communication</a> over a <a href="https://en.wikipedia.org/wiki/Computer_network">computer network</a>, and is widely used on the Internet</p><p><strong>Secure Socket Layer (SSL) : </strong>SSL, or Secure Sockets Layer, is <strong>an encryption-based Internet security protocol</strong>. It was first developed by Netscape in 1995 for the purpose of ensuring privacy, authentication, and data integrity in Internet communications. SSL is the predecessor to the modern TLS encryption used today.</p><p><strong>Figure 245: Example Of The DNS Name Resolution Process</strong></p><p>This fairly complex example illustrates a typical DNS name resolution using both iterative and recursive resolution. The user types in a DNS name (“www.net.compsci.googleplex.edu”) into a Web browser, which causes a DNS resolution request to be made from her client machine’s resolver to a local DNS name server. That name server agrees to resolve the name recursively on behalf of the resolver, but uses iterative requests to accomplish it. These requests are sent to a DNS root name server, followed in turn by the name servers for “.edu”, “googleplex.edu” and ‘compsci.googleplex.edu”. The IP address is then passed to the local name server and then back to the user’s resolver and finally, her Web browser software.</p><p><strong>The diagram</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/0*m5FAbUvzuJQvTx8P.png" /></figure><h3>What happens when…</h3><p>This repository is an attempt to answer the age-old interview question “What happens when you type google.com into your browser’s address box and press enter?”</p><p>Except instead of the usual story, we’re going to try to answer this question in as much detail as possible. No skipping out on anything.</p><p>This is a collaborative process, so dig in and try to help out! There are tons of details missing, just waiting for you to add them! So send us a pull request, please!</p><p>This is all licensed under the terms of the <a href="https://creativecommons.org/publicdomain/zero/1.0/">Creative Commons Zero</a> license.</p><p>Read this in <a href="https://github.com/skyline75489/what-happens-when-zh_CN">简体中文</a> (simplified Chinese), <a href="https://github.com/tettttsuo/what-happens-when-JA">日本語</a> (Japanese), <a href="https://github.com/SantonyChoi/what-happens-when-KR">한국어</a> (Korean) and <a href="https://github.com/gonzaleztroyano/what-happens-when-ES">Spanish</a>. NOTE: these have not been reviewed by the alex/what-happens-when maintainers.</p><h3>Table of Contents</h3><ul><li><a href="https://github.com/alex/what-happens-when#the-g-key-is-pressed">The “g” key is pressed</a></li><li><a href="https://github.com/alex/what-happens-when#the-enter-key-bottoms-out">The “enter” key bottoms out</a></li><li><a href="https://github.com/alex/what-happens-when#interrupt-fires-not-for-usb-keyboards">Interrupt fires [NOT for USB keyboards]</a></li><li><a href="https://github.com/alex/what-happens-when#on-windows-a-wm-keydown-message-is-sent-to-the-app">(On Windows) A </a><a href="https://github.com/alex/what-happens-when#on-windows-a-wm-keydown-message-is-sent-to-the-app">WM_KEYDOWN message is sent to the app</a></li><li><a href="https://github.com/alex/what-happens-when#on-os-x-a-keydown-nsevent-is-sent-to-the-app">(On OS X) A </a><a href="https://github.com/alex/what-happens-when#on-os-x-a-keydown-nsevent-is-sent-to-the-app">KeyDown NSEvent is sent to the app</a></li><li><a href="https://github.com/alex/what-happens-when#on-gnu-linux-the-xorg-server-listens-for-keycodes">(On GNU/Linux) the Xorg server listens for keycodes</a></li><li><a href="https://github.com/alex/what-happens-when#parse-url">Parse URL</a></li><li><a href="https://github.com/alex/what-happens-when#is-it-a-url-or-a-search-term">Is it a URL or a search term?</a></li><li><a href="https://github.com/alex/what-happens-when#convert-non-ascii-unicode-characters-in-the-hostname">Convert non-ASCII Unicode characters in the hostname</a></li><li><a href="https://github.com/alex/what-happens-when#check-hsts-list">Check HSTS list</a></li><li><a href="https://github.com/alex/what-happens-when#dns-lookup">DNS lookup</a></li><li><a href="https://github.com/alex/what-happens-when#arp-process">ARP process</a></li><li><a href="https://github.com/alex/what-happens-when#opening-of-a-socket">Opening of a socket</a></li><li><a href="https://github.com/alex/what-happens-when#tls-handshake">TLS handshake</a></li><li><a href="https://github.com/alex/what-happens-when#if-a-packet-is-dropped">If a packet is dropped</a></li><li><a href="https://github.com/alex/what-happens-when#http-protocol">HTTP protocol</a></li><li><a href="https://github.com/alex/what-happens-when#http-server-request-handle">HTTP Server Request Handle</a></li><li><a href="https://github.com/alex/what-happens-when#behind-the-scenes-of-the-browser">Behind the scenes of the Browser</a></li><li><a href="https://github.com/alex/what-happens-when#browser">Browser</a></li><li><a href="https://github.com/alex/what-happens-when#html-parsing">HTML parsing</a></li><li><a href="https://github.com/alex/what-happens-when#css-interpretation">CSS interpretation</a></li><li><a href="https://github.com/alex/what-happens-when#page-rendering">Page Rendering</a></li><li><a href="https://github.com/alex/what-happens-when#gpu-rendering">GPU Rendering</a></li><li><a href="https://github.com/alex/what-happens-when#window-server">Window Server</a></li><li><a href="https://github.com/alex/what-happens-when#post-rendering-and-user-induced-execution">Post-rendering and user-induced execution</a></li></ul><h3>The “g” key is pressed</h3><p>The following sections explain the physical keyboard actions and the OS interrupts. When you press the key “g” the browser receives the event and the auto-complete functions kick in. Depending on your browser’s algorithm and if you are in private/incognito mode or not various suggestions will be presented to you in the dropdown below the URL bar. Most of these algorithms sort and prioritize results based on search history, bookmarks, cookies, and popular searches from the internet as a whole. As you are typing “google.com” many blocks of code run and the suggestions will be refined with each keypress. It may even suggest “google.com” before you finish typing it.</p><h3>The “enter” key bottoms out</h3><p>To pick a zero point, let’s choose the Enter key on the keyboard hitting the bottom of its range. At this point, an electrical circuit specific to the enter key is closed (either directly or capacitively). This allows a small amount of current to flow into the logic circuitry of the keyboard, which scans the state of each key switch, debounces the electrical noise of the rapid intermittent closure of the switch, and converts it to a keycode integer, in this case 13. The keyboard controller then encodes the keycode for transport to the computer. This is now almost universally over a Universal Serial Bus (USB) or Bluetooth connection, but historically has been over PS/2 or ADB connections.</p><p><em>In the case of the USB keyboard:</em></p><ul><li>The USB circuitry of the keyboard is powered by the 5V supply provided over pin 1 from the computer’s USB host controller.</li><li>The keycode generated is stored by internal keyboard circuitry memory in a register called “endpoint”.</li><li>The host USB controller polls that “endpoint” every ~10ms (minimum value declared by the keyboard), so it gets the keycode value stored on it.</li><li>This value goes to the USB SIE (Serial Interface Engine) to be converted in one or more USB packets that follow the low-level USB protocol.</li><li>Those packets are sent by a differential electrical signal over D+ and D- pins (the middle 2) at a maximum speed of 1.5 Mb/s, as an HID (Human Interface Device) device is always declared to be a “low-speed device” (USB 2.0 compliance).</li><li>This serial signal is then decoded at the computer’s host USB controller, and interpreted by the computer’s Human Interface Device (HID) universal keyboard device driver. The value of the key is then passed into the operating system’s hardware abstraction layer.</li></ul><p><em>In the case of Virtual Keyboard (as in touch screen devices):</em></p><ul><li>When the user puts their finger on a modern capacitive touch screen, a tiny amount of current gets transferred to the finger. This completes the circuit through the electrostatic field of the conductive layer and creates a voltage drop at that point on the screen. The screen controller then raises an interrupt reporting the coordinate of the keypress.</li><li>Then the mobile OS notifies the currently focused application of a press event in one of its GUI elements (which now is the virtual keyboard application buttons).</li><li>The virtual keyboard can now raise a software interrupt for sending a ‘key pressed’ message back to the OS.</li><li>This interrupt notifies the currently focused application of a ‘key pressed’ event.</li></ul><h3>Interrupt fires [NOT for USB keyboards]</h3><p>The keyboard sends signals on its interrupt request line (IRQ), which is mapped to an interrupt vector (integer) by the interrupt controller. The CPU uses the Interrupt Descriptor Table (IDT) to map the interrupt vectors to functions (interrupt handlers) which are supplied by the kernel. When an interrupt arrives, the CPU indexes the IDT with the interrupt vector and runs the appropriate handler. Thus, the kernel is entered.</p><h3>(On Windows) A WM_KEYDOWN message is sent to the app</h3><p>The HID transport passes the key down event to the KBDHID.sys driver which converts the HID usage into a scancode. In this case, the scan code is VK_RETURN (0x0D). The KBDHID.sys driver interfaces with the KBDCLASS.sys (keyboard class driver). This driver is responsible for handling all keyboard and keypad input in a secure manner. It then calls into Win32K.sys (after potentially passing the message through 3rd party keyboard filters that are installed). This all happens in kernel mode.</p><p>Win32K.sys figures out what window is the active window through the GetForegroundWindow() API. This API provides the window handle of the browser&#39;s address box. The main Windows &quot;message pump&quot; then calls SendMessage(hWnd, WM_KEYDOWN, VK_RETURN, lParam). lParam is a bitmask that indicates further information about the keypress: repeat count (0 in this case), the actual scan code (can be OEM dependent, but generally wouldn&#39;t be for VK_RETURN), whether extended keys (e.g. alt, shift, ctrl) were also pressed (they weren&#39;t), and some other state.</p><p>The Windows SendMessage API is a straightforward function that adds the message to a queue for the particular window handle (hWnd). Later, the main message processing function (called a WindowProc) assigned to the hWnd is called in order to process each message in the queue.</p><p>The window (hWnd) that is active is actually an edit control and the WindowProc in this case has a message handler for WM_KEYDOWN messages. This code looks within the 3rd parameter that was passed to SendMessage (wParam) and, because it is VK_RETURN knows the user has hit the ENTER key.</p><h3>(On OS X) A KeyDown NSEvent is sent to the app</h3><p>The interrupt signal triggers an interrupt event in the I/O Kit kext keyboard driver. The driver translates the signal into a key code which is passed to the OS X WindowServer process. Resultantly, the WindowServer dispatches an event to any appropriate (e.g. active or listening) applications through their Mach port where it is placed into an event queue. Events can then be read from this queue by threads with sufficient privileges calling the mach_ipc_dispatch function. This most commonly occurs through, and is handled by, an NSApplication main event loop, via an NSEvent of NSEventType KeyDown.</p><h3>(On GNU/Linux) the Xorg server listens for keycodes</h3><p>When a graphical X server is used, X will use the generic event driver evdev to acquire the keypress. A re-mapping of keycodes to scancodes is made with X server specific keymaps and rules. When the scancode mapping of the key pressed is complete, the X server sends the character to the window manager (DWM, metacity, i3, etc), so the window manager in turn sends the character to the focused window. The graphical API of the window that receives the character prints the appropriate font symbol in the appropriate focused field.</p><h3>Is it a URL or a search term?</h3><p>When no protocol or valid domain name is given the browser proceeds to feed the text given in the address box to the browser’s default web search engine. In many cases the URL has a special piece of text appended to it to tell the search engine that it came from a particular browser’s URL bar.</p><h3>Convert non-ASCII Unicode characters in the hostname</h3><ul><li>The browser checks the hostname for characters that are not in a-z, A-Z, 0-9, -, or ..</li><li>Since the hostname is google.com there won&#39;t be any, but if there were the browser would apply <a href="https://en.wikipedia.org/wiki/Punycode">Punycode</a> encoding to the hostname portion of the URL.</li></ul><h3>Check HSTS list</h3><ul><li>The browser checks its “preloaded HSTS (HTTP Strict Transport Security)” list. This is a list of websites that have requested to be contacted via HTTPS only.</li><li>If the website is in the list, the browser sends its request via HTTPS instead of HTTP. Otherwise, the initial request is sent via HTTP. (Note that a website can still use the HSTS policy <em>without</em> being in the HSTS list. The first HTTP request to the website by a user will receive a response requesting that the user only send HTTPS requests. However, this single HTTP request could potentially leave the user vulnerable to a <a href="http://en.wikipedia.org/wiki/SSL_stripping">downgrade attack</a>, which is why the HSTS list is included in modern web browsers.)</li></ul><h3>DNS lookup</h3><ul><li>Browser checks if the domain is in its cache. (to see the DNS Cache in Chrome, go to chrome://net-internals/#dns).</li><li>If not found, the browser calls gethostbyname library function (varies by OS) to do the lookup.</li><li>gethostbyname checks if the hostname can be resolved by reference in the local hosts file (whose location <a href="https://en.wikipedia.org/wiki/Hosts_%28file%29#Location_in_the_file_system">varies by OS</a>) before trying to resolve the hostname through DNS.</li><li>If gethostbyname does not have it cached nor can find it in the hosts file then it makes a request to the DNS server configured in the network stack. This is typically the local router or the ISP&#39;s caching DNS server.</li><li>If the DNS server is on the same subnet the network library follows the ARP process below for the DNS server.</li><li>If the DNS server is on a different subnet, the network library follows the ARP process below for the default gateway IP.</li></ul><h3>ARP process</h3><p>In order to send an ARP (Address Resolution Protocol) broadcast the network stack library needs the target IP address to lookup. It also needs to know the MAC address of the interface it will use to send out the ARP broadcast.</p><p>The ARP cache is first checked for an ARP entry for our target IP. If it is in the cache, the library function returns the result: Target IP = MAC.</p><p>If the entry is not in the ARP cache:</p><ul><li>The route table is looked up, to see if the Target IP address is on any of the subnets on the local route table. If it is, the library uses the interface associated with that subnet. If it is not, the library uses the interface that has the subnet of our default gateway.</li><li>The MAC address of the selected network interface is looked up.</li><li>The network library sends a Layer 2 (data link layer of the <a href="https://en.wikipedia.org/wiki/OSI_model">OSI model</a>) ARP request:</li></ul><p>ARP Request:</p><pre>Sender MAC: interface:mac:address:here<br>Sender IP: interface.ip.goes.here<br>Target MAC: FF:FF:FF:FF:FF:FF (Broadcast)<br>Target IP: target.ip.goes.here</pre><p>Depending on what type of hardware is between the computer and the router:</p><p>Directly connected:</p><ul><li>If the computer is directly connected to the router the router response with an ARP Reply (see below)</li></ul><p>Hub:</p><ul><li>If the computer is connected to a hub, the hub will broadcast the ARP request out of all other ports. If the router is connected on the same “wire”, it will respond with an ARP Reply (see below).</li></ul><p>Switch:</p><ul><li>If the computer is connected to a switch, the switch will check its local CAM/MAC table to see which port has the MAC address we are looking for. If the switch has no entry for the MAC address it will rebroadcast the ARP request to all other ports.</li><li>If the switch has an entry in the MAC/CAM table it will send the ARP request to the port that has the MAC address we are looking for.</li><li>If the router is on the same “wire”, it will respond with an ARP Reply (see below)</li></ul><p>ARP Reply:</p><pre>Sender MAC: target:mac:address:here<br>Sender IP: target.ip.goes.here<br>Target MAC: interface:mac:address:here<br>Target IP: interface.ip.goes.here</pre><p>Now that the network library has the IP address of either our DNS server or the default gateway it can resume its DNS process:</p><ul><li>The DNS client establishes a socket to UDP port 53 on the DNS server, using a source port above 1023.</li><li>If the response size is too large, TCP will be used instead.</li><li>If the local/ISP DNS server does not have it, then a recursive search is requested and that flows up the list of DNS servers until the SOA is reached, and if found an answer is returned.</li></ul><h3>Opening of a socket</h3><p>Once the browser receives the IP address of the destination server, it takes that and the given port number from the URL (the HTTP protocol defaults to port 80, and HTTPS to port 443), and makes a call to the system library function named socket and requests a TCP socket stream - AF_INET/AF_INET6 and SOCK_STREAM.</p><ul><li>This request is first passed to the Transport Layer where a TCP segment is crafted. The destination port is added to the header, and a source port is chosen from within the kernel’s dynamic port range (ip_local_port_range in Linux).</li><li>This segment is sent to the Network Layer, which wraps an additional IP header. The IP address of the destination server as well as that of the current machine is inserted to form a packet.</li><li>The packet next arrives at the Link Layer. A frame header is added that includes the MAC address of the machine’s NIC as well as the MAC address of the gateway (local router). As before, if the kernel does not know the MAC address of the gateway, it must broadcast an ARP query to find it.</li></ul><p>At this point the packet is ready to be transmitted through either:</p><ul><li><a href="http://en.wikipedia.org/wiki/IEEE_802.3">Ethernet</a></li><li><a href="https://en.wikipedia.org/wiki/IEEE_802.11">WiFi</a></li><li><a href="https://en.wikipedia.org/wiki/Cellular_data_communication_protocol">Cellular data network</a></li></ul><p>For most home or small business Internet connections the packet will pass from your computer, possibly through a local network, and then through a modem (MOdulator/DEModulator) which converts digital 1’s and 0’s into an analog signal suitable for transmission over telephone, cable, or wireless telephony connections. On the other end of the connection is another modem which converts the analog signal back into digital data to be processed by the next <a href="https://en.wikipedia.org/wiki/Computer_network#Network_nodes">network node</a> where the from and to addresses would be analyzed further.</p><p>Most larger businesses and some newer residential connections will have fiber or direct Ethernet connections in which case the data remains digital and is passed directly to the next <a href="https://en.wikipedia.org/wiki/Computer_network#Network_nodes">network node</a> for processing.</p><p>Eventually, the packet will reach the router managing the local subnet. From there, it will continue to travel to the autonomous system’s (AS) border routers, other ASes, and finally to the destination server. Each router along the way extracts the destination address from the IP header and routes it to the appropriate next hop. The time to live (TTL) field in the IP header is decremented by one for each router that passes. The packet will be dropped if the TTL field reaches zero or if the current router has no space in its queue (perhaps due to network congestion).</p><p>This send and receive happens multiple times following the TCP connection flow:</p><ul><li>Client chooses an initial sequence number (ISN) and sends the packet to the server with the SYN bit set to indicate it is setting the ISN</li><li>Server receives SYN and if it’s in an agreeable mood:</li><li>Server chooses its own initial sequence number</li><li>Server sets SYN to indicate it is choosing its ISN</li><li>Server copies the (client ISN +1) to its ACK field and adds the ACK flag to indicate it is acknowledging receipt of the first packet</li><li>Client acknowledges the connection by sending a packet:</li><li>Increases its own sequence number</li><li>Increases the receiver acknowledgment number</li><li>Sets ACK field</li><li>Data is transferred as follows:</li><li>As one side sends N data bytes, it increases its SEQ by that number</li><li>When the other side acknowledges receipt of that packet (or a string of packets), it sends an ACK packet with the ACK value equal to the last received sequence from the other</li><li>To close the connection:</li><li>The closer sends a FIN packet</li><li>The other sides ACKs the FIN packet and sends its own FIN</li><li>The closer acknowledges the other side’s FIN with an ACK</li></ul><h3>TLS handshake</h3><ul><li>The client computer sends a ClientHello message to the server with its Transport Layer Security (TLS) version, list of cipher algorithms and compression methods available.</li><li>The server replies with a ServerHello message to the client with the TLS version, selected cipher, selected compression methods and the server&#39;s public certificate signed by a CA (Certificate Authority). The certificate contains a public key that will be used by the client to encrypt the rest of the handshake until a symmetric key can be agreed upon.</li><li>The client verifies the server digital certificate against its list of trusted CAs. If trust can be established based on the CA, the client generates a string of pseudo-random bytes and encrypts this with the server’s public key. These random bytes can be used to determine the symmetric key.</li><li>The server decrypts the random bytes using its private key and uses these bytes to generate its own copy of the symmetric master key.</li><li>The client sends a Finished message to the server, encrypting a hash of the transmission up to this point with the symmetric key.</li><li>The server generates its own hash, and then decrypts the client-sent hash to verify that it matches. If it does, it sends its own Finished message to the client, also encrypted with the symmetric key.</li><li>From now on the TLS session transmits the application (HTTP) data encrypted with the agreed symmetric key.</li></ul><h3>If a packet is dropped</h3><p>Sometimes, due to network congestion or flaky hardware connections, TLS packets will be dropped before they get to their final destination. The sender then has to decide how to react. The algorithm for this is called <a href="https://en.wikipedia.org/wiki/TCP_congestion_control">TCP congestion control</a>. This varies depending on the sender; the most common algorithms are <a href="https://en.wikipedia.org/wiki/CUBIC_TCP">cubic</a> on newer operating systems and <a href="https://en.wikipedia.org/wiki/TCP_congestion_control#TCP_New_Reno">New Reno</a> on almost all others.</p><ul><li>Client chooses a <a href="https://en.wikipedia.org/wiki/TCP_congestion_control#Congestion_window">congestion window</a> based on the <a href="https://en.wikipedia.org/wiki/Maximum_segment_size">maximum segment size</a> (MSS) of the connection.</li><li>For each packet acknowledged, the window doubles in size until it reaches the ‘slow-start threshold’. In some implementations, this threshold is adaptive.</li><li>After reaching the slow-start threshold, the window increases additively for each packet acknowledged. If a packet is dropped, the window reduces exponentially until another packet is acknowledged.</li></ul><h3>HTTP protocol</h3><p>If the web browser used was written by Google, instead of sending an HTTP request to retrieve the page, it will send a request to try and negotiate with the server an “upgrade” from HTTP to the SPDY protocol.</p><p>If the client is using the HTTP protocol and does not support SPDY, it sends a request to the server of the form:</p><pre>GET / HTTP/1.1<br>Host: google.com<br>Connection: close<br>[other headers]</pre><p>where [other headers] refers to a series of colon-separated key-value pairs formatted as per the HTTP specification and separated by single newlines. (This assumes the web browser being used doesn&#39;t have any bugs violating the HTTP spec. This also assumes that the web browser is using HTTP/1.1, otherwise it may not include the Host header in the request and the version specified in the GET request will either be HTTP/1.0 or HTTP/0.9.)</p><p>HTTP/1.1 defines the “close” connection option for the sender to signal that the connection will be closed after completion of the response. For example,</p><blockquote><em>Connection: close</em></blockquote><p>HTTP/1.1 applications that do not support persistent connections MUST include the “close” connection option in every message.</p><p>After sending the request and headers, the web browser sends a single blank newline to the server indicating that the content of the request is done.</p><p>The server responds with a response code denoting the status of the request and responds with a response of the form:</p><pre>200 OK<br>[response headers]</pre><p>Followed by a single newline, and then sends a payload of the HTML content of www.google.com. The server may then either close the connection, or if headers sent by the client requested it, keep the connection open to be reused for further requests.</p><p>If the HTTP headers sent by the web browser included sufficient information for the webserver to determine if the version of the file cached by the web browser has been unmodified since the last retrieval (ie. if the web browser included an ETag header), it may instead respond with a request of the form:</p><pre>304 Not Modified<br>[response headers]</pre><p>and no payload, and the web browser instead retrieve the HTML from its cache.</p><p>After parsing the HTML, the web browser (and server) repeats this process for every resource (image, CSS, favicon.ico, etc) referenced by the HTML page, except instead of GET / HTTP/1.1 the request will be GET /$(URL relative to www.google.com) HTTP/1.1.</p><p>If the HTML referenced a resource on a different domain than www.google.com, the web browser goes back to the steps involved in resolving the other domain, and follows all steps up to this point for that domain. The Host header in the request will be set to the appropriate server name instead of google.com.</p><h3>HTTP Server Request Handle</h3><p>The HTTPD (HTTP Daemon) server is the one handling the requests/responses on the server-side. The most common HTTPD servers are Apache or nginx for Linux and IIS for Windows.</p><ul><li>The HTTPD (HTTP Daemon) receives the request.</li><li>The server breaks down the request to the following parameters:</li><li>HTTP Request Method (either GET, HEAD, POST, PUT, PATCH, DELETE, CONNECT, OPTIONS, or TRACE). In the case of a URL entered directly into the address bar, this will be GET.</li><li>Domain, in this case — google.com.</li><li>Requested path/page, in this case — / (as no specific path/page was requested, / is the default path).</li><li>The server verifies that there is a Virtual Host configured on the server that corresponds with google.com.</li><li>The server verifies that google.com can accept GET requests.</li><li>The server verifies that the client is allowed to use this method (by IP, authentication, etc.).</li><li>If the server has a rewrite module installed (like mod_rewrite for Apache or URL Rewrite for IIS), it tries to match the request against one of the configured rules. If a matching rule is found, the server uses that rule to rewrite the request.</li><li>The server goes to pull the content that corresponds with the request, in our case it will fall back to the index file, as “/” is the main file (some cases can override this, but this is the most common method).</li><li>The server parses the file according to the handler. If Google is running on PHP, the server uses PHP to interpret the index file, and streams the output to the client.</li></ul><h3>Behind the scenes of the Browser</h3><p>Once the server supplies the resources (HTML, CSS, JS, images, etc.) to the browser it undergoes the below process:</p><ul><li>Parsing — HTML, CSS, JS</li><li>Rendering — Construct DOM Tree → Render Tree → Layout of Render Tree → Painting the render tree</li></ul><h3>Browser</h3><p>The browser’s functionality is to present the web resource you choose, by requesting it from the server and displaying it in the browser window. The resource is usually an HTML document, but may also be a PDF, image, or some other type of content. The location of the resource is specified by the user using a URI (Uniform Resource Identifier).</p><p>The way the browser interprets and displays HTML files is specified in the HTML and CSS specifications. These specifications are maintained by the W3C (World Wide Web Consortium) organization, which is the standards organization for the web.</p><p>Browser user interfaces have a lot in common with each other. Among the common user interface elements are:</p><ul><li>An address bar for inserting a URI</li><li>Back and forward buttons</li><li>Bookmarking options</li><li>Refresh and stop buttons for refreshing or stopping the loading of current documents</li><li>Home button that takes you to your home page</li></ul><p>Browser High-Level Structure</p><p>The components of the browsers are:</p><ul><li>User interface: The user interface includes the address bar, back/forward button, bookmarking menu, etc. Every part of the browser display except the window where you see the requested page.</li><li>Browser engine: The browser engine marshals actions between the UI and the rendering engine.</li><li>Rendering engine: The rendering engine is responsible for displaying requested content. For example if the requested content is HTML, the rendering engine parses HTML and CSS, and displays the parsed content on the screen.</li><li>Networking: The networking handles network calls such as HTTP requests, using different implementations for different platforms behind a platform-independent interface.</li><li>UI backend: The UI backend is used for drawing basic widgets like combo boxes and windows. This backend exposes a generic interface that is not platform-specific. Underneath it uses operating system user interface methods.</li><li>JavaScript engine: The JavaScript engine is used to parse and execute JavaScript code.</li><li>Data storage: The data storage is a persistence layer. The browser may need to save all sorts of data locally, such as cookies. Browsers also support storage mechanisms such as localStorage, IndexedDB, WebSQL and FileSystem.</li></ul><h3>HTML parsing</h3><p>The rendering engine starts getting the contents of the requested document from the networking layer. This will usually be done in 8kB chunks.</p><p>The primary job of the HTML parser is to parse the HTML markup into a parse tree.</p><p>The output tree (the “parse tree”) is a tree of DOM element and attribute nodes. DOM is short for Document Object Model. It is the object presentation of the HTML document and the interface of HTML elements to the outside world like JavaScript. The root of the tree is the “Document” object. Prior to any manipulation via scripting, the DOM has an almost one-to-one relation to the markup.</p><p>The parsing algorithm</p><p>HTML cannot be parsed using the regular top-down or bottom-up parsers.</p><p>The reasons are:</p><ul><li>The forgiving nature of the language.</li><li>The fact that browsers have traditional error tolerance to support well known cases of invalid HTML.</li><li>The parsing process is reentrant. For other languages, the source doesn’t change during parsing, but in HTML, dynamic code (such as script elements containing document.write() calls) can add extra tokens, so the parsing process actually modifies the input.</li></ul><p>Unable to use the regular parsing techniques, the browser utilizes a custom parser for parsing HTML. The parsing algorithm is described in detail by the HTML5 specification.</p><p>The algorithm consists of two stages: tokenization and tree construction.</p><p>Actions when the parsing is finished</p><p>The browser begins fetching external resources linked to the page (CSS, images, JavaScript files, etc.).</p><p>At this stage the browser marks the document as interactive and starts parsing scripts that are in “deferred” mode: those that should be executed after the document is parsed. The document state is set to “complete” and a “load” event is fired.</p><p>Note there is never an “Invalid Syntax” error on an HTML page. Browsers fix any invalid content and go on.</p><h3>CSS interpretation</h3><ul><li>Parse CSS files, &lt;style&gt; tag contents, and style attribute values using <a href="http://www.w3.org/TR/CSS2/grammar.html">&quot;CSS lexical and syntax grammar&quot;</a></li><li>Each CSS file is parsed into a StyleSheet object, where each object contains CSS rules with selectors and objects corresponding CSS grammar.</li><li>A CSS parser can be top-down or bottom-up when a specific parser generator is used.</li></ul><h3>Page Rendering</h3><ul><li>Create a ‘Frame Tree’ or ‘Render Tree’ by traversing the DOM nodes, and calculating the CSS style values for each node.</li><li>Calculate the preferred width of each node in the ‘Frame Tree’ bottom-up by summing the preferred width of the child nodes and the node’s horizontal margins, borders, and padding.</li><li>Calculate the actual width of each node top-down by allocating each node’s available width to its children.</li><li>Calculate the height of each node bottom-up by applying text wrapping and summing the child node heights and the node’s margins, borders, and padding.</li><li>Calculate the coordinates of each node using the information calculated above.</li><li>More complicated steps are taken when elements are floated, positioned absolutely or relatively, or other complex features are used. See <a href="http://dev.w3.org/csswg/css2/">http://dev.w3.org/csswg/css2/</a> and <a href="http://www.w3.org/Style/CSS/current-work">http://www.w3.org/Style/CSS/current-work</a> for more details.</li><li>Create layers to describe which parts of the page can be animated as a group without being re-rasterized. Each frame/render object is assigned to a layer.</li><li>Textures are allocated for each layer of the page.</li><li>The frame/render objects for each layer are traversed and drawing commands are executed for their respective layer. This may be rasterized by the CPU or drawn on the GPU directly using D2D/SkiaGL.</li><li>All of the above steps may reuse calculated values from the last time the webpage was rendered, so that incremental changes require less work.</li><li>The page layers are sent to the compositing process where they are combined with layers for other visible content like the browser chrome, iframes and addon panels.</li><li>Final layer positions are computed and the composite commands are issued via Direct3D/OpenGL. The GPU command buffer(s) are flushed to the GPU for asynchronous rendering and the frame is sent to the window server.</li></ul><h3>GPU Rendering</h3><ul><li>During the rendering process the graphical computing layers can use general purpose CPU or the graphical processor GPU as well.</li><li>When using GPU for graphical rendering computations the graphical software layers split the task into multiple pieces, so it can take advantage of GPU massive parallelism for float point calculations required for the rendering process.</li></ul><h3>Window Server</h3><h3>Post-rendering and user-induced execution</h3><p>After rendering has been completed, the browser executes JavaScript code as a result of some timing mechanism (such as a Google Doodle animation) or user interaction (typing a query into the search box and receiving suggestions). Plugins such as Flash or Java may execute as well, although not at this time on the Google homepage. Scripts can cause additional network requests to be performed, as well as modify the page or its layout, causing another round of page rendering and painting.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e46e5cfa957" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What happens when you type ls *.c in the shell?]]></title>
            <link>https://medium.com/@3681/what-happens-when-you-type-ls-c-in-the-shell-727b3200acc1?source=rss-5729a8fdfd59------2</link>
            <guid isPermaLink="false">https://medium.com/p/727b3200acc1</guid>
            <dc:creator><![CDATA[ghassenehedfi]]></dc:creator>
            <pubDate>Wed, 08 Dec 2021 21:55:52 GMT</pubDate>
            <atom:updated>2021-12-08T21:55:52.481Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s take a look at what happens when you type ls *.c in the shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CcmSvJIURF6ygnJe.jpeg" /></figure><p>Terminal with the ls *.c command</p><p>First of all, we need to know what is a shell, a shell is the command interpreter between the user and the computer, when you write a command on the terminal, the shell translates the message to the computer and then the command is executed.</p><p>We can find multiple commands on the shell to execute, one of them is the command ls, using this command you can make a list of the files and directories inside any folder.</p><p>Now, to understand the whole command ls *.c we need to check what is a wildcard, a wildcard is a symbol or a character that is used as a substitute for any class of characters, for example, if you want to search for all the files ending in txt we can use “*.txt”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*2AXTTy1d9R430yL2" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*RAiFQR7pjpwNMX6C.jpeg" /></figure><p>ls *.txt command</p><p>In this case, the “*” works as a substitute to match any file ending in .txt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*-imHhycJRqco6OJr" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*5e0I_gNpdOgwtyTB.jpeg" /></figure><p>ls *.c command</p><p>So now if we type ls *.c in the shell, the command is going to list all the files with the extension .c and is going to ignore any other file, this is useful when you are trying to search for specific files.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=727b3200acc1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple Shell]]></title>
            <link>https://medium.com/@3681/simple-shell-edfc77e92b9a?source=rss-5729a8fdfd59------2</link>
            <guid isPermaLink="false">https://medium.com/p/edfc77e92b9a</guid>
            <dc:creator><![CDATA[ghassenehedfi]]></dc:creator>
            <pubDate>Wed, 08 Dec 2021 21:52:19 GMT</pubDate>
            <atom:updated>2021-12-08T21:52:19.064Z</atom:updated>
            <content:encoded><![CDATA[<h3>WHAT IS A SHELL?</h3><p>Most of us are used to navigate through a computer via a graphical user interface(GUI), files, folders, and clicks. but there is another to navigate the shell is a command-line interface(CLI), this program that takes commands from the keyboard and gives them to the operating system to perform, in this case, to navigate and do pretty much everything that you can do by clicking.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*WLfquVOq_mmMyi-cSzuD7w.png" /></figure><p>In the picture above you can see the two ways to navigate in a computer, in the left you will see a normal GUI from Ubuntu a Linux distribution, in the right, you will see the Linux command line, as you can appreciate in the picture both are in the same folder.</p><p>To understand better how to code a simple shell we are going to use “ls -l” as an example of how the shell execute every command that is entered in the command line.</p><blockquote><em>In this project, we are going to build an interpreter, which means that we are going to read the command, look for the executable file and execute it, this is not about building each command</em></blockquote><h3>Aliases</h3><p>when we type a command in the terminal and hit enter, your shell program checks for any aliases associated with the commands you’ve entered. If an alias is found, it expands that alias before it executes.</p><h3>Built-in</h3><p>After switching out any aliases, we want to next look for built-in commands. Built-in commands are commands that exist within the shell. They aren’t outside programs living in other directories. Theoretically. In the simple shell, some of the built-ins include <strong>exit</strong> and <strong>env</strong>. In our case, <em>ls</em> is not built-in.</p><p>Ok now, In the next screenshot, we will see the command typed in the shell, ready to be processed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*gdSgtUZmzSVwpTf1" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*FvQAtlulK__-yosP.png" /></figure><p>Once we write the command, followed by the ENTER</p><p>The shell reads the line, this is done by using a function called getline(), it also puts a NULL at the end, it indicates the end of the text.</p><pre>line = getline(&amp;buffer, &amp;line_size, stdin);</pre><p>The <a href="https://linux.die.net/man/3/getline">getline()</a> reads the text entered and save it a char pointer variable like this. Remember it also adds the NULL</p><pre>char *buffer = [ls -l\0];</pre><p><strong>Creating tokens</strong></p><p>The next step in the data processes to make shell works is tokenize the buffer, we take the entered command and split it in tokens, using the “space” as a delimiter using the <a href="http://man7.org/linux/man-pages/man3/strtok_r.3.html">strtok()</a> function.</p><pre>char *token = strtok(buffer, “ “);</pre><p>Now that strtok() give as every token one by one we have to save it token by token into a double-pointer of arrays, with each token being saved as a char pointer, followed by a NULL, like this.</p><pre>char **token_holder = [*token, *token, NULL];char **commands = [&quot;ls&quot;, &quot;-l&quot;, NULL];</pre><p>One thing that we have to consider at this point is that we actually don’t know how many commands or tokens will be entered in the CLI, this is why we have to save **commands and *token in the Heap memory, in order to prevent a StackOverflow. We need to allocate enough memory to **commands and *token.<br>We do this created the _realloc() function (<a href="https://github.com/AndrewB4y/simple_shell/blob/master/_realloc.c"><em>source code)</em>,</a> this function allocates a new block of memory, which is very useful because we allocate this block every time that strtok() give us a token.</p><blockquote><em>Now, one thing that I forget to mention is that strtok() has an inner malloc. with the use of a loop we canmake that every token mallocs it self into the allocated space created by _realloc.</em></blockquote><p>Cool, now to this point we have received the command, split it into tokens, and saves every token in the heap memory in a double-pointer array.<br>But this process by itself is not enough to make the shell work properly, at the same time that the shell does this process there is another process ongoing, and it has to do with the PATH.</p><p><strong>PATH</strong></p><p>So at this point, we have:</p><pre>**commands = [“ls”, “-l”, “NULL]</pre><p>but if we pass in just the “ls” our shell won’t work, because the shell does not know where to find the command the “ls -l”</p><p>We need to check our PATH variable to find it. Yes, we have to check directory by directory, for those who don’t know what is a PATH its basically this</p><pre>PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin/:bin</pre><p>as you can see the PATH is a variable that storage directories we have to check each directory in the PATH to see if the command exits in one of them.</p><blockquote><em>Remember that commands are executable files, which means that are looking for a executable</em></blockquote><p>Our Shell looks through each directory separated by a “ : ” to see if the “ ls “ executable exist inside of one of them, we do this using a function called <a href="https://linux.die.net/man/2/stat">stat()</a> that see if the executable file exists in each directory.<br>When the shell has managed to find the executable file, it replaces the first string with the path of the directory that has “ ls”, like this</p><pre>**commands = [“/bin/ls”, “-l”, ”\0&quot;]</pre><p>We did this in order to have the location of “ls” otherwise how can we know where it is? remember we are building an interpreter, our goal is to read, parse, find and execute.</p><p>Until this point, we have read the CLI, parsed the information, stored the information, validated the PATH of our command, and now, we have to execute it.</p><p>This is the last main step in the process, now we have to fork the process, and I know this is confusing, but there is a very good reason for this, let talk a little bit about this…</p><blockquote><em>We have to understand that computers have many processes ongoing, processes are like stories they have a beginning, a knot, and an outcome. The shell is a process itself this is why we can’t execute the command in the same process (the shell process), if we do this we would finish this process and kill the shell, and we don’t want that, we want to keep entering commands as much as we want, so we need to fork the process and execute the command in to the child process created, once the command is executed the child process will be killed, and we will back to the parent process, let see this more in detail…</em></blockquote><h3>Creating New Processes</h3><p>Once you have entered the command “ls -l”, the shell has already validated the PATH and is ready to run from “/bin/ls”, we create a new process using a function called <a href="http://man7.org/linux/man-pages/man2/fork.2.html">fork( )</a>, this is where the child process appears.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*8MH26nC9VmqYgXgfCfMkjA.png" /></figure><p>After the child process is created, its time to execute de command “ /bin/ls -l” in the child process, we use the function <a href="http://man7.org/linux/man-pages/man2/execve.2.html">execve()</a>, this function goes to the PATH, finds the executable file and execute it, <em>it also looks for the flags.<br></em>Once the successful execution is confirmed by execve() we kill the child process.</p><p>At last but not least we use the wait() function which is responsible for check that everything was right with the child process and return to the parent process</p><p>When it’s all said and done, your newly created simple shell should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*wonIeB6GjO23rxs741M0FA.png" /></figure><p>The source code for the Simple Shell can be found <a href="https://github.com/AndrewB4y/simple_shell">here</a>.</p><p>If you’re using a computer for much more than word processing and the internet, you’re probably going end up becoming familiar with <strong>THE SHELL.</strong> Also known as a command-line interface (CLI), shell programs give you access to the hitherto unexplored reaches of your computer. Fundamentally, shell programs offer simple but very powerful facilities for interacting with your file system and executing text-based programs. These days, with the existence of graphical operating systems, like Windows or MacOS, in order to access a CLI, you use a <em>terminal</em> program, which allows you run a shell program from within your GUI OS.</p><p>There are a large number of <a href="https://en.wikipedia.org/wiki/Comparison_of_command_shells">shell programs</a> out there, although several clearly have become most popular: those are <strong>bash</strong> (<a href="https://en.wikipedia.org/wiki/Bash_(Unix_shell)">the Bourne-again shell</a>), <strong>csh</strong> (<a href="https://en.wikipedia.org/wiki/C_shell">C shell</a>), <strong>ksh</strong> (<a href="https://en.wikipedia.org/wiki/KornShell">Korn shell</a>), and <strong>zsh</strong> (<a href="https://en.wikipedia.org/wiki/Z_shell">named for Zhong Shao</a>). Each of them provides several essential functionalities:</p><ol><li>Ability to execute other programs in a subprocess.</li><li>An interactive command line into which commands are entered.</li><li>Varying levels of scripting; i.e. short programs in a concise syntax that can executed non-interactively using variables and simple flow control.</li><li>Access permissions to safely administer computer resources.</li><li>Many others, but this is a good basic list…</li></ol><p>While I have been using the shell for a while, in order to gain a deeper appreciation for how shell programs work internally I have attempted to write a simple shell program of my own, on Linux, using the system-level API to interact directly with the kernel. Spoiler alert: it’s really hard to make a good shell and you probably will never see mine, unless I know you, which is likely, since not many other people will ever read this. I will demonstrate how it all works using a combination of <strong>sh</strong>, the original Bourne shell, as it is relatively simple in comparison with <strong>bash</strong>, and some system-level C code to show how it all works beneath the hood.</p><p>I’m going to try to explain, more or less, what happens when you start running <strong>sh</strong> and execute the command ls -l.</p><p>When you start up your terminal program, typically there is a default shell already specified, which is read from one of several (often hidden) files located in your home directory. Every user on a system has their own home directory, which contains all of the files that they have created or installed for their own use. Depending on the level of permissions a given user is granted by the system administrator they may have access to additional files and programs, such as information about other users, and the ability to modify system properties.</p><p>When you log into your terminal, on Linux/UNIX-based operating systems, you will often be given a <strong>bash</strong> shell, unless otherwise specified in the file ~/profile. To invoke an instance of different shell you can call it as a command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*UhYuHdxwpgmtwpwp" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/0*OgQhxiSKmEuRWhGf.png" /></figure><p>As you can see, my (nicely colored) command prompt from <strong>bash</strong> changes to a simple $ once I begin a simple <strong>sh</strong> session. I am now operating from within a subprocess of the original <strong>bash</strong> session that I started up with. This is an important point to be aware of. Most commands entered on the command line are executed as a subprocess and are given a totally separate virtual memory during their execution. When they complete their execution or encounter an error, they return to the calling process, such as <strong>bash</strong> or <strong>sh</strong>. As a consequence, changes made in the subshell do not affect the parent shell, which I will explore more thoroughly below.</p><p>Shell programs are typically initialized with a number of variables that affect their execution environment and provide information about where commands are located and how to display them on the screen. One critical variable is called PATH. Within the PATH variable is stored a list of directories that the shell should search when a user enters a command after the prompt. For example, when I enter ls without any arguments <strong>sh</strong> will find absolute path of ls to be /bin/ls. The which command, itself located at /usr/bin/which let’s me know where the executable is located.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*NX7HjGMnu3P_ISN6" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/0*quD763XH106x8bKY.png" /></figure><p>Not all commands are executable programs in this sense, however. Shell programs provide <em>builtin</em> functions that are hardwired into the shell source code. Some of these are written into the shell by convenience, while others are written this way by necessity. The type function, which is a shell <em>builtin</em>, will tell you whether its argument is an executable or internal to the shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*mFCnK38ud1MPUT8y" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/0*lVshP4stMK_j584B.png" /></figure><p>To appreciate why this is necessary you have to know a bit about how processes deal with memory. When a child process is spawned from a parent process it inherits its environment and whatever variables were set to be exported to its children. Child processes are unable to alter their parental environments, however. As a result, any operation that requires altering or interacting with the parent process directly requires the parent to perform this for itself. The execution environment, which the kernel keeps track of, includes things like the <em>user ID</em>, permissions, and current directory of the process. So, if you want to change the current directory, the only way to do it is to make a system call from the process whose directory you want to change. Thus, cd has to be implemented as a <em>builtin</em> and uses a <em>system call</em> (aside: there are always convoluted ways to get around — or break — these restrictions, but by and large, the kernel must be invoked to manage such tasks).</p><p>System calls are the interface between user-space and kernel-space. It all boils down to ~1700 commands (at last check; cf. <em>The Linux Programming Interface) </em>that the operating system provides for input, output, and managing the file system.</p><p>Here is an example of short program to <em>fork</em> a process and execute a program before returning to the main program (notably using only system calls, including write, wait, fork, andexecve):</p><pre>#include &lt;unistd.h&gt;<br>#include &lt;sys/types.h&gt;<br>#include &lt;sys/wait.h&gt;<br><br>int main(int argc, char *argv[], char *envp[])<br>{<br>    pid_t child; // To store the child process ID returned by fork()<br>    char *command[] = {&quot;/bin/ls&quot;, &quot;-l&quot;, NULL}; // execve expects an array of strings, starting with the command<br>    int status; // Used to capture the result of executing `ls -l&#39;<br>  <br>    child = fork();<br>    if (child == -1) // If fork() fails it does not create a child and returns -1<br>      write(1, &quot;Problems\n&quot;, 9);<br>    if (child == 0) // In the child process<br>    {<br>        if (execve(command[0], command, envp)) // execve only returns if it encountered an error<br>        {<br>            write(1, &quot;Child Problems\n&quot;, 15);<br>            return(-1);<br>        }<br>    }<br>    if (child &gt; 0)<br>    {<br>        wait(&amp;status);<br>        if (status == 0)<br>          write(1, &quot;Success!\n&quot;, 9);<br>        else<br>          write(1, &quot;Uhhh...\n&quot;, 8);<br>    }<br>    return (status);<br>}<br></pre><p>unistd.h is an important header file that gives access to the underlying Linux system calls. It is not part of the standard library, but underlies all of the GCC library source code. Amazingly, the above code compiles and runs ls -l as requested. Proof:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*SXhF4oB2hje73Azk" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/0*6iwUme5p6ZPa2MAc.png" /></figure><p>The <em>fork</em>, <em>execve, wait</em> paradigm is a hallmark of setting up and using a child process. The fork() system call copies everything from the memory of the currently executing process into a new process. It returns the <em>process id</em> of the child process to the calling process (the parent). In contrast, it returns 0 to the child process. This allow you to write a single program that can determine which process it is looking at. Since it only returns 0 to the child process, by checking the value of child in the above code it is possible to do different things in the parent and child, which exactly what we want. Here, we are executing the ls -l command in the child and waiting in the parent for the return value.</p><p>While processes spawned using fork() have a parent-child relationship, calls to execve() produce a sibling process. That is, after <em>forking</em> the child, <em>execve</em> replaces the entire memory of the calling (child) process with its own memory and behaves as a completely separate program. Before execve(), the child possesses an exact copies of all code and data in the scope of the parent at the time of <em>forking</em>. execve(), then, overwrites the memory of its calling process if it is able to execute the specified program. If it succeeds, it severs the connection to the parent and goes on to live on its own in the real world…</p><p>While all of this is going on, the parent process can either keep on executing until it returns (leaving the child process with nowhere to return its exit status), or it can pause its own execution until the child process finishes executing. Even though the connection between the <em>exec’d </em>child and parent is severed, the kernel is aware of all processes. The system call wait() essentially requests information about any existing child processes from the kernel, which sends a signal back to the parent to resume execution when a signal set by the child process tells the kernel that the child has finished executing. Once this happens, wait() relays the exit status of the child and returns control to the parent. Finally, the parent can rest easy knowing the child process completed successfully.</p><p>Of course, not all processes are so lucky. When memory is limited, or the maximum number of processes allowed by the system are already running, various errors will be set by the system, which the parent can check before proceeding. A hallmark of system calls is that they must be very robust to all sorts of invalid input or resource limitations to preserve the integrity of the file system. Programmers should check all possible errors when using system calls.</p><p>When calling execve(), besides the possibility that the file you are hoping execute does not exist, other expected sources of error include incorrect permissions of the user executing the parent program, which are inherited by all the children, or file locks due to another process interacting with the requested file simultaneously. Complications due to the latter type of problem can become extremely hairy when dealing with large, multiuser systems and presage issues surrounding concurrency and threading.</p><p>The shell uses the <em>fork</em>, <em>execve, wait</em> paradigm for virtually all its processes, apart from <em>builtins</em>, however to have useful shell there is another layer to getting repeated input. When you enter some text on the command line and press return, all of that text gets passed to the <em>stdin</em> file stream. This is where input is stored before being read and interpreted by your program. Unlike the example program above, in which I hardcoded the path to the executable, a shell program has to accept arbitrary input from the user and request the correct resources in response. To do this, it goes through repeating loop of:</p><ol><li>Getting input using read(), or the library function wrapper getline().</li><li>Tokenizing input into separate tokens (e.g. splitting at whitespace and separating commands at semicolons and ampersands).</li><li>Performing pattern matching, e.g. via *’s and brace expansions.</li><li>Searching for a matching command (first among <em>aliases</em>, then <em>builtins</em>, then external programs in PATH directories).</li><li>If found, it then executes the command in a child process, or displays some error message.</li><li>Then prints the prompt again and prepares itself for further input.</li></ol><p>This is typically implemented in a while loop that breaks only when the program is no longer receiving input from <em>stdin</em>. When a request to the read() system call generates no data from <em>stdin — </em>or possibly a script or a pipe — the shell interprets it as a signal to exit back to its calling process, <strong>bash</strong> in our case. Interestingly, any unclaimed children of a process, aka “zombies”, that are still hanging around a process exits are “adopted” by the mother of all processes, called init, the first and last process to run when a Linux operating system starts up and shuts down.</p><p>A truly simple shell — absolutely no bells or whistles — using all of the above information could then be implemented like so:</p><p>Check it out:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*72RgTis4T7ekUjWY" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/0*WCb9wQTdraK6utcp.png" /></figure><p>There are a couple things I’d like to point out:</p><p>First, it worked, which is really nice.</p><p>Second, the entered commands produce the same result, including with arguments beyond the command path. This is because they are just the same old executables executing in their own processes, as usual.</p><p>Third, I can even spawn an instance of <strong>bash</strong> within my <strong>verysimpleshell</strong>. You see that the command line changes to my fancy colored prompt after calling /bin/bash. Then I can call exit — a <strong>bash</strong> <em>builtin</em> — and return to <strong>verysimpleshell</strong>. In contrast to a fully featured shell, like <strong>bash</strong>, if I try to call echo in my shell without the full path it fails because it doesn’t know anything about the PATH variable.</p><p>Fourth, to quit my shell I type control-D. This flushes the stdin and signals EOF, or <em>end-of-file</em>, as getline() has received no further data from a call to read(), and returns -1. I check for this in the loop, and then break, free, and exit.</p><p>Made by Hedfi Ghassen And Benna Ala</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=edfc77e92b9a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[steps of compilation]]></title>
            <link>https://medium.com/@3681/steps-of-compilation-5c02935a3904?source=rss-5729a8fdfd59------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c02935a3904</guid>
            <dc:creator><![CDATA[ghassenehedfi]]></dc:creator>
            <pubDate>Thu, 30 Sep 2021 21:24:09 GMT</pubDate>
            <atom:updated>2021-09-30T21:24:09.622Z</atom:updated>
            <content:encoded><![CDATA[<p>The compilation is a process of converting the source code into object code. It is done with the help of the compiler. The compiler checks the source code for the syntactical or structural errors, and if the source code is error-free, then it generates the object code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*Y-mpudS8sQVzsw6U3PyQ-w.png" /></figure><p>The c compilation process converts the source code taken as input into the object code or machine code. The compilation process can be divided into four steps, i.e., Pre-processing, Compiling, Assembling, and Linking.</p><p>The preprocessor takes the source code as an input, and it removes all the comments from the source code. The preprocessor takes the preprocessor directive and interprets it. For example, if <strong>&lt;stdio.h&gt;,</strong> the directive is available in the program, then the preprocessor interprets the directive and replace this directive with the content of the <strong>‘stdio.h’</strong> file.</p><p>The following are the phases through which our program passes before being transformed into an executable form:</p><ul><li><strong>Preprocessor</strong></li><li><strong>Compiler</strong></li><li><strong>Assembler</strong></li><li><strong>Linker</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*i38MSoYXaWwekvHTzNOAXQ.png" /></figure><h3>Preprocessor</h3><p>The source code is the code which is written in a text editor and the source code file is given an extension “.c”. This source code is first passed to the preprocessor, and then the preprocessor expands this code. After expanding the code, the expanded code is passed to the compiler.</p><h3>Compiler</h3><p>The code which is expanded by the preprocessor is passed to the compiler. The compiler converts this code into assembly code. Or we can say that the C compiler converts the pre-processed code into assembly code.</p><h3>Assembler</h3><p>The assembly code is converted into object code by using an assembler. The name of the object file generated by the assembler is the same as the source file. The extension of the object file in DOS is ‘.obj,’ and in UNIX, the extension is ‘o’. If the name of the source file is <strong>‘hello.c’,</strong> then the name of the object file would be ‘hello.obj’.</p><h3>Linker</h3><p>Mainly, all the programs written in C use library functions. These library functions are pre-compiled, and the object code of these library files is stored with ‘.lib’ (or ‘.a’) extension. The main working of the linker is to combine the object code of library files with the object code of our program. Sometimes the situation arises when our program refers to the functions defined in other files; then linker plays a very important role in this. It links the object code of these files to our program. Therefore, we conclude that the job of the linker is to link the object code of our program with the object code of the library files and other files. The output of the linker is the executable file. The name of the executable file is the same as the source file but differs only in their extensions. In DOS, the extension of the executable file is ‘.exe’, and in UNIX, the executable file can be named as ‘a.out’. For example, if we are using printf() function in a program, then the linker adds its associated code in an output file.</p><p><strong>Let’s understand through an example.</strong></p><p><strong>hello.c</strong></p><ol><li>#include &lt;stdio.h&gt;</li><li><strong>int</strong> main()</li><li>{</li><li>printf(“Hello javaTpoint”);</li><li><strong>return</strong> 0;</li><li>}</li></ol><p><strong>Now, we will create a flow diagram of the above program:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/1*9V0k1fn5TcSd3YU3bS7U_g.png" /></figure><h3>What is gcc?</h3><p><strong>G</strong>NU <strong>C</strong>ompiler <strong>C</strong>ollection. In few words it is a compiler system.</p><h3>What happens when you invoke GCC?</h3><p>When you invoke GCC , it normally does preprocessing, compilation, assembly and linking. <strong>Those are the four steps of compilation</strong>.</p><h3>Explaining the four steps of compilation…</h3><h3>1. Preprocessing</h3><p>Prepares the code for procesing. It removes the comments and complement the code.</p><blockquote><em>$ gcc -E</em></blockquote><blockquote><em>Preprocess only, do not compile, assemble or link.</em></blockquote><h3>2. Compilation</h3><p>During the compilation process the code C is transformed into the assembly language of our machine</p><blockquote><em>$ gcc -S</em></blockquote><blockquote><em>Compile only, do not assemble or link.</em></blockquote><blockquote><em>$ gcc -c</em></blockquote><blockquote><em>Compile and assemble, do not link.</em></blockquote><h3>3. Assembly</h3><p>In this stage the assembly language is transformed to object code (also named machine code)</p><h3>4. Linking</h3><p>In this step it link the libraries and C files into an executable file.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c02935a3904" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is the difference between a hard link and a symbolic link?]]></title>
            <link>https://medium.com/@3681/what-is-the-difference-between-a-hard-link-and-a-symbolic-link-754d7facebd?source=rss-5729a8fdfd59------2</link>
            <guid isPermaLink="false">https://medium.com/p/754d7facebd</guid>
            <dc:creator><![CDATA[ghassenehedfi]]></dc:creator>
            <pubDate>Wed, 29 Sep 2021 10:11:46 GMT</pubDate>
            <atom:updated>2021-09-29T10:11:46.463Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*Ix7F9fy5hGpBNRCO2std9Q.png" /></figure><p>Both <strong>hard links</strong> and <strong>symbolic links</strong> are methods of linking one file to another on a hard drive. A system is made up of several files which are each referenced on the hard drive by what is called an <strong>inode</strong>. In short before going into details, we will see that a <strong>hard link</strong> is a copy of a file that points to the same <strong>inode</strong>, when a <strong>symbolic link</strong> is linked only to the file in question</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=754d7facebd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>