<?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 Cihat Yildiz on Medium]]></title>
        <description><![CDATA[Stories by Cihat Yildiz on Medium]]></description>
        <link>https://medium.com/@cihatyildiz?source=rss-292cafac5654------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*jSbpTcDP_42yvNYi.jpeg</url>
            <title>Stories by Cihat Yildiz on Medium</title>
            <link>https://medium.com/@cihatyildiz?source=rss-292cafac5654------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 07:20:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cihatyildiz/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[Linux Capabilities for Enhancing Security]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/hackerspot/linux-capabilities-for-enhancing-security-32c7c491198e?source=rss-292cafac5654------2"><img src="https://cdn-images-1.medium.com/max/680/0*3o2oXK3yReQiKvbA.jpeg" width="680"></a></p><p class="medium-feed-snippet">Linux Capabilities are a fundamental security feature that allows for granular control over what processes can and cannot do within a&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/hackerspot/linux-capabilities-for-enhancing-security-32c7c491198e?source=rss-292cafac5654------2">Continue reading on HackerSpot »</a></p></div>]]></description>
            <link>https://medium.com/hackerspot/linux-capabilities-for-enhancing-security-32c7c491198e?source=rss-292cafac5654------2</link>
            <guid isPermaLink="false">https://medium.com/p/32c7c491198e</guid>
            <category><![CDATA[security-configuration]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[os-security]]></category>
            <category><![CDATA[linux-security]]></category>
            <category><![CDATA[information-security]]></category>
            <dc:creator><![CDATA[Cihat Yildiz]]></dc:creator>
            <pubDate>Fri, 08 Nov 2024 20:46:56 GMT</pubDate>
            <atom:updated>2024-11-08T20:46:56.920Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Secret Management on Secure Application Development]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://cihatyildiz.medium.com/secret-management-on-secure-application-development-5816ad608414?source=rss-292cafac5654------2"><img src="https://cdn-images-1.medium.com/max/1024/1*NTszTbiKPk4uA_uwORvvWA.jpeg" width="1024"></a></p><p class="medium-feed-snippet">Applications are becoming more complex and interconnected every day, so it&#x2019;s important to securely manage secrets like API keys, database&#x2026;</p><p class="medium-feed-link"><a href="https://cihatyildiz.medium.com/secret-management-on-secure-application-development-5816ad608414?source=rss-292cafac5654------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://cihatyildiz.medium.com/secret-management-on-secure-application-development-5816ad608414?source=rss-292cafac5654------2</link>
            <guid isPermaLink="false">https://medium.com/p/5816ad608414</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[devsecops]]></category>
            <category><![CDATA[information-security]]></category>
            <category><![CDATA[privacy]]></category>
            <dc:creator><![CDATA[Cihat Yildiz]]></dc:creator>
            <pubDate>Fri, 18 Oct 2024 17:22:08 GMT</pubDate>
            <atom:updated>2024-10-18T17:22:08.033Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[The Story of Minecraft]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-snippet">Minecraft is not just a game; it&#x2019;s a global phenomenon that has transformed how we think about creativity, exploration, and even education&#x2026;</p><p class="medium-feed-link"><a href="https://cihatyildiz.medium.com/the-story-of-minecraft-5f95be4c14b8?source=rss-292cafac5654------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://cihatyildiz.medium.com/the-story-of-minecraft-5f95be4c14b8?source=rss-292cafac5654------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f95be4c14b8</guid>
            <category><![CDATA[game-design]]></category>
            <category><![CDATA[games]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Cihat Yildiz]]></dc:creator>
            <pubDate>Mon, 26 Aug 2024 07:21:03 GMT</pubDate>
            <atom:updated>2024-08-26T07:21:03.570Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Understanding Server-Side Template Injection (SSTI)]]></title>
            <link>https://medium.com/hackerspot/understanding-server-side-template-injection-ssti-5f910ee0318f?source=rss-292cafac5654------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f910ee0318f</guid>
            <dc:creator><![CDATA[Cihat Yildiz]]></dc:creator>
            <pubDate>Fri, 21 Jun 2024 15:52:33 GMT</pubDate>
            <atom:updated>2024-06-21T15:52:33.034Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the less commonly discussed vulnerabilities is Server-Side Template Injection (SSTI). SSTI is an attack vector that can lead to severe consequences, including remote code execution, data leakage, and server compromise. This blog post aims to comprehensively understand SSTI, including its mechanisms, risks, detection methods, and mitigation strategies.</p><h3>What is Server-Side Template Injection?</h3><p>Server-side template Injection occurs when user input is unsafely embedded into a template rendered on the server. This vulnerability exploits the templating engine used by the web application. If the templating engine processes user-supplied data without proper sanitization, attackers can inject malicious payloads that the server executes.</p><h3>How Does SSTI Work?</h3><p>To understand SSTI, we first need to understand how templating engines work. Templating engines allow developers to create dynamic web pages by embedding logic within HTML. Popular templating engines include Jinja2 (Python), Thymeleaf (Java), Twig (PHP), and others.</p><p>For instance, a simple template in Jinja2 might look like this:</p><pre>&lt;h1&gt;Welcome, {{ username }}&lt;/h1&gt;</pre><p>If username is controlled by user input and not properly sanitized, an attacker could input a payload like {{ 7*7 }}. The server would render the template and output 49, indicating that the template engine evaluated the expression.</p><h3>The Risks of SSTI</h3><p>The risks associated with SSTI are significant and can vary depending on the capabilities of the templating engine. The most severe consequence is remote code execution, where an attacker can run arbitrary code on the server. Other risks include:</p><ol><li><strong>Data Leakage</strong>: Attackers can access sensitive data stored on the server.</li><li><strong>Denial of Service (DoS)</strong>: Crafting payloads that consume server resources, leading to service disruption.</li><li><strong>Server Compromise</strong>: Gaining further access to the server environment and potentially the internal network.</li></ol><h3>Real-World Examples</h3><p>Several real-world incidents have highlighted the dangers of SSTI. For example, a Python-based templating engine Jinja2 vulnerability allowed attackers to achieve remote code execution by injecting specific payloads into a vulnerable application. Similarly, the Twig templating engine in PHP has been exploited.</p><p><strong>Some Examples from ExploitDB:</strong></p><ul><li><a href="https://www.exploit-db.com/exploits/51499">OffSec&#39;s Exploit Database Archive</a></li><li><a href="https://www.exploit-db.com/exploits/51893">OffSec&#39;s Exploit Database Archive</a></li><li><a href="https://www.exploit-db.com/exploits/51948">OffSec&#39;s Exploit Database Archive</a></li></ul><h3>Detecting SSTI Vulnerabilities</h3><p>Detecting SSTI requires a combination of automated tools and manual testing. Here are some steps to identify potential SSTI vulnerabilities:</p><ol><li><strong>Input Points Identification</strong>: Identify where user input is incorporated into templates.</li><li><strong>Payload Testing</strong>: Inject common SSTI payloads (e.g., {{ 7*7 }}, ${{7*7}}, &lt;%= 7*7 %&gt;) and observe the server’s response.</li><li><strong>Error Messages</strong>: Look for error messages or unusual behavior that might indicate template processing.</li><li><strong>Automated Scanners</strong>: Use automated security scanners designed to detect SSTI vulnerabilities.</li></ol><h3>Preventing SSTI</h3><p>Preventing SSTI involves adhering to best practices for secure coding and input handling. Key strategies include:</p><ol><li><strong>Input Sanitization and Validation</strong>: Always sanitize and validate user input before processing it within templates.</li><li><strong>Contextual Escaping</strong>: Use appropriate escaping mechanisms for the context where the input will be used.</li><li><strong>Template Engine Configuration</strong>: Configure the template engine to disable or restrict the execution of arbitrary code.</li><li><strong>Use Safe Templating Engines</strong>: Prefer templating engines designed with security, offering built-in protections against injection attacks.</li><li><strong>Security Training</strong>: Educate developers about the risks of SSTI and secure coding practices.</li></ol><h3>Example: Secure Template Handling</h3><p>Consider the following insecure template rendering in Python with Jinja2:</p><pre>from jinja2 import Template<br><br>user_input = request.args.get(&#39;name&#39;)<br>template = Template(&#39;&lt;h1&gt;Hello, {{ name }}!&lt;/h1&gt;&#39;)<br>rendered = template.render(name=user_input)</pre><p>An attacker could inject a payload such as {{ config.items() }}, leading to the exposure of configuration variables. To secure this, you should sanitize the input:</p><pre>from jinja2 import Template, escape<br><br>user_input = escape(request.args.get(&#39;name&#39;))<br>template = Template(&#39;&lt;h1&gt;Hello, {{ name }}!&lt;/h1&gt;&#39;)<br>rendered = template.render(name=user_input)</pre><h3>Advanced Mitigation Techniques</h3><p>In addition to basic sanitization and validation, consider implementing advanced security measures:</p><ol><li><strong>Content Security Policy (CSP)</strong>: Use CSP to limit the sources from which scripts can be loaded and executed.</li><li><strong>Web Application Firewall (WAF)</strong>: Deploy a WAF to detect and block malicious requests targeting SSTI vulnerabilities.</li><li><strong>Regular Security Audits</strong>: Conduct regular security audits and code reviews to identify and fix vulnerabilities.</li></ol><h3>Conclusion</h3><p>Server-side template Injection (SSTI) is a potent vulnerability that can lead to severe consequences if not properly addressed. Understanding the mechanisms, risks, and mitigation strategies associated with SSTI is crucial for building secure web applications. By adhering to best practices for input handling, using secure templating engines, and regularly auditing your code, you can significantly reduce the risk of SSTI and protect your applications from potential attacks.</p><p>In the ever-evolving web security landscape, staying informed and proactive is the key to safeguarding your digital assets.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f910ee0318f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackerspot/understanding-server-side-template-injection-ssti-5f910ee0318f">Understanding Server-Side Template Injection (SSTI)</a> was originally published in <a href="https://medium.com/hackerspot">HackerSpot</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Top LeetCode Challenges to Ace Your Information Security Interviews]]></title>
            <link>https://medium.com/hackerspot/top-leetcode-challenges-to-ace-your-information-security-interviews-40baa9671088?source=rss-292cafac5654------2</link>
            <guid isPermaLink="false">https://medium.com/p/40baa9671088</guid>
            <category><![CDATA[leetcode-easy]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[information-security]]></category>
            <dc:creator><![CDATA[Cihat Yildiz]]></dc:creator>
            <pubDate>Sun, 09 Jun 2024 15:25:05 GMT</pubDate>
            <atom:updated>2024-06-09T15:25:05.233Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post, I want to share a curated list of essential questions for those preparing for information security (infosec) roles in the tech industry. Securing an interview and succeeding in software development is highly competitive and depends significantly on your skill level and preparation.</p><p>In the security domain, many companies expect professionals to be well-versed in software development principles. While you don’t need to be an expert coder, a solid understanding of basic concepts is crucial.</p><p>Top-tier companies like Meta and Google often require candidates to solve coding challenges during the interview process. For instance, you might be asked to solve one easy and one medium-level coding problem within 45 minutes or tackle a single question in 30 minutes.</p><p>By focusing on these areas, you can better prepare yourself for the technical challenges and expectations of infosec roles in leading tech companies. Here are some questions that you can prepare:</p><h3>Easy Questions</h3><p><strong>Two Sum</strong></p><ul><li><strong>Problem:</strong> Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.</li><li><strong>Focus:</strong> Hash maps, array traversal.</li><li><a href="https://leetcode.com/problems/two-sum/description/">https://leetcode.com/problems/two-sum/</a></li></ul><p><strong>Reverse String</strong></p><ul><li><strong>Problem:</strong> Write a function that reverses a string. The input string is given as an array of characters s.</li><li><strong>Focus:</strong> Two-pointer technique, in-place modifications.</li><li><a href="https://leetcode.com/problems/reverse-string/description/">https://leetcode.com/problems/reverse-string/</a></li></ul><p><strong>Valid Anagram</strong></p><ul><li><strong>Problem:</strong> Given two strings s and t, return true if t is an anagram of s, and false otherwise.</li><li><strong>Focus:</strong> Hash maps, string manipulation.</li><li><a href="https://leetcode.com/problems/valid-anagram/description/">https://leetcode.com/problems/valid-anagram/</a></li></ul><p><strong>Merge Two Sorted Lists</strong></p><ul><li><strong>Problem:</strong> Merge two sorted linked lists and return it as a new sorted list.</li><li><strong>Focus:</strong> Linked lists, recursion.</li><li><a href="https://leetcode.com/problems/merge-two-sorted-lists/description/">https://leetcode.com/problems/merge-two-sorted-lists/</a></li></ul><p><strong>Best Time to Buy and Sell Stock</strong></p><ul><li><strong>Problem:</strong> Given an array prices where prices[i] is the price of a given stock on the i-th day, maximize the profit.</li><li><strong>Focus:</strong> Array traversal, greedy algorithm.</li><li><a href="https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/">https://leetcode.com/problems/best-time-to-buy-and-sell-stock/</a></li></ul><h3>Medium Questions</h3><p><strong>Add Two Numbers</strong></p><ul><li><strong>Problem:</strong> You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.</li><li><strong>Focus:</strong> Linked lists, elementary math.</li><li><a href="https://leetcode.com/problems/add-two-numbers/description/">https://leetcode.com/problems/add-two-numbers/</a></li></ul><p><strong>Longest Substring Without Repeating Characters</strong></p><ul><li><strong>Problem:</strong> Given a string s, find the length of the longest substring without repeating characters.</li><li><strong>Focus:</strong> Sliding window technique, hash maps.</li><li><a href="https://leetcode.com/problems/longest-substring-without-repeating-characters/description/">https://leetcode.com/problems/longest-substring-without-repeating-characters/</a></li></ul><p><strong>Group Anagrams</strong></p><ul><li><strong>Problem:</strong> Given an array of strings strs, group the anagrams together.</li><li><strong>Focus:</strong> Hash maps, string manipulation.</li><li><a href="https://leetcode.com/problems/group-anagrams/description/">https://leetcode.com/problems/group-anagrams/description/</a></li></ul><p><strong>Product of Array Except for Self</strong></p><ul><li><strong>Problem:</strong> Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i].</li><li><strong>Focus:</strong> Array manipulation, prefix and suffix products.</li><li><a href="https://leetcode.com/problems/product-of-array-except-self/description/">https://leetcode.com/problems/product-of-array-except-self/</a></li></ul><p><strong>Find the Duplicate Number</strong></p><ul><li><strong>Problem:</strong> Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive, return the duplicate number.</li><li><strong>Focus:</strong> Binary search, Floyd’s Tortoise and Hare (cycle detection).</li><li><a href="https://leetcode.com/problems/find-the-duplicate-number/description/">https://leetcode.com/problems/find-the-duplicate-number/</a></li></ul><p><strong>3Sum</strong></p><ul><li><strong>Problem:</strong> Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.</li><li><strong>Focus:</strong> Sorting, two-pointer technique, handling duplicates.</li><li><a href="https://leetcode.com/problems/3sum/description/">https://leetcode.com/problems/3sum/</a></li></ul><h3>Practice Strategies:</h3><ol><li><strong>Understand the Problem:</strong> Read the problem statement carefully and identify input, output, and constraints.</li><li><strong>Plan the Approach:</strong> Think about the data structures and algorithms you will use. Sketch out the logic on paper if necessary.</li><li><strong>Write Clean Code:</strong> Focus on writing clean, modular, and efficient code. Use meaningful variable names and add comments if necessary.</li><li><strong>Test Thoroughly:</strong> Use both provided test cases and additional edge cases to ensure your solution is robust.</li><li><strong>Optimize:</strong> Look for opportunities to optimize your code if it’s not efficient. Consider time and space complexity.</li></ol><h3>Last Words</h3><p>Remember, practice is key. Consistently solving these problems, analyzing your solutions, and optimizing for efficiency will help you develop a strong problem-solving mindset. By following the practice strategies provided, you can approach each coding challenge methodically, ensuring you write clean, efficient, and robust code.</p><p>Good luck with your preparation, and may your journey toward landing an infosec role in a leading tech company be successful!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40baa9671088" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackerspot/top-leetcode-challenges-to-ace-your-information-security-interviews-40baa9671088">Top LeetCode Challenges to Ace Your Information Security Interviews</a> was originally published in <a href="https://medium.com/hackerspot">HackerSpot</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What to Know About DLL Injection]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-snippet">DLL Injection&#x200A;&#x2014;&#x200A;What Need to Know</p><p class="medium-feed-link"><a href="https://cihatyildiz.medium.com/what-to-know-about-dll-injection-e7aba39b969?source=rss-292cafac5654------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://cihatyildiz.medium.com/what-to-know-about-dll-injection-e7aba39b969?source=rss-292cafac5654------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7aba39b969</guid>
            <dc:creator><![CDATA[Cihat Yildiz]]></dc:creator>
            <pubDate>Fri, 01 Sep 2023 17:32:26 GMT</pubDate>
            <atom:updated>2023-09-01T17:32:26.222Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Creating Custom Docker Base Images: Boost Security and Efficiency]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-snippet">In the modern software development landscape, containerization has emerged as a key element in deploying applications consistently and&#x2026;</p><p class="medium-feed-link"><a href="https://cihatyildiz.medium.com/creating-custom-docker-base-images-boost-security-and-efficiency-84deca0d8d8f?source=rss-292cafac5654------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://cihatyildiz.medium.com/creating-custom-docker-base-images-boost-security-and-efficiency-84deca0d8d8f?source=rss-292cafac5654------2</link>
            <guid isPermaLink="false">https://medium.com/p/84deca0d8d8f</guid>
            <dc:creator><![CDATA[Cihat Yildiz]]></dc:creator>
            <pubDate>Fri, 07 Apr 2023 17:09:08 GMT</pubDate>
            <atom:updated>2023-04-07T17:09:08.288Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Docker Daemon Startup Issues on ARM-based Macs]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-snippet">Docker has become an essential tool for developers, providing a convenient way to containerize and manage applications. However, as with&#x2026;</p><p class="medium-feed-link"><a href="https://cihatyildiz.medium.com/my-docker-deamon-doesnt-start-483f46c37adf?source=rss-292cafac5654------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://cihatyildiz.medium.com/my-docker-deamon-doesnt-start-483f46c37adf?source=rss-292cafac5654------2</link>
            <guid isPermaLink="false">https://medium.com/p/483f46c37adf</guid>
            <dc:creator><![CDATA[Cihat Yildiz]]></dc:creator>
            <pubDate>Wed, 29 Mar 2023 21:47:47 GMT</pubDate>
            <atom:updated>2023-04-07T17:15:37.759Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Define A Custom Search Shortcut in Google Chrome]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://cihatyildiz.medium.com/define-a-custom-search-shortcut-in-google-chrome-441ee92d0bca?source=rss-292cafac5654------2"><img src="https://cdn-images-1.medium.com/max/676/1*_pPLpg_BtcE9ThQNZKTSeg.png" width="676"></a></p><p class="medium-feed-snippet">In this post, I want to share a simple trick that you can do a search on your custom platform such as Medium, confluence, WordPress, etc.</p><p class="medium-feed-link"><a href="https://cihatyildiz.medium.com/define-a-custom-search-shortcut-in-google-chrome-441ee92d0bca?source=rss-292cafac5654------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://cihatyildiz.medium.com/define-a-custom-search-shortcut-in-google-chrome-441ee92d0bca?source=rss-292cafac5654------2</link>
            <guid isPermaLink="false">https://medium.com/p/441ee92d0bca</guid>
            <dc:creator><![CDATA[Cihat Yildiz]]></dc:creator>
            <pubDate>Mon, 14 Nov 2022 20:33:40 GMT</pubDate>
            <atom:updated>2022-11-14T20:33:40.659Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Win32 System Programming]]></title>
            <link>https://cihatyildiz.medium.com/win32-system-programming-996f702c162?source=rss-292cafac5654------2</link>
            <guid isPermaLink="false">https://medium.com/p/996f702c162</guid>
            <category><![CDATA[win32]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[system-programming]]></category>
            <category><![CDATA[c]]></category>
            <dc:creator><![CDATA[Cihat Yildiz]]></dc:creator>
            <pubDate>Sun, 28 Aug 2022 06:31:08 GMT</pubDate>
            <atom:updated>2022-08-28T17:42:05.837Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>This note was created in the “Windows System Programming” course that was given by “C and System programmers Accosiaion” in 2016. Kaan Arslan was the lecturer in this course.</blockquote><p>Bu yazida, daha once yayinlamis oldugum C ve sistem prgramcilari derneginden almis oldugum windows sistem programlama kursu kurs notlarini tekrar bir araya getirdim. Bu kurs C ve System programcilari dernegi tarafindan 2014 yili eylul ayinda alinisti.</p><h3>Temel Kavramlar</h3><p>İşletim sistemi bilgisayar temel donanımını yöneten kullanıcı ile sistem arasında arayüz oluşturan bir sistem yazılımıdır. Sistemler temelde iki bolume ayrilirlar.</p><ul><li>kernel (cekirdek)</li><li>Shell (kabul)</li></ul><p>Windows daki desktop uygulamasi bir kabuktur. Aynı şekilde Linuxda da bash bir bir kabuktur. İşletim Sistemi Alt Sistemleri</p><ul><li>Proses yöneticisi</li><li>Dosya sistemi</li><li>Network alt sistemi</li><li>Programın RAM’de nerelere yerleştirileceğine karar veren bellek yöneticisi</li><li>Çizelgeleyici</li></ul><p>İşletim Sistemlerinin Sınıflandırılması</p><ul><li>Multiprocessing sistemleri — ayni anda birden fazla programi calistirabilen sistemleri</li><li>preemptive</li><li>non-preemptive</li></ul><p>Single processing sistemler — ayni anda tek bir programi calistirabilen sistemleri — Cizelgeleyici sisteme gore</p><ul><li>Realtime isletim sistemleri</li><li>Hard realtime</li><li>Soft realtime</li></ul><p>Desktop isletim sistemi kernele gore</p><ul><li>monolitik kernel (linux)</li><li>microkernel (windwos) Darvin &gt; zunu &gt;</li></ul><p>mac sistemlerin cekirdegi acik bir sistemdir. hibrit bir sistemdir.macosx internals kitaplari okunmasi gereken onemli kitaplar <a href="https://www.tiobe.com/">www.tiobe.com</a> index icerisinde yapilan arastirmalarda Functional paradigma — f# haskel etc.</p><p>Isletim sistemi sistem fonksiyonlari</p><ul><li>windows da api fonksiyonlari</li><li>linux da system calls olarak adlandirilir.</li></ul><p>isletim sistemleri pure c ile yazilmistir. Object Oriented teknik performansi azaltici ozelliklere sahip oldugu icin isletim sistemlerinde kullanilmaz OS icerisindeki her fonksiyon cagirilamaz. sana izi erilen fonksiyonlari kullanabilirsin api fonksiyonlari ni bimek tam olarak yeterli degil. Bu fonksiyonlarin isleyis mantiklarini da bilmek gerekmektedir.</p><h3>İşlemcilerin Koruma Mekanizması</h3><p>isletim sistemi ram da calisan bir kod. Ramz icerisinde farkli programlarin calistigi alanlara mudahale etmemelk gerekmektedir. Bir process ile kendine ait bir ram bolgesine erismek istedigin zaman isletim sistemi tarafinda engellenir. Buna koruma mekanizmasi denir. belirli komutlari da kullanamzsin Bu nedenle uygulamalar ikiye ayrilir.</p><ul><li>user mode (butun servis ve processlere erisemez ve butun komutlari calistiramazsin, ozel makina koutlarini calistimazsin.)</li><li>kernel mode (her seyi yapar. butun sistem cagrilarina erisebilir.) Process Kavramı calismakta olan programlara process denir. bir process in gorevi bitikten sonra process sonrlanir. process ile task sozcukleri bazi sistemlerde kucuk fakliliklari olsa da temel de aynidir.</li><li>Bir process iki farkli modda calisir</li><li>kernel mod</li><li>user mod</li><li>Bir process belli bir anda user modda ve kernel modda ola bilir. Process user modda iken bellekte istedigi yere erisemez ve istedigi makina kodlarini kullanamaz kernel modda iken herseyi yapabilir.</li><li>Hic bir guvenlik onlemine takilmadan calisan bir uygulama yazabilmek icin device driver yapmak lazim.</li></ul><h3>fopen — createfile</h3><ul><li>kernel moda gecisin zaman maliyeti var</li><li>isletim sisteminin pekcok sistem fonksiyonu bellekte cesitli veri yapilarina erismekte ve cesitli makina komutlarini kullanmaktadir. Bunun saglanabilmesi icin user moddan kernel moda gecis mekanizmasi olusturlmustur. Ornegin intel terminolojisinde bu mekanizmayi saglayan yapiya kapi(gate) denir.</li><li>isletim sistemlerini yazanlar sistem fonksiyonlarini kapilara yerlestirmistir. Bu fonksiyonlar cagirildiginda User moddan kernel moda otomatik gecis gerceklesir. cagirma bitince yeniden user moda donus yapilir.</li><li>Opensource windows &gt; reactos</li><li>windows da native api &gt; “windows 2000 native api’s” kitabi incelenebilir.</li><li>User moddan kernel moda gecis genel olarak zaman kaybina neden olmaktadir.</li></ul><h3>Zaman Paylaşımlı çalışma</h3><ul><li>quanta suresi 20 ms</li><li>cizelgeleme algortmalari var</li><li>task swirch — context switck</li><li>Hardware interrapt olusturulur.</li><li>Windows ve linux makinalari da 1 ms timer kesmeleri var. Bu kesme ile task switch</li><li>Isletim sistemleri birden fazla processi zaman paylasimli olarak calistirirlar. Bir process bir surecalistirilir. sonra calismasina ara verilip kalinan yer not alinir. Sonra digeri kalinan yerden devam ettirilir. Bu parcali calisma suresine quanta veya quanta suresi denilir. Quanta suresi doldugunda gecis ansizin donanim kesmesi yolu ile yapilir. Bu tur sistemlere preemptive sistemler denir.</li><li>Bu tur olmayan sistemler cooperative sistemlerdir.</li><li>Bu konudaki detaylar isletin sisteminin uyguladigi cizelgeleme algoritmasina baglidir.</li><li>quanta degirinin degisimi ??</li></ul><h3>throughput — birim zamanda yapilan is</h3><ul><li>Cizelgeleme isleminin detaylari genellikle karasiktir. Bir takim kalibrasyonlar yapilmaktatdir.</li><li>Masa ustu isletim sistemleri round robin scheduking ve turevlerini kullanir bu sistemde oncelik grupleri ve quanta suresi farkliliklari olusturulabilir.</li><li>cok islemcili sistemlerde cizelgeleme algoritmalari dafarkliliklar gostermektedir. Ornegin bazi sistemlerde her islemci yada cekirdek icin ayri bir kyruk olusturulur. Bazilarinda ise tek bir kuyruk vardir.</li></ul><p>Bir process islemini bir cpu da kullanmak icin paralel processing (processor efinity)  openmp  .nette paralel task library</p><h3>Processlerin Bloke Olması — Process Blocking</h3><p>Dissal bir olayi baslatan process veya thread ler o olay gerceklesene kadar isletim sistemi tarafindan gecici olarak cizelge disina cikartilirlar. Boylece o olayin gerceklesmesi beklenirken bosa cpu zamani harcanmamis olur. Bu surece processin bloke olmasi denilmektedir.  Bir processin yasam dongusu.tipik olarak soyledir. (Sekil-1)</p><p>Kitap : Windows via c/c++ Kitap : Understanding the linux kernel</p><h3>Proses Kontrol Blogu — Process Control Block</h3><ul><li>Linux da task-struct Windows da eproct,</li><li>Bir processin tum bilgileri ismine process kontrol blogu denilen bir veri yapisinda tutulur. Bu bilgilerden bazilari process id’s, processin erisim haklari (process credentals), procesin calisma dizini (cwd), tahsis ettigi bellek alanlari, tahsis ettigi dosyalar, cevre degiskenleri, task swirch sirasinda kalinan degerleri berlirten yazmac degerleri</li><li>process control block (wikipedia dan incele)</li><li>linux kaynak kodunu incelemek icin o understand c++ kullanilabilir. o lxr.linux.no</li><li>– buun linux kodlarinin o source nav source code navigator. o lind source code analiz</li></ul><h3>Windows API Programlamaya İlişkin Temel Bilgiler</h3><p>Windows API programlama yaparken kaynak kodun içerisine windows.h dosyasi include edilmelidir. Bu dosya içerisinde içerisinde gereken pekçok bildirim vardir. Sistem programlamada yazim stili olarak macar notasyonu (hungarian notation) kullanilir. Macar notasyonuna göre;</p><ul><li>Fonksiyonlar pascal tarzı harflendirilir. Yani her sözcüğün ilk harfi büyüktür. (her sozcugun ilk harfi buyuktur. Fiiller ince kullanilir.)</li><li>o GetWindowLong(), CreateProcess()</li><li>Degiskenler genellikle onun turunu belirten bir önek ile başlatılır. Degişkenler deve notasyonu ile isimlendirilir. (camel notation)</li><li>BYTE, WORD ve DWORD typedef isimleri sırasiyla 1, 2 ve 4 byte lik işaretsiz tam sayı türlerini temsil eder.</li><li>Typedef isimlerindeki P öneki ve LP öneki gösterici anlamına gelir. (Windows 3.x sistemlerinde farkli anlama gelmektedir.)</li><li>Word kavramı donanım ve yazılımda farklıdırlar. Yazılımda 2 byte, ama donanimda register uzunlugu olarak adlandirilirlar.</li><li>Gösterdigi yer const olan const göstericilerde PC veya LPC öneki kullanılır.</li><li>Yazi türleri (char türden göstericiler) SZ yada LPSZ ile baslatilir.</li><li>PSTR, LPSTR, LPCSTR yazıyı gösteren gösterici anlamındadır.</li><li>BOOL türü başarı ve başarısızlığı anlatan bir türdür. INT olarak typedef edilmistir. ( 0 basarisiz, 0 disi basarisiz)</li><li>fonksiyon tanimlarinda in, ”in_out”, ve “__out” ifadeleri sirasiyla ver kullanayim, ver icini ben de doldurayim ve ver icicin doldurayim manasinda kullanilir. CreateProcess() fonksiyonunun msdn icerisindeki dokumani icerisinde gorulebilir.</li><li>kaanaslan.com makale id 49 incele</li></ul><p>Not : foldoc.org Güzel bir web sitesi. Online sözlük.</p><h3>unicode_kullanimi</h3><ul><li><a href="https://www.unicode.org/">www.unicode.org</a></li><li>java ve c# da char turu 2 byte tutar. C de ise 1 byte dir.</li><li>typedef unsigned short wchart;</li><li>32 bi windows sistemlerine gecildiginde unicode kullanimi da devreye girmistir. Butun yazi parametresi alan fonksiyonlardan aslinda 2 tane bulunmektedir. Sonu A ile birenler ASCII sonu W ile bitenler UNICODE anlamina gelmektedir.</li><li>Biz program yazarken genellikle A ve W olmayan isimleri kullaniriz bu isimler duruma gore A ve W lu bicime donusturulurler.</li><li>IDE de bu ayar proje seceneklerinden yapilmaktadir ve default durum UNICODE bicimindedir.</li><li>CreateProcessA (ascii)</li><li>CreateProcessW (unicode)</li></ul><p>C de ascii string “xxxx” biciminde, unicode string L”xxxxx” biciminde yazilir. Eger programimizi ascci ile unicode arasinda istedigimiz zaman cevirebilecegimiz bicimde yazmak istiyorsak. Butun iki tirnaklari TEXT macrosu ile girmeliyor.</p><pre>#ifdef UNICODE<br>#define TEXT() L##S<br>#else<br>#define TEXT(,) S<br>#endif</pre><ul><li>Ayrica Standat C fonksiyonlarinin ascii ve unicode versiyonlari vardir. Bunlar arasinda otomatik gecis yapmak icin ozel makrolar kullanilmaktadir. Bu makrolar tchar.h dosyasi icerisinde.</li><li>Aslinda standartlara gore printf fonksiyonunun ascii ismi printf unicode ismi wprintf dir. Windowsta “_tprintf” dersek bu ide deki ayara gore wprintf veya printf kullanir</li></ul><h3>HANDLE Kavramı</h3><ul><li>BIr veri yapisina erismekte kullanilan anahtar degerlere handle denir.</li><li>Handle genel olarak bir veri yapisina erismekte kullanilan tekil anahtar degerdir. Handle tipik olarak bir adres formunda bulunabuilir. Bir dizide index belirtiyor olabilir.</li><li>Handle kullanan kisi onun ne anlam ifade ettigini bilmek zorunda degildir.</li><li>Bir handle sisteminde tipik olarak handle sistemini yaratan bir fonksiyon bulunur. Bunlar tipik olarak CreateXxxxx veya OpenXxxx olarak adlandirilir</li><li>Handle sistemini kullanan fonksiyonlar vardir. bunlara biz handle degerini veririz ve giris yaptiririz. Nihayet handle sistemini yok eden fonksiyonalr vardir. Bunlar CloseXxx veya DestroyXxxx olarak adlandirilir.</li></ul><h3>Bir Processin Yaratilmasi</h3><ul><li>windows sistemlerinde bir process yaratmak icin CreateProcess api fonksiyonu kullanilir. Bu dosyayi ram a yukler. Process kontrol blogunu olusturur.</li><li>Ayrica process yaratmak icin shellExecute isimli bir shell apisi de vardir. Fakat shellExecute base bir fonksiiyon degildir. Bu da createProcess fonksiyonunu cagirmaktadir.</li><li>shellExecute base bir fonksiyon degil. Dosya iliskilerini de ayrica inceliyor.</li><li>Kernel e en yakin process yaratma fonksiyonu createProcess fonksiyonudur.</li><li>Process yaratildigi zaman process yaninda bir de thread yaratilir. dwCreationFlags</li><li>CREATE_NEW_CONSOLE — console uygulamasinda yeni bir konsol yaratilmaz. Ancak bu parametre ile yaratilabilir.</li><li>process ceration class ve priorty class da belirtilebilir.</li></ul><pre>BOOL WINAPI CreateProcess(<br>    _In_opt_ LPCTSTR lpApplicationName,<br>    _Inout_opt_ LPTSTR lpCommandLine,<br>    _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,<br>    _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,<br>    _In_ BOOL bInheritHandles,<br>    _In_ DWORD dwCreationFlags,<br>    _In_opt_ LPVOID lpEnvirUnordered List Itemonment,<br>    _In_opt_ LPCTSTR lpCurrentDirectory,<br>    _In_ LPSTARTUPINFO lpStartupInfo,<br>    _Out_ LPPROCESS_INFORMATION lpProcessInformation<br>);<br>/*------------------------------------------------------------------------<br>-<br>    CreateProcess örneği<br>-------------------------------------------------------------------------<br>*/</pre><pre>/* Sample.c */</pre><pre>#include &lt;stdio.h&gt;;<br>#include &lt;stdlib.h&gt;;<br>#include &lt;Windows.H&gt;;</pre><pre>int main(void)<br>{<br>  STARTUPINFO si = {sizeof(STARTUPINFO)};<br>    PROCESS_INFORMATION pi;<br>    char cmdLine[] = &quot;Notepad.exe&quot;;</pre><pre>    if (!CreateProcess(NULL, cmdLine, NULL, NULL, FALSE, <br>                     CREATE_NEW_CONSOLE, NULL, NULL, &amp;si, &amp;pi)) {<br>        fprintf(stderr, &quot;Cannot create process!\n);<br>        exit(EXIT_FAILURE);<br>    }</pre><pre>    printf(&quot;Press ENTER to exit&quot;);<br>    getchar();</pre><pre>    return 0;<br>}</pre><ul><li>Malesef createProcess fonksiyonunun ikinci parametresi fonksiyon tarafindan guncellenmektedir. Yani fonksiyonu buraya birseyler yazip sonra orjinal yaziyi yeniden yuklemektedir. Halbuki C de stringler guncellenemez. Eger edilmeye calisilirsa exception olusur.</li><li>butun cift tirnaklari TEXT makrosu ile vereceksin</li><li>unicode uyumlu fonksiyonleri kullanacaksin</li><li>Char yerine de TCHAR uyumlu olani kullanmakn gerekiyor</li><li>tchar.h icersiinde TEXT() makrosu yerine “_T()” makrosu de kullanilarbilir. Tamamiyle ayni anlama gelmektedir.</li></ul><pre>/*-----------------------------------------------------------------------<br>    CreateProcess örneği (Bir console programı diğerine<br>    çalıştırırsa default olarak aynı console ekranını kullanır.<br>    CREATE_NEW_CONSOLE çalıştırılan uygulama için yeni<br>    bir console ekranınınm yaratılcağı anlamına gelir)<br>-------------------------------------------------------------------------*/</pre><pre>/* Sample.c */</pre><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;Windows.h&gt;</pre><pre>int main(void)<br>{<br>    STARTUPINFO si = {sizeof(STARTUPINFO)};<br>    PROCESS_INFORMATION pi;<br>    char cmdLine[] = &quot;E:\\Dropbox\\Test\\Debug\\Test.exe ali veli selami&quot;;</pre><pre>    if (!CreateProcess(NULL, cmdLine, NULL, NULL, FALSE, <br>                        CREATE_NEW_CONSOLE, NULL, NULL, &amp;si, &amp;pi)) {<br>        fprintf(stderr, &quot;Cannot create process!..\n&quot;);<br>        exit(EXIT_FAILURE);<br>    }</pre><pre>    printf(&quot;Press ENTER to exit&quot;);<br>    getchar();</pre><pre>    return 0;<br>}</pre><pre>/* Test.c */</pre><pre>#include &lt;stdio.h&gt;</pre><pre>int main(int argc, char *argv[])<br>{<br>    int i;</pre><pre>    for (i = 0; i &lt; argc; ++i)<br>        printf(&quot;%s\n&quot;, argv[i]);</pre><pre>    printf(&quot;Press ENTER to exit\n&quot;);<br>    getchar();</pre><pre>    return 0;<br>}</pre><h3>UNICODE / ASCII uyumlu kullanim</h3><pre>/*--------------------------------------------------------------<br>    UNICODE / ASCII uyumlu kullanım<br>--------------------------------------------------------------*/</pre><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;tchar.h&gt;<br>#include &lt;Windows.h&gt;</pre><pre>int main(void)<br>{<br>    STARTUPINFO si = {sizeof(STARTUPINFO)};<br>    PROCESS_INFORMATION pi;<br>    TCHAR cmdLine[] = TEXT(&quot;Notepad.exe&quot;);</pre><pre>    if (!CreateProcess(NULL, cmdLine, NULL, NULL, FALSE, <br>                            CREATE_NEW_CONSOLE, NULL, NULL, &amp;si, &amp;pi)) {<br>        _ftprintf(stderr, TEXT(&quot;Cannot create process!..\n&quot;));<br>        exit(EXIT_FAILURE);<br>    }</pre><pre>    _tprintf(TEXT(&quot;Press ENTER to exit&quot;));<br>    getchar();</pre><pre>    return 0;<br>}<br>/*---------------------------------------------------------------------------<br>    UNICODE / ASCII uyumlu kullanım <br>    (TEXT makrosu yerine _T makrosu da kullanılabilir. UYARI: TEXT<br>    makrosu için Windows.h yeterlidir, _T makrosu için tchar.h gerekir)<br>----------------------------------------------------------------------------*/</pre><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;tchar.h&gt;<br>#include &lt;Windows.h&gt;</pre><pre>int main(void)<br>{<br>    STARTUPINFO si = {sizeof(STARTUPINFO)};<br>    PROCESS_INFORMATION pi;<br>    TCHAR cmdLine[] = _T(&quot;Notepad.exe&quot;);</pre><pre>    if (!CreateProcess(NULL, cmdLine, NULL, NULL, FALSE, <br>                        CREATE_NEW_CONSOLE, NULL, NULL, &amp;si, &amp;pi)) {<br>        _ftprintf(stderr, _T(&quot;Cannot create process!..\n&quot;));<br>        exit(EXIT_FAILURE);<br>    }</pre><pre>    _tprintf(_T(&quot;Press ENTER to exit&quot;));<br>    getchar();</pre><pre>    return 0;<br>}</pre><h3>Shell Execute</h3><pre>HINSTANCE ShellExecute(<br>  \_In\_opt\_  HWND hwnd,<br>  \_In\_opt\_  LPCTSTR lpOperation,<br>  \_In\_      LPCTSTR lpFile,<br>  \_In\_opt\_  LPCTSTR lpParameters,<br>  \_In\_opt\_  LPCTSTR lpDirectory,<br>  \_In\_      INT nShowCmd<br>);</pre><p>ShellExecude ile open ile dosya acarken bu dosya ile iliskilendirilmis olan uygulama ile birlikte acar. doc dosyasi acilirsa word acar, png dosyasi ise goruntu editleme programi ile acar.</p><pre>/*---------------------------------------------------------------<br>    ShellExecute örneği<br>---------------------------------------------------------------*/</pre><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;tchar.h&gt;<br>#include &lt;Windows.h&gt;<br>#include &lt;Shellapi.h&gt;</pre><pre>int main(void)<br>{<br>    if ((DWORD) ShellExecute(NULL, TEXT(&quot;open&quot;), <br>                                TEXT(&quot;Notepad.exe&quot;), NULL, NULL, SW_SHOW) &lt; 32) {<br>        _ftprintf(stderr, TEXT(&quot;cannot execute!..\n&quot;));<br>        exit(EXIT_FAILURE);<br>    }</pre><pre>    _tprintf(TEXT(&quot;Preass ENTER to exit&quot;));<br>    getchar();</pre><pre>    return 0;<br>}<br>/*------------------------------------------------------------<br>    ShellExecute örneği<br>    (ShellExecute dosya ilişkilendirmesine bakar.<br>     Arka planda zaten CreateProcess fonksiyonunu çağırır)<br>-------------------------------------------------------------*/</pre><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;tchar.h&gt;<br>#include &lt;Windows.h&gt;<br>#include &lt;Shellapi.h&gt;</pre><pre>int main(void)<br>{<br>    if ((DWORD) ShellExecute(NULL, TEXT(&quot;open&quot;), TEXT(&quot;Test.txt&quot;), <br>                                NULL, NULL, SW_SHOW) &lt; 32) {<br>        _ftprintf(stderr, TEXT(&quot;cannot execute!..\n&quot;));<br>        exit(EXIT_FAILURE);<br>    }</pre><pre>    _tprintf(TEXT(&quot;Preass ENTER to exit&quot;));<br>    getchar();</pre><pre>    return 0;<br>}</pre><p>Windows da API Fonksiyonlarinin Hata Kodlarinin Elde edilmesi</p><ul><li>Bir api fonksiyonu basarisiz oldugunda onun neden basarisiz oldugunu getLastError fonksiyonu ile elde edebiliriz. Butun error kodlarin windows.h iceriosinde ERROR_XXX sebolik sabitleri ile define edilmistir.</li><li>Error degerlerini yaziya donusturmak icin formatMessage fonksiyornu kullanilir.</li></ul><pre>/*----------------------------------------------------------------------<br>    GetLastError ve FormatMessage fonksiyonları<br>    (ExitSys bu fonksiyonları çağırarak programı sonlandırır)<br>-----------------------------------------------------------------------*/</pre><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;tchar.h&gt;<br>#include &lt;Windows.h&gt;</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status);</pre><pre>int main(void)<br>{<br>    STARTUPINFO si = {sizeof(STARTUPINFO)};<br>    PROCESS_INFORMATION pi;<br>    TCHAR cmdLine[] = TEXT(&quot;xxxxx.exe&quot;);</pre><pre>    if (!CreateProcess(NULL, cmdLine, NULL, NULL, FALSE, <br>                        CREATE_NEW_CONSOLE, NULL, NULL, &amp;si, &amp;pi))<br>        ExitSys(TEXT(&quot;CreateProcess&quot;), EXIT_FAILURE);</pre><pre>    _tprintf(_T(&quot;Press ENTER to exit&quot;));<br>    getchar();</pre><pre>    return 0;<br>}</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status)<br>{<br>    DWORD dwLastError = GetLastError();<br>    LPTSTR lpszErr;<br>    <br>    if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, <br>                        NULL, dwLastError,<br>                        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), <br>                        (LPTSTR) &amp;lpszErr, 0, NULL)) {<br>        _ftprintf(stderr, TEXT(&quot;%s: %s&quot;), lpszMsg, lpszErr);<br>        LocalFree(lpszErr);<br>    }<br>    <br>    exit(status);<br>}</pre><h3>Process Id ve hadle degerleri</h3><ul><li>process id uzerinden handle degerini elde edebilirsin.</li><li>Prcesslerin ID degerleri sistem genelinde tekdir.Biz ID degerini verip handle degerini alabiliriz. Process kontrol bloguna erismekte kullanilan deger hendle degeridir.Dolayisiyla API fonksiyonlari bizden handle degerini istemektedir.</li></ul><h3>Processlerin Sonlanmasi</h3><ul><li>exit fonksiyonu ile process kendisini sonlandirir. exit standart bir C fonksiyonudur.</li><li>Process her zaman bir api ile sonlandirilir. Exit fonksiyonu exitProcess fonksiyonunu cagirir.</li><li>Bir process windowsda aslinda exitProcess api fonksiyonu ile sonlandirilir.</li><li>C nin statndart exit fonksiyonu aslinda bu api fonksiyonunu cagirir.VOID WINAPI ExitProcess( _In_ UINT uExitCode );</li><li>Aslinda bir C programi calismasina main fonksiyonundan baslamaz. Derleyici tarafindan koda yerlestirilmis olan bir yeden baslar ve main fonksiyonu burdan cagirilir. Main bitince akis bu baslangic koduna geri doner. Iste burada Exit uygulanmistir.</li></ul><h3>Processlerin Exit Kodlari</h3><ul><li>Process sonlandiginde isletim sistemine bir exit kodu iletilir.</li><li>C de main fonksiyonunu geri donus degeri int olmak zorundadir. main fonksiyonunu geri donus degeri exit fonksiyonuna arguman yapilir.</li><li>Zombi proses incelenecek (windows da zombi process yok. )</li><li>Proceslerin exit codui process kontrol blogunda saklanir. Dolayisi ile process sonlanip hadle da kapatilis ise artik biz processin exit kodunu alamayiz.</li><li>Bir processin exit kodu GetExitCodeProcess api fonksiyonu ile alinir.</li></ul><pre>BOOL WINAPI GetExitCodeProcess(<br>\_In\_ HANDLE hProcess,<br>\_Out\_ LPDWORD lpExitCode<br>);</pre><ul><li>Calisan processlerin exit codlarini alamayiz. Almaya calisirsak getExitCodeProcess fonksiyonu 259 ozel degerine geri doner.</li></ul><pre>/*------------------------------------------------------------------<br>    Proseslerin exit kodlarının elde edilmesi<br>------------------------------------------------------------------*/</pre><pre>/* Sample.c */</pre><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;tchar.h&gt;<br>#include &lt;Windows.h&gt;</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status);</pre><pre>int main(void)<br>{<br>    STARTUPINFO si = {sizeof(STARTUPINFO)};<br>    PROCESS_INFORMATION pi;<br>    TCHAR cmdLine[] = _T(&quot;E:\\Dropbox\\Test\\Debug\\Test.exe ali veli selami&quot;);<br>    DWORD dwExitCode;<br>    int result;</pre><pre>    if (!CreateProcess(NULL, cmdLine, NULL, NULL, FALSE, <br>                        CREATE_NEW_CONSOLE, NULL, NULL, &amp;si, &amp;pi))<br>        ExitSys(TEXT(&quot;CreateProcess&quot;), EXIT_FAILURE);</pre><pre>    _tprintf(TEXT(&quot;Press ENTER to continue...&quot;));<br>    getchar();</pre><pre>    if (!GetExitCodeProcess(pi.hProcess, &amp;dwExitCode))<br>        ExitSys(TEXT(&quot;GetExitCodeProcess&quot;), EXIT_FAILURE);</pre><pre>    if (dwExitCode == STILL_ACTIVE) {<br>        _tprintf(TEXT(&quot;Process still running...\n&quot;));<br>        exit(EXIT_FAILURE);<br>    }</pre><pre>    _tprintf(TEXT(&quot;Exit code: %lu\n&quot;), dwExitCode);</pre><pre>    return 0;<br>}</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status)<br>{<br>    DWORD dwLastError = GetLastError();<br>    LPTSTR lpszErr;<br>    <br>    if (FormatMessage(  FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, <br>                        NULL, <br>                        dwLastError,<br>                        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), <br>                        (LPTSTR) &amp;lpszErr, <br>                        0, <br>                        NULL)) <br>    {<br>        _ftprintf(stderr, TEXT(&quot;%s: %s&quot;), lpszMsg, lpszErr);<br>        LocalFree(lpszErr);<br>    }<br>    <br>    exit(status);<br>}</pre><pre>/* Test.c */</pre><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;</pre><pre>int main(int argc, char *argv[])<br>{<br>    int i;</pre><pre>    for (i = 0; i &lt; argc; ++i)<br>        printf(&quot;%s\n&quot;, argv[i]);</pre><pre>    printf(&quot;Press ENTER to exit\n&quot;);<br>    getchar();</pre><pre>    exit(100);</pre><pre>    return 0;<br>}</pre><p>VirtualBox da share mount etmek:</p><pre>sudo mount -t vboxsf EDrive EDrive</pre><ul><li>Unix ve linux sistemlerinde process yaratan tek bir fonksiyon vardir o da fork isimli fonksiyondur. pid_t fork(void)</li><li>Fork processin ozdes kopyasindan cikartir. Fakat ust e alt processler arasinda artik bundan sonra hicbir iliski yoktur. Bunlarin gecmisleri aynidir. Ayni kod bolmune sahiptirler. Fakat artik bu kodun ayni bolumunu calistirmak zorunda degildirler.</li><li>Yani fork fonksiyonuna tek bir proses akisi girer ancak iki process cikar.</li><li><a href="http://linux.die.net/man/2/fork">http://linux.die.net/man/2/fork</a> Adresinden ayrintili bilgi edinilebilir.</li><li>Fork fonksiyonundan ust process yaratmis oldugu alt processin ID degeri ile Alt process de 0 degeri ile cikar.</li></ul><pre>pid_t pid; <br>if((pid = fork())== -1){<br>   perror(&quot;Fork&quot;);   exit(EXIT_FAILURE)<br> } <br>if(pid == 0){ // child   <br>    /// Your code will be here.... <br>}</pre><ul><li>UNIX ve Linux sstemlerinde bir programi calistiran bir grup exec fonksiyonu vardir. bu fonksiyonlar mevcut processin bellek alanini bosaltarak yeni bir programi yuklerler ve mevcut processi baska bir program gibi calistirirlar.</li><li>Yani exec isleminden sonra process kontrol blogu degismez. Processin butun haklari ayni kalir.</li></ul><pre>/*---------------------------------------------------------------<br>    UNIX/Linux sistemlerinde fork işlemi<br>-----------------------------------------------------------------*/</pre><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;unistd.h&gt;</pre><pre>int main(void)<br>{<br>    pid_t pid;<br>    <br>    if ((pid = fork()) == -1) {<br>        perror(&quot;fork&quot;);<br>        exit(EXIT_FAILURE);<br>    }<br>    <br>    if (pid == 0) {<br>        printf(&quot;child\n&quot;);<br>    }<br>    else {<br>        printf(&quot;parent\n&quot;);<br>    }<br>    <br>    printf(&quot;ends..\n&quot;);<br>    <br>    return 0;<br>}<br>/*-------------------------------------------------------------------<br>   UNIX/Linux sistemlerinde exec işlemleri<br>---------------------------------------------------------------------*/</pre><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;unistd.h&gt;</pre><pre>int main(void)<br>{<br>    if (execl(&quot;/bin/ls&quot;, &quot;/bin/ls&quot;, &quot;-l&quot;, (char *) NULL) == -1) {<br>        perror(&quot;execl&quot;);<br>        exit(EXIT_FAILURE);<br>    }<br>    <br>    printf(&quot;unreachable code!...\n&quot;);<br>    <br>    return 0;<br>}</pre><pre>/*-------------------------------------------------------------<br>    Tipik bir fork / exec kalıbı<br>---------------------------------------------------------------*/</pre><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;unistd.h&gt;</pre><pre>int main(void)<br>{<br>    pid_t pid;<br>    <br>    if ((pid = fork()) == -1) {<br>        perror(&quot;fork&quot;);<br>        exit(EXIT_FAILURE);<br>    }<br>    <br>    if (pid == 0)<br>        if (execl(&quot;/bin/ls&quot;, &quot;/bin/ls&quot;, &quot;-l&quot;, (char *) NULL) == -1) {<br>            perror(&quot;execl&quot;);<br>            exit(EXIT_FAILURE);<br>        }<br>    <br>    /* only parent executes this code... */<br>    <br>    {<br>        int i;<br>        <br>        for (i = 0; i &lt; 10; ++i) {<br>            printf(&quot;%d\n&quot;, i);<br>            sleep(1);<br>        }<br>    }<br>    <br>    return 0;<br>}</pre><h3>Process Listesinin Elde Edilmesi</h3><ul><li>Windows da sistemdeki processlerin listesini alabilmek icin iki grup apiden faydalanilabilmektedir. Birincisi eski stil toolhelp apileridir. ikincisi yeni stil psapi isimli api grubudur. Bu fonksiyonlarla biz processlerin ID lerini elde ederiz IDleri handle degerlerine donusturebiliriz.</li><li>* toolhelp</li><li>* psapi</li><li>Unix linux sistemlerde proc dosya sistemie bakilmasi gerekmektedir. /proc</li><li>Unix/linux sistemlerinde prosess listesini veren standart fonksiyonlar yoktur. Bu nedenle ps komutunun bazi sistemlerde nasil yazildigi bilinmemektedir. Fakat modern unix turevi sistemler proc dosya sistemini desteklemektedir. Process listesi dogrudan proc dosya sisteminden alinabilir.</li></ul><pre>/*-------------------------------------------------------------<br>    .NET&#39;te proses listesinin elde edilmesi<br>---------------------------------------------------------------\*/</pre><pre>using System;<br>using System.Diagnostics;</pre><pre>namespace CSD<br>{<br>    class App<br>    {<br>        public static void Main()<br>        {<br>            foreach (Process proc in Process.GetProcesses())<br>                Console.WriteLine(proc.ProcessName);<br>        }<br>    }<br>}</pre><p>Windows da tum processlerin listesinin elde edilmesi konusunda bazi problemler vardir. Ornegin 64 bit bir process de EnumProcesses fonksiyonu 32 bit processleri tam olarak elde edememekte 32 de 64 bit processleri tam olarak elde edememektedir. bu nedenle tum listeyi almak icin hem 32 hem 64 bit uygulama calistirilmasi gereklmektedir.</p><pre>/*-----------------------------------------------------------------<br>    Proses listesinin PSAPI fonksiyonlarıyla elde edilmesi<br>-----------------------------------------------------------------*/</pre><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;tchar.h&gt;<br>#include &lt;Windows.h&gt;<br>#include &lt;Psapi.h&gt;</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status);</pre><pre>int main(void)<br>{<br>    DWORD pids[8192];<br>    DWORD dwCount;<br>    HANDLE hProcess;<br>    HMODULE hMod;<br>    DWORD cbNeeded;<br>    char szProcessName[MAX_PATH] = &quot;&lt;unknown&gt;&quot;;<br>    int i;</pre><pre>    if (!EnumProcesses(pids, 8192, &amp;dwCount))<br>        ExitSys(&quot;EnumProcesses&quot;, EXIT_FAILURE);</pre><pre>    for (i = 0; i &lt; dwCount / sizeof(DWORD); ++i) {<br>        if ((hProcess = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, <br>                                            FALSE, pids[i])) == NULL)<br>            continue;<br>        <br>        if (EnumProcessModules( hProcess, &amp;hMod, sizeof(hMod), &amp;cbNeeded))<br>            GetModuleBaseName( hProcess, hMod, szProcessName,<br>                               sizeof(szProcessName)/sizeof(TCHAR) );<br>        printf(&quot;%s\n&quot;, szProcessName);</pre><pre>    }<br>    printf(&quot;\n&quot;);<br>    <br>    return 0;<br>}</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status)<br>{<br>    DWORD dwLastError = GetLastError();<br>    LPTSTR lpszErr;<br>    <br>    if (FormatMessage(  FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, <br>                        NULL, <br>                        dwLastError,<br>                        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), <br>                        (LPTSTR) &amp;lpszErr, <br>                        0, <br>                        NULL)) <br>    {<br>        fprintf(stderr, &quot;%s: %s&quot;, lpszMsg, lpszErr);<br>        LocalFree(lpszErr);<br>    }<br>    <br>    exit(status);<br>}</pre><h3>Processlerin calisma dizinleri</h3><ul><li>Her processin bir calisma dizini vardir. Calisma dizini goreli yol ifadelerinin (path name) cozulmesi icin kullanilir. Process calisirken calisma dizini degistirilebilir.</li><li>Windows da process in calisma dizini process yaratilirken createProcess fonksiyonunda belirtirlir. Eger ilgili parametee NULL gecilirse alt processin calisma dizini ust proccess ile ayni olur.</li><li>UNIX ve Linux Sistemlerinde process in calisma dizini Fork islemi sirasinda dogrudan ust processs den alinoir biz bu sistemlerde calistiracagimiz programin calisma dizinini belirlemek istiyorsak once bir kez fork yapariz. Alt process de henuz exec yapmadan calisma dizinini degistiririz. sonra exec yapariz.</li><li>Kaan aslanin <a href="http://www.kaanaslan.com/resource/article/display">http://www.kaanaslan.com/resource/article/display</a>_article.php?page=1&amp;id=79 adresindeki makale okunmali</li><li>Bir processin calisma dizini get current directory fonksiyonu ile elde edilebilir.</li></ul><pre>DWORD WINAPI GetCurrentDirectory(<br> _In_   DWORD nBufferLength,<br> _Out_  LPTSTR lpBuffer <br>);</pre><p>windowsda path olarak 260 karakterden fazla girilemez. Eger daha uzun path lere erisim saglamak istiyorsak o zaman bir yere kadar path degisimi yapilir ve sonra tekrar path degisimi yapilir. Cok uzun yollardabu yontem izlenmelidir. Processin calisma dizini degistirmek icin windows da SetCurrentDirectory api fonksiyonu kullanilir.</p><pre>BOOL WINAPI SetCurrentDirectory(<br>  \_In\_  LPCTSTR lpPathName<br>);</pre><p>UNIX / Linux sistemlerinde processin calisma dizini getcwd api fonksiyonu ile alinir. Processin calisma dizinini degistirmek icin de chdir fonksiyonu kullanilir.</p><ul><li>UNIX / Linux sistemlerinde bir surucu kavrami yoktur. Ancak windows sistemlerinde bu kavram vardir.</li><li>Windows cevre degiskenleri yolu ile her surucu icin ayri bir default calisma dizini tutmaktadir. Ayrica processine iliskin surucu aktif surucudur. Eger yol ifadesinde surucuden sonra bir ter bolu () isareti kullanimamissa bu gorev yol ifadesidir. Dolayisi ile processin calismadizininden itibaren yer belirtir.</li><li>Ancak yol ifadesi surucu icerdigi halde ilk ters bolu () yu icermiyor ise (oldugu gibi) bizim gecerli dizinimiz, aktif surucunmuz ne olursa olsun belirtilen surucudeki default dizinden hareket edilerek yol cozulur.</li></ul><pre>/*-----------------------------------------------------------------<br>    Prosesin çalışma dizininin elde edilmesi<br>------------------------------------------------------------------*/</pre><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;tchar.h&gt;<br>#include &lt;Windows.h&gt;<br>#include &lt;Psapi.h&gt;</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status);</pre><pre>int main(void)<br>{<br>    char cwd[1024];</pre><pre>    if (GetCurrentDirectory(1024, cwd) == 0)<br>        ExitSys(&quot;GetCurrentDirectory&quot;, EXIT_FAILURE);</pre><pre>    printf(&quot;%s\n&quot;, cwd);<br>    <br>    return 0;<br>}</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status)<br>{<br>    DWORD dwLastError = GetLastError();<br>    LPTSTR lpszErr;<br>    <br>    if (FormatMessage(  FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, <br>                        NULL, <br>                        dwLastError,<br>                        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), <br>                        (LPTSTR) &amp;lpszErr, <br>                        0, <br>                        NULL)) <br>    {<br>        fprintf(stderr, &quot;%s: %s&quot;, lpszMsg, lpszErr);<br>        LocalFree(lpszErr);<br>    }<br>    <br>    exit(status);<br>}</pre><h3>Bir komut yorumlayicisinin catisi</h3><pre>/*-----------------------------------------------------<br>    Bir komut yorumlayıcının çatısı<br>-------------------------------------------------------*/</pre><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;string.h&gt;<br>#include &lt;tchar.h&gt;<br>#include &lt;Windows.h&gt;<br>#include &lt;Psapi.h&gt;</pre><pre>/* Symbolic Constants */</pre><pre>#define MAX_CMD_LINE                1024<br>#define MAX_CMD_PARAMS                32</pre><pre>/* Type Declarations */</pre><pre>typedef struct tagCMD {<br>    const char *name;<br>    void (*Proc)(void);<br>} CMD;</pre><pre>/* Function Prototypes */</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status);<br>void PrintSysErr(void);<br>void Parse(void);<br>void DirProc(void);<br>void ClsProc(void);<br>void ChDirProc(void);<br>void ExitProc(void);</pre><pre>/* Global Data Definitions */</pre><pre>char g_cmd[MAX_CMD_LINE];<br>char *g_params[MAX_CMD_PARAMS];<br>int g_nparams;<br>CMD g_cmds[] = {<br>    {&quot;dir&quot;, DirProc},<br>    {&quot;cls&quot;, ClsProc},<br>    {&quot;cd&quot;, ChDirProc},<br>    {&quot;exit&quot;, ExitProc},<br>    {NULL, NULL},<br>};</pre><pre>/* Function Definitions */</pre><pre>int main(void)<br>{<br>    char cwd[1024];<br>    int i;</pre><pre>    for (;;) {<br>        if (GetCurrentDirectory(1024, cwd) == 0)<br>            ExitSys(&quot;GetCurrentDirectory&quot;, EXIT_FAILURE);<br>        printf(&quot;%s&gt;&quot;, cwd);<br>        gets(g_cmd);<br>        Parse();<br>        if (g_nparams == 0)<br>            continue;<br>        for (i = 0; g_cmds[i].name != NULL; ++i)<br>            if (!strcmp(g_cmds[i].name, g_params[0])) {<br>                g_cmds[i].Proc();<br>                break;<br>            }<br>        if (g_cmds[i].name == NULL)<br>            printf(&quot;&#39;%s&#39; is not recognized as an internal or external command, \n<br>                        operable program or batch file.\n\n&quot;, g_params[0]);<br>        if (!strcmp(g_cmd, &quot;quit&quot;))<br>            break;<br>    }<br>        <br>    return 0;<br>}</pre><pre>void Parse(void)<br>{<br>    char *param;</pre><pre>    g_nparams = 0;<br>    for (param = strtok(g_cmd, &quot; \t&quot;); param != NULL; param = strtok(NULL, &quot; \t&quot;))<br>        g_params[g_nparams++] = param;<br>}</pre><pre>void DirProc(void)<br>{<br>    printf(&quot;dir\n&quot;);<br>}</pre><pre>void ClsProc(void)<br>{<br>    if (g_nparams &gt; 1) {<br>        printf(&quot;too many arguments...\n\n&quot;);<br>        return;<br>    }<br>    system(&quot;cls&quot;);<br>}</pre><pre>void ChDirProc(void)<br>{<br>    char cwd[1024];</pre><pre>    if (g_nparams == 1) {<br>        if (GetCurrentDirectory(1024, cwd) == 0)<br>            ExitSys(&quot;GetCurrentDirectory&quot;, EXIT_FAILURE);<br>        printf(&quot;%s\n\n&quot;, cwd);<br>        return;<br>    }</pre><pre>    if (g_nparams &gt; 2) {<br>        printf(&quot;too many arguments...\n\n&quot;);<br>        return;<br>    }</pre><pre>    if (!SetCurrentDirectory(g_params[1]))<br>        PrintSysErr();<br>}</pre><pre>void ExitProc(void)<br>{<br>    exit(EXIT_SUCCESS);<br>}</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status)<br>{<br>    DWORD dwLastError = GetLastError();<br>    LPTSTR lpszErr;<br>    <br>    if (FormatMessage(  FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, <br>                        NULL, <br>                        dwLastError,<br>                        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), <br>                        (LPTSTR) &amp;lpszErr, <br>                        0, <br>                        NULL)) <br>    {<br>        fprintf(stderr, &quot;%s: %s&quot;, lpszMsg, lpszErr);<br>        LocalFree(lpszErr);<br>    }<br>    <br>    exit(status);<br>}</pre><pre>void PrintSysErr(void)<br>{<br>    DWORD dwLastError = GetLastError();<br>    LPTSTR lpszErr;<br>    <br>    if (FormatMessage(  FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, <br>                        NULL, <br>                        dwLastError,<br>                        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), <br>                        (LPTSTR) &amp;lpszErr, <br>                        0, <br>                        NULL)) <br>    {<br>        fprintf(stderr, &quot;%s\n&quot;, lpszErr);<br>        LocalFree(lpszErr);<br>    }<br>}</pre><h3>Processlerin Cevre Degiskenleri</h3><ul><li>Cevre degiskenleri (Environment variables) anahtar deger ciftlerini tutan bir cesit sozluk tarzi veri yapisidir.</li><li>Biz anahtari verdigimizde bize deger geri verilir.</li><li>Processin bir degisken listesi vardir.</li><li>Cevre degiskenleri cekirdek tarafindan genellikle process kontrol blogunda yada processin bellek alaninda tutulur. Yani process e ozgudur.</li><li>Processin cevre degiskenleri windows da process yaratilirken createProcess api fnksiyonu ile belirlenir. Eger ilgili parametre NULL ecilirse alt processin cevre degisken takimi ust process ile ayni olur.</li><li>UNIX / Linux sistemlerinde cevre degiskenleri fork islemi sirasinda ust processten tamamen kopyalanir. Fakat exec yaparken tipki windowsda oldugu gibi istege bagli olarak degistirilebilmektedir.</li><li>Windows da bir cevre degiskeni degerini almak icin GetEnvironmentVarible Api fonksiyonu kullanilir.</li><li>Windows sistemlwerde komut satirinda cevre degiskeni verip anahtar elde etmek icin %%, linux sistemlerde de $ kalibi kullanilir.</li><li>Windows sistemlerde komut satirindda komt satiri cevre degikenine ekleme yapmak icin set c=y komutu kullanilir. UNIX/Linux sistemlrede export x = y komutu kullanilir.</li><li>Windows sistemlerde yeni cevre degiskeni eklemek icin setEnvironmentVeriable fonksiyonu kullanilir.</li><li>Processin tum cevre degiskenlerinin elde edilmesi gerekebilir bu islem GetEnvironmentStrings api fonksiyonu ile yapilmaktadir.</li><li><a href="http://www.csystem.org/makaleler/proseslerin-%C3%A7evre-de%C4%9Fi%C5%9Fkenleri">http://www.csystem.org/makaleler/proseslerin-%C3%A7evre-de%C4%9Fi%C5%9Fkenleri</a> makalesi incelenmeli.</li></ul><p><strong>NOT:</strong> Bir sistem fonksiyonu cagirildigi zamanan stack uzerinde normal calismasi gerektigi gibi calisir ancak bir kernel fonksiyonu cagirilsa kernel fonksiyonu kullanilan stack yapisina guvenmedigi icin kendisi stack uzerindeki alani kernel icin guvenli bir alana kopyalar. Isi bittikte sonra geri stake donus yapar. NOT: Unix/Linux sistemlerinde bir cevre degiskenini elde etmek icin get env standart c fonksiyonu kullanilir. Process e yeni bir cevre degiskeni eklemek icin setenv fonksiyotnu kullanilir. Procesin tum cevre degislenini elde etmek icin environ global pointer i kullanilir.</p><ul><li>Bir cevre degiskenini kaliciligini saglamak icin Unix ve Linx da shell processinin calistirdigi betiklerin icersinde set islemleri yapilabilir. Windows da benzer bicimde ayni islem denetim masasindan yapilmaktadir.</li><li>Cevre degiskenrleri neden kullanilmaktadir?</li><li>BaZEN PROGRAMLARDAKI cesitli ayarlarin hicbirsey yapilmadan kujllaicilar tarafindan degistirilmesi istenebilir. Ornegin bir data dosyasinin yerini programci bir cevre degiskeninden alabilir. Kullanici da o cevre degiskenini degistirerek data dosyasini istedigi yere yerlestirebilir.</li><li>Bazi sistem fonksiyonlarida bazi sistem degiskenlerine bakmaktadir.</li><li>Ornegin createProcess birinci parametresi null gecilirse ve ikinci parametresindeki dosya isminde hicbir ters bolu karakteri kullannilmamissa. ilgili exe dosyayi sirasiyla belirli yerlerde arar en sonunda PATH cevre degiskeni ile belirtilen dizinlerde tek tek arar.</li><li>Windows isletim sistemlerinde cevre degiskenlerinin buyuk/kucuk harf duyarliligi yoktur. fakat unix ve linux sistemlerinde vardir.</li></ul><pre>/*-----------------------------------------------------------------<br>      Prosesin çevre değişkenleri<br>      (GetEnvPros ve SetEnvProc fonksiyonlarının yazımlarına bakınız)<br>----------------------------------------------------------------*/</pre><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;string.h&gt;<br>#include &lt;tchar.h&gt;<br>#include &lt;Windows.h&gt;<br>#include &lt;Psapi.h&gt;</pre><pre>/* Symbolic Constants */</pre><pre>#define MAX_CMD_LINE                1024<br>#define MAX_CMD_PARAMS                32</pre><pre>/* Type Declarations */</pre><pre>typedef struct tagCMD {<br>    const char *name;<br>    void (*Proc)(void);<br>} CMD;</pre><pre>/* Function Prototypes */</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status);<br>void PrintSysErr(void);<br>void Parse(void);<br>void DirProc(void);<br>void ClsProc(void);<br>void ChDirProc(void);<br>void GetEnvProc(void);<br>void SetEnvProc(void);<br>void ExitProc(void);</pre><pre>/* Global Data Definitions */</pre><pre>char g_cmd[MAX_CMD_LINE];<br>char *g_params[MAX_CMD_PARAMS];<br>int g_nparams;<br>CMD g_cmds[] = {<br>    {&quot;dir&quot;, DirProc},<br>    {&quot;cls&quot;, ClsProc},<br>    {&quot;cd&quot;, ChDirProc},<br>    {&quot;getenv&quot;, GetEnvProc},<br>    {&quot;setenv&quot;, SetEnvProc},<br>    {&quot;exit&quot;, ExitProc},<br>    <br>    {NULL, NULL},<br>};</pre><pre>/* Function Definitions */</pre><pre>int main(void)<br>{<br>    char cwd[1024];<br>    int i;</pre><pre>    for (;;) {<br>        if (GetCurrentDirectory(1024, cwd) == 0)<br>            ExitSys(&quot;GetCurrentDirectory&quot;, EXIT_FAILURE);<br>        printf(&quot;%s&gt;&quot;, cwd);<br>        gets(g_cmd);<br>        Parse();<br>        if (g_nparams == 0)<br>            continue;<br>        for (i = 0; g_cmds[i].name != NULL; ++i)<br>            if (!strcmp(g_cmds[i].name, g_params[0])) {<br>                g_cmds[i].Proc();<br>                break;<br>            }<br>        if (g_cmds[i].name == NULL)<br>            printf(&quot;&#39;%s&#39; is not recognized as an internal or external command, <br>                    operable program or batch file.\n\n&quot;, g_params[0]);</pre><pre>        if (!strcmp(g_cmd, &quot;quit&quot;))<br>            break;<br>    }<br>        <br>    return 0;<br>}</pre><pre>void Parse(void)<br>{<br>    char *param;</pre><pre>    g_nparams = 0;<br>    for (param = strtok(g_cmd, &quot; \t&quot;); param != NULL; param = strtok(NULL, &quot; \t&quot;))<br>        g_params[g_nparams++] = param;<br>}</pre><pre>void DirProc(void)<br>{<br>    printf(&quot;dir\n&quot;);<br>}</pre><pre>void ClsProc(void)<br>{<br>    if (g_nparams &gt; 1) {<br>        printf(&quot;too many arguments...\n\n&quot;);<br>        return;<br>    }<br>    system(&quot;cls&quot;);<br>}</pre><pre>void ChDirProc(void)<br>{<br>    char cwd[1024];</pre><pre>    if (g_nparams == 1) {<br>        if (GetCurrentDirectory(1024, cwd) == 0)<br>            ExitSys(&quot;GetCurrentDirectory&quot;, EXIT_FAILURE);<br>        printf(&quot;%s\n\n&quot;, cwd);<br>        return;<br>    }</pre><pre>    if (g_nparams &gt; 2) {<br>        printf(&quot;too many arguments...\n\n&quot;);<br>        return;<br>    }</pre><pre>    if (!SetCurrentDirectory(g_params[1]))<br>        PrintSysErr();<br>}</pre><pre>void GetEnvProc(void)<br>{<br>    char buf[1024];<br>    char *envs;</pre><pre>    if (g_nparams == 1) {<br>        if ((envs = GetEnvironmentStrings()) == NULL)<br>            ExitSys(&quot;GetEnvironmentStrings&quot;, EXIT_FAILURE);</pre><pre>        while (*envs != &#39;\0&#39;) {<br>            puts(envs);<br>            envs += strlen(envs) + 1;<br>        }<br>        printf(&quot;\n&quot;);<br>        return;<br>    }</pre><pre>    if (g_nparams &gt; 2) {<br>        printf(&quot;too many arguments..\n\n&quot;);<br>        return;<br>    }</pre><pre>    if (!GetEnvironmentVariable(g_params[1], buf, 1024)) {<br>        PrintSysErr();<br>        return;<br>    }</pre><pre>    printf(&quot;%s\n\n&quot;, buf);<br>}</pre><pre>void SetEnvProc(void)<br>{<br>    if (g_nparams == 1) {<br>        printf(&quot;argument missing...\n\n&quot;);<br>        return;<br>    }</pre><pre>    if (g_nparams &gt; 3) {<br>        printf(&quot;too many arguments..\n\n&quot;);<br>        return;<br>    }</pre><pre>    if (!SetEnvironmentVariable(g_params[1], g_nparams == 3 ? g_params[2] : NULL)) {<br>        PrintSysErr();<br>        return;<br>    }<br>}</pre><pre>void ExitProc(void)<br>{<br>    exit(EXIT_SUCCESS);<br>}</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status)<br>{<br>    DWORD dwLastError = GetLastError();<br>    LPTSTR lpszErr;<br>    <br>    if (FormatMessage(  FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, <br>                        NULL, <br>                        dwLastError,<br>                        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), <br>                        (LPTSTR) &amp;lpszErr, <br>                        0, <br>                        NULL)) <br>    {<br>        fprintf(stderr, &quot;%s: %s&quot;, lpszMsg, lpszErr);<br>        LocalFree(lpszErr);<br>    }<br>    <br>    exit(status);<br>}</pre><pre>void PrintSysErr(void)<br>{<br>    DWORD dwLastError = GetLastError();<br>    LPTSTR lpszErr;<br>    <br>    if (FormatMessage(  FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, <br>                        NULL, <br>                        dwLastError,<br>                        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), <br>                        (LPTSTR) &amp;lpszErr, <br>                        0, <br>                        NULL)) <br>    {<br>        fprintf(stderr, &quot;%s\n&quot;, lpszErr);<br>        LocalFree(lpszErr);<br>    }<br>}<br>/*---------------------------------------------------------------<br>    UNIX/Linux sistemlerine prosesin tüm çevre<br>    değişkenlerinin yazdırılması<br>---------------------------------------------------------------*/</pre><pre>#include &lt;stdio.h&gt;</pre><pre>extern char **environ;</pre><pre>int main(void)<br>{<br>    int i;<br>    <br>    for (i = 0; environ[i] != NULL; ++i)<br>        puts(environ[i]);<br>    <br>    return 0;<br>}</pre><pre>/*----------------------------------------------------------------<br>    CreateProcess PATH çevre değişkenlerine bakmaktadır</pre><pre>    (RunProcess)<br>------------------------------------------------------------------*/</pre><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;string.h&gt;<br>#include &lt;tchar.h&gt;<br>#include &lt;Windows.h&gt;<br>#include &lt;Psapi.h&gt;</pre><pre>/* Symbolic Constants */</pre><pre>#define MAX_CMD_LINE                1024<br>#define MAX_CMD_PARAMS                32</pre><pre>/* Type Declarations */</pre><pre>typedef struct tagCMD {<br>    const char *name;<br>    void (*Proc)(void);<br>} CMD;</pre><pre>/* Function Prototypes */</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status);<br>void PrintSysErr(void);<br>void Parse(void);<br>void DirProc(void);<br>void ClsProc(void);<br>void ChDirProc(void);<br>void GetEnvProc(void);<br>void SetEnvProc(void);<br>void RunProcess(void);<br>void ExitProc(void);</pre><pre>/* Global Data Definitions */</pre><pre>char g_cmd[MAX_CMD_LINE];<br>char *g_params[MAX_CMD_PARAMS];<br>int g_nparams;<br>CMD g_cmds[] = {<br>    {&quot;dir&quot;, DirProc},<br>    {&quot;cls&quot;, ClsProc},<br>    {&quot;cd&quot;, ChDirProc},<br>    {&quot;getenv&quot;, GetEnvProc},<br>    {&quot;setenv&quot;, SetEnvProc},<br>    {&quot;exit&quot;, ExitProc},<br>    <br>    {NULL, NULL},<br>};</pre><pre>/* Function Definitions */</pre><pre>int main(void)<br>{<br>    char cwd[1024];<br>    int i;</pre><pre>    for (;;) {<br>        if (GetCurrentDirectory(1024, cwd) == 0)<br>            ExitSys(&quot;GetCurrentDirectory&quot;, EXIT_FAILURE);<br>        printf(&quot;%s&gt;&quot;, cwd);<br>        gets(g_cmd);<br>        Parse();<br>        if (g_nparams == 0)<br>            continue;<br>        for (i = 0; g_cmds[i].name != NULL; ++i)<br>            if (!strcmp(g_cmds[i].name, g_params[0])) {<br>                g_cmds[i].Proc();<br>                break;<br>            }<br>        if (g_cmds[i].name == NULL) {<br>            RunProcess();<br>            //printf(&quot;&#39;%s&#39; is not recognized as an internal or external command, operable program or batch file.\n\n&quot;, g_params[0]);<br>        }</pre><pre>        if (!strcmp(g_cmd, &quot;quit&quot;))<br>            break;<br>    }<br>        <br>    return 0;<br>}</pre><pre>void Parse(void)<br>{<br>    char *param;</pre><pre>    g_nparams = 0;<br>    for (param = strtok(g_cmd, &quot; \t&quot;); param != NULL; param = strtok(NULL, &quot; \t&quot;))<br>        g_params[g_nparams++] = param;<br>}</pre><pre>void DirProc(void)<br>{<br>    printf(&quot;dir\n&quot;);<br>}</pre><pre>void ClsProc(void)<br>{<br>    if (g_nparams &gt; 1) {<br>        printf(&quot;too many arguments...\n\n&quot;);<br>        return;<br>    }<br>    system(&quot;cls&quot;);<br>}</pre><pre>void ChDirProc(void)<br>{<br>    char cwd[1024];</pre><pre>    if (g_nparams == 1) {<br>        if (GetCurrentDirectory(1024, cwd) == 0)<br>            ExitSys(&quot;GetCurrentDirectory&quot;, EXIT_FAILURE);<br>        printf(&quot;%s\n\n&quot;, cwd);<br>        return;<br>    }</pre><pre>    if (g_nparams &gt; 2) {<br>        printf(&quot;too many arguments...\n\n&quot;);<br>        return;<br>    }</pre><pre>    if (!SetCurrentDirectory(g_params[1]))<br>        PrintSysErr();<br>}</pre><pre>void GetEnvProc(void)<br>{<br>    char buf[1024];<br>    char *envs;</pre><pre>    if (g_nparams == 1) {<br>        if ((envs = GetEnvironmentStrings()) == NULL)<br>            ExitSys(&quot;GetEnvironmentStrings&quot;, EXIT_FAILURE);</pre><pre>        while (*envs != &#39;\0&#39;) {<br>            puts(envs);<br>            envs += strlen(envs) + 1;<br>        }<br>        printf(&quot;\n&quot;);<br>        return;<br>    }</pre><pre>    if (g_nparams &gt; 2) {<br>        printf(&quot;too many arguments..\n\n&quot;);<br>        return;<br>    }</pre><pre>    if (!GetEnvironmentVariable(g_params[1], buf, 1024)) {<br>        PrintSysErr();<br>        return;<br>    }</pre><pre>    printf(&quot;%s\n\n&quot;, buf);<br>}</pre><pre>void SetEnvProc(void)<br>{<br>    if (g_nparams == 1) {<br>        printf(&quot;argument missing...\n\n&quot;);<br>        return;<br>    }</pre><pre>    if (g_nparams &gt; 3) {<br>        printf(&quot;too many arguments..\n\n&quot;);<br>        return;<br>    }</pre><pre>    if (!SetEnvironmentVariable(g_params[1], g_nparams == 3 ? g_params[2] : NULL)) {<br>        PrintSysErr();<br>        return;<br>    }<br>}</pre><pre>void RunProcess(void)<br>{<br>    STARTUPINFO si = {sizeof(STARTUPINFO)};<br>    PROCESS_INFORMATION pi;</pre><pre>    if (!CreateProcess(NULL, g_params[0], NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &amp;si, &amp;pi)) {<br>        PrintSysErr();<br>        return;<br>    }</pre><pre>    CloseHandle(pi.hProcess);<br>}</pre><pre>void ExitProc(void)<br>{<br>    exit(EXIT_SUCCESS);<br>}</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status)<br>{<br>    DWORD dwLastError = GetLastError();<br>    LPTSTR lpszErr;<br>    <br>    if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwLastError,<br>                    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &amp;lpszErr, 0, NULL)) {<br>        fprintf(stderr, &quot;%s: %s&quot;, lpszMsg, lpszErr);<br>        LocalFree(lpszErr);<br>    }<br>    <br>    exit(status);<br>}</pre><pre>void PrintSysErr(void)<br>{<br>    DWORD dwLastError = GetLastError();<br>    LPTSTR lpszErr;<br>    <br>    if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwLastError,<br>                    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &amp;lpszErr, 0, NULL)) {<br>        fprintf(stderr, &quot;%s\n&quot;, lpszErr);<br>        LocalFree(lpszErr);<br>    }<br>}</pre><h3>Proseslerin komut satiri argumanlari (Command line arguments of a process)</h3><ul><li>Programlari komut satirindan calistirirken program isminin yanina yazilan yazilara komut satiri argumanlari denir. Windows sistemlerinde komut satiri argumanlari createProcess fonksiyonunda parametre olarak girilmektedir.</li><li>windows da komut satiri argumanlari createProcess in ikinci parametresi olarak girilir. ve tek bir yazi seklindedir.</li><li>Processin komut satiri argumanlari GetCommandLine api fonksiyonu ile elde dilebilir.</li><li>Derleyilerin baslangic kodlari bu api yi kullanarak komut satirini elde eder. Sonra onu boskuk karakterlerinden parse ederek ayirir ve main fonksiyonuna gecirir.</li><li>UNIX / Linux sistemlerin komut satiri argumanlari tek tek exec fonksiyonlarinda verilmektedir.</li><li>komut satiri argumanlari process kontrol blogunda saklanmaktadir.</li></ul><h3>GNU Stili komut satiri argumanlari</h3><p>Klasik GNU sisteminde komut satiri argumanalari 3 bicimde olabilir.</p><p>1.seceneksiz arguman 2.yalnizca secenek 3.secenekli arguman</p><ul><li>secenek bir tire ve tek bir karakterden olusur. (orn, ls -l -a)</li><li>secenekler birlestirilebilir. (orn. ls -la)</li><li>Eger secenek birden fazla karakterden olusuyor ise secenek karakteri (–) ile belirtilir.(ornegin –login gibi )</li></ul><p>Unix/ Lionux sistemlerinde komut satiri argumanlarini parse etmek icin getopt ve getopt_long isimli fonksiyonlar vardir. <a href="http://www.csystem.org/makaleler/programlar%C4%B1n-komut-sat%C4%B1r%C4%B1-arg%C3%BCmanlar%C4%B1">http://www.csystem.org/makaleler/programlar%C4%B1n-komut-sat%C4%B1r%C4%B1-arg%C3%BCmanlar%C4%B1</a> makalesini oku.</p><pre>/*----------------------------------------------------------<br>    Proseslerin komut satırı argümanları <br>    (Parse işlemi düzeltilmiş versiyon)<br>------------------------------------------------------------*/</pre><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;ctype.h&gt;<br>#include &lt;string.h&gt;<br>#include &lt;tchar.h&gt;<br>#include &lt;Windows.h&gt;<br>#include &lt;Psapi.h&gt;</pre><pre>/* Symbolic Constants */</pre><pre>#define MAX_CMD_LINE                1024<br>#define MAX_CMD_PARAMS                32</pre><pre>/* Type Declarations */</pre><pre>typedef struct tagCMD {<br>    const char *name;<br>    void (*Proc)(void);<br>} CMD;</pre><pre>/* Function Prototypes */</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status);<br>void PrintSysErr(void);<br>void Parse(void);<br>void DirProc(void);<br>void ClsProc(void);<br>void ChDirProc(void);<br>void GetEnvProc(void);<br>void SetEnvProc(void);<br>void RunProcess(void);<br>void TrimCmd(char *trimmed);<br>void ExitProc(void);</pre><pre>/* Global Data Definitions */</pre><pre>char g_cmd[MAX_CMD_LINE];<br>char *g_params[MAX_CMD_PARAMS];<br>int g_nparams;<br>CMD g_cmds[] = {<br>    {&quot;dir&quot;, DirProc},<br>    {&quot;cls&quot;, ClsProc},<br>    {&quot;cd&quot;, ChDirProc},<br>    {&quot;getenv&quot;, GetEnvProc},<br>    {&quot;setenv&quot;, SetEnvProc},<br>    {&quot;exit&quot;, ExitProc},<br>    {NULL, NULL},<br>};</pre><pre>/* Function Definitions */</pre><pre>int main(void)<br>{<br>    char cwd[1024];<br>    int i;</pre><pre>    for (;;) {<br>        if (GetCurrentDirectory(1024, cwd) == 0)<br>            ExitSys(&quot;GetCurrentDirectory&quot;, EXIT_FAILURE);<br>        printf(&quot;%s&gt;&quot;, cwd);<br>        gets(g_cmd);<br>        Parse();<br>        if (g_nparams == 0)<br>            continue;<br>        for (i = 0; g_cmds[i].name != NULL; ++i)<br>            if (!strcmp(g_cmds[i].name, g_params[0])) {<br>                g_cmds[i].Proc();<br>                break;<br>            }<br>        if (g_cmds[i].name == NULL)<br>            RunProcess();</pre><pre>        if (!strcmp(g_cmd, &quot;quit&quot;))<br>            break;<br>    }<br>        <br>    return 0;<br>}</pre><pre>void Parse(void)<br>{<br>    char *str, *beg;<br>    str = g_cmd;<br>    <br>    for (g_nparams = 0;; ++g_nparams) {<br>        while (isspace(*str))<br>            ++str;<br>        if (*str == &#39;\0&#39;)<br>            break;<br>        beg = str;<br>        while (!isspace(*str) &amp;&amp; *str != &#39;\0&#39;) {<br>            if (*str == &#39;\&quot;&#39;) {<br>                ++str;<br>                while (*str != &#39;\&quot;&#39; &amp;&amp; *str != &#39;\0&#39;)<br>                    ++str;<br>                if (*str == &#39;\&quot;&#39;)<br>                    ++beg;<br>                if (*str == &#39;\0&#39;)<br>                    break;<br>                *str = &#39;\0&#39;;<br>            }<br>            ++str;<br>        }<br>        g_params[g_nparams] = beg;<br>        if (*str == &#39;\0&#39;)<br>            break;<br>        *str++ = &#39;\0&#39;;<br>    }</pre><pre>    ++g_nparams;<br>}</pre><pre>void DirProc(void)<br>{<br>    printf(&quot;dir\n&quot;);<br>}</pre><pre>void ClsProc(void)<br>{<br>    if (g_nparams &gt; 1) {<br>        printf(&quot;too many arguments...\n\n&quot;);<br>        return;<br>    }<br>    system(&quot;cls&quot;);<br>}</pre><pre>void ChDirProc(void)<br>{<br>    char cwd[1024];</pre><pre>    if (g_nparams == 1) {<br>        if (GetCurrentDirectory(1024, cwd) == 0)<br>            ExitSys(&quot;GetCurrentDirectory&quot;, EXIT_FAILURE);<br>        printf(&quot;%s\n\n&quot;, cwd);<br>        return;<br>    }</pre><pre>    if (g_nparams &gt; 2) {<br>        printf(&quot;too many arguments...\n\n&quot;);<br>        return;<br>    }</pre><pre>    if (!SetCurrentDirectory(g_params[1]))<br>        PrintSysErr();<br>}</pre><pre>void GetEnvProc(void)<br>{<br>    char buf[1024];<br>    char *envs;</pre><pre>    if (g_nparams == 1) {<br>        if ((envs = GetEnvironmentStrings()) == NULL)<br>            ExitSys(&quot;GetEnvironmentStrings&quot;, EXIT_FAILURE);</pre><pre>        while (*envs != &#39;\0&#39;) {<br>            puts(envs);<br>            envs += strlen(envs) + 1;<br>        }<br>        printf(&quot;\n&quot;);<br>        return;<br>    }</pre><pre>    if (g_nparams &gt; 2) {<br>        printf(&quot;too many arguments..\n\n&quot;);<br>        return;<br>    }</pre><pre>    if (!GetEnvironmentVariable(g_params[1], buf, 1024)) {<br>        PrintSysErr();<br>        return;<br>    }</pre><pre>    printf(&quot;%s\n\n&quot;, buf);<br>}</pre><pre>void SetEnvProc(void)<br>{<br>    if (g_nparams == 1) {<br>        printf(&quot;argument missing...\n\n&quot;);<br>        return;<br>    }</pre><pre>    if (g_nparams &gt; 3) {<br>        printf(&quot;too many arguments..\n\n&quot;);<br>        return;<br>    }</pre><pre>    if (!SetEnvironmentVariable(g_params[1], g_nparams == 3 ? g_params[2] : NULL)) {<br>        PrintSysErr();<br>        return;<br>    }<br>}</pre><pre>void RunProcess(void)<br>{<br>    STARTUPINFO si = {sizeof(STARTUPINFO)};<br>    PROCESS_INFORMATION pi;<br>    char cmdLine[MAX_CMD_LINE];</pre><pre>    TrimCmd(cmdLine);<br>    printf(&quot;:%s:\n&quot;, cmdLine);<br>    if (!CreateProcess(NULL, cmdLine, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &amp;si, &amp;pi)) {<br>        PrintSysErr();<br>        return;<br>    }</pre><pre>    CloseHandle(pi.hProcess);<br>    printf(&quot;\n&quot;);<br>}</pre><pre>void ExitProc(void)<br>{<br>    exit(EXIT_SUCCESS);<br>}</pre><pre>void TrimCmd(char *trimmed)<br>{<br>    char *str1 = g_cmd;<br>    char *str2 = g_cmd + strlen(g_cmd) - 1;</pre><pre>    while (isspace(*str1))<br>        ++str1;<br>    if (*str1 == &#39;\0&#39;) {<br>        *trimmed = &#39;\0&#39;;<br>        return;<br>    }<br>    <br>    while (isspace(*str2))<br>        --str2;</pre><pre>    do {<br>        *trimmed++ = *str1++;<br>    } while (str1 &lt;= str2);<br>    *trimmed = &#39;\0&#39;;<br>}</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status)<br>{<br>    DWORD dwLastError = GetLastError();<br>    LPTSTR lpszErr;<br>    <br>    if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwLastError,<br>                    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &amp;lpszErr, 0, NULL)) {<br>        fprintf(stderr, &quot;%s: %s&quot;, lpszMsg, lpszErr);<br>        LocalFree(lpszErr);<br>    }<br>    <br>    exit(status);<br>}</pre><pre>void PrintSysErr(void)<br>{<br>    DWORD dwLastError = GetLastError();<br>    LPTSTR lpszErr;<br>    <br>    if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwLastError,<br>                    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &amp;lpszErr, 0, NULL)) {<br>        fprintf(stderr, &quot;%s\n&quot;, lpszErr);<br>        LocalFree(lpszErr);<br>    }<br>}</pre><h3>UNIX /Linux Sistemlerinin Tarihsel Gelisimi</h3><p>Ken Thomson ile roportaj</p><ul><li>Unix isletim sistemi 1969 1970 yillarindan AT&amp;T bell labs da Ken thomson, Brian Kernigan ve Dennis Ricchi tarafondan dec makinalari icin yazilmistir.</li><li>Deniss R. bu gruptan bagimsiz olarak unix yaziminda kullanilan Ken Thaomson’in B programlama dilinden hareketle C yi gelistirmistir.</li><li>Unix 1973 yilinda yeniden C ile yazildi. Bundan sonra Unix in kaynak kodlari pekcok universite ve arastirma kurumlarina dagitildi. Onlar da C ogrenerek UNIX varyantlari olusturmaya basladilar.</li><li>1970 li yillarin ortalarinda berkeley deki kaliforniya universitesi Orjinal UNIX kodlarini degistirerek BSD sistemlerini cikartti.</li><li>Soket sistemi, sanal bellek, tcpip hep ilk olarak bsd de deneniyor.</li><li>zamanla pekcok unix turevi sistem olusturuldu.</li><li>80 li yillarin ortalarinda R Stallman ponerisi ile farkli unix turevi sistemler POSIX ismi ile standardize edilmistir.</li><li>POSIX standartlari birkac bolumden olusmaktadir. Bolumlerden biri Shell komutlarini aciklari.</li></ul><p>Digeri C den kullanabilecegimiz api fonksiyonunu aciklar.</p><ul><li>Bugun LINUX, BSD, SOLARIS gibi sistemlerin hepsi POSIX uyumludur.</li><li>PCBSD bsd surumu olarak kullanilabilir.</li><li>WMS ve openWMS</li><li>opengroup dernegi</li><li>80 li yillarin basindan Sichard S FSF isminde bir xx kurdu. ve Free software akimini kurdu.</li><li>FSF ayni zamanda GNU projesini baslatti, Bu projenin amaci acik bir isletim sistemi ve gelistirme araclarini yazmakti.</li><li>Ozgur yazilimi temsil eden lisansn GPL lisansidir. Bu lisansa copyright yerine copyleft denilmektedir.</li><li>90 li yillarin basinda Linus torvalds linux u gelistirmeye basladi.</li><li>Linux sistemleri bugn icin acik kaynak kodlu posix uyumlu unix turevi sistemlerdir.</li></ul><h3>Standart C Fonksiyonlari, POSIX Fonksiyonlari ve SIstem Fonksiyonlari</h3><ul><li>Standar C fonksiyonlari C derleyicisinin bulundugu her yerde olan fonksiyonlardir. Microcontroller olsa bile bu fonksiyonlar bulunmaktadirlar</li><li>POSIX Fonksiyonlari POSIX Standartlarina uyan UNIX turevi sistemlerde var olan fonksiyonlardir.</li><li>Sistem fonksiyonlari ise i isletim sistemine ozgu fonksiyonlardir.</li><li>Windows dunyasinda standard C fonksiyonlari ve windows api fonksiyonlari vardir.</li><li>LINUX</li><li>fopen → open → sys_open</li><li>cdeki fopen fonksiyonu POSIX fonksiyonu olan open fonksiyonunu cagirir. Bu da sistem fonksiyonu olan sys_open fonksiyonunu cagirir.</li><li>Windows</li><li>fopen → CreateFile Windows daki c fonksiyonu olan fopen cagirildigi zaman, API fonsiyonu olan createFile fonksiyonu cagirilir,</li></ul><h3>Windows Dosya Sistemi</h3><ul><li>DIsk organizasyon tarafi</li><li>Bellek organizasyon tarafi bulunmaktafir.</li><li>Bir isletim sisteminin dosya sisteminin iki yonu vardir. Disk tarafi ve bellek tarafi.</li><li>Sistemin disk tarafi, Yapilan disk organizasyonuna iliskindir. Yani sektorlerin dosyalari tutacak bicimde nasil organize olacagi ile ilgilidir.</li><li>Bellek tarafi denilince diskteki bu dosyalarin idare edilmedi icin olusturulan veri yapilari akla gelmetedir.</li><li>isletim sisteminin dosya sistemi diskteki sektorleri bize bagimsiz dosyalarmis gibi gosterir.</li><li>Biz de dosya islemlerini api fonksiyonleri ile yapariz.</li><li>BIrcok sistemdi device driver ler dosya olarak tanimlanir ve sistem bu dosyalara okuma yazma yaparak bu driverlari kullanirlar.</li><li>Windows sistemlerinde temel dosya apileri sunlardir.</li><li>CreateFile : help dosyası ıcerısınde ıncele</li><li>ReadFile :</li><li>WriteFile :</li><li>SetFilePointer : Dosya kullnici icin bytelerdan olusan brttopluluk. Bir de file pointer diye bir sayi. O anda hagi dosya ile ilgili islem yapilacgini anlatiyor.http://www.kaanaslan.com/resource/article/display_article.php?id=64 makalesini oku</li><li>CloseHandle :</li></ul><p>CreateFile fonksıyonu basarısız olursa invalid handle value isimliozel bir isme geri doner read file fonksiyonunu kullanirken sunlara dikkat etmek gerekmektedir.</p><ul><li>Dosya gostericisiinin bulundu yerden itibaren kalan byte miktarindan daha fazla miktarda okuma yapmak normak bir durumdur. BU durumda fonksiyon basarisiz olmaz. Okunabilen byte okunur. ve kac byte okundugu bize verilir.</li><li>ReadFile IO hatasi olustugunda yada gecersiz parametre girildiginde basarisiz olur.</li><li>EOF durumunda okuma yapmaya calisirsak 0 byte okuruz ancak fonksiyon basarisiz olmaz. UNIX Linux dunyasinda IO hatasinda -1 ve EOF durumunda 0 dinus yapar. WriteFile Fonksiyonu</li><li>dosyalarin handle degerleri process kontrol blogunda da bulunmaktadir. biz bir disyayi papatmamasak bile process sonlandiginda isletim sistemi butun dosalari bizim icin kapatir. (Terminate process dahil olmak uzere) . Fakat bir dosya ile isimizi bitirmissek onu mumkun oldugunca kapatmak iyi bir tekniktir. Set file pointer — <a href="http://www.kaanaslan.com/resource/article/display">http://www.kaanaslan.com/resource/article/display</a>_article.php?id=64</li></ul><pre>/*--------------------------------------------------------------------------<br>    CreateFile, ReadFile, WriteFile örneği<br>----------------------------------------------------------------------------*/</pre><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;Windows.h&gt;</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status);</pre><pre>int main(void)<br>{<br>    HANDLE hFile;<br>    char buf[1024 + 1];<br>    DWORD dwRead, dwWritten;</pre><pre>    if ((hFile = CreateFile(&quot;test.dat&quot;, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,<br>                        FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE)<br>        ExitSys(&quot;CreateFile&quot;, EXIT_FAILURE);</pre><pre>    if (!ReadFile(hFile, buf, 1024, &amp;dwRead, NULL))<br>        ExitSys(&quot;ReadFile&quot;, EXIT_FAILURE);</pre><pre>    buf[dwRead] = &#39;\0&#39;;<br>    puts(buf);</pre><pre>    strcpy(buf, &quot;xxxxx&quot;);</pre><pre>    if (!WriteFile(hFile, buf, 5, &amp;dwWritten, NULL))<br>        ExitSys(&quot;WriteFile&quot;, EXIT_FAILURE);</pre><pre>    CloseHandle(hFile);</pre><pre>    return 0;<br>}</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status)<br>{<br>    DWORD dwLastError = GetLastError();<br>    LPTSTR lpszErr;<br>    <br>    if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwLastError,<br>                    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &amp;lpszErr, 0, NULL)) {<br>        fprintf(stderr, &quot;%s: %s&quot;, lpszMsg, lpszErr);<br>        LocalFree(lpszErr);<br>    }<br>    <br>    exit(status);<br>}</pre><h3>Yardimci Dosya fonksiyonlari</h3><p>read wite yapmayan ancak dosya sistemi ile ilgili islemler yapam fonksiyonlar</p><ul><li>CopyFile ve CopyFileEx fonksiyonlari dosya kopyalamakta kopyalanir.</li></ul><p>DeleteFile Fonksiyonu dosya silmekte kullnilir.</p><ul><li>GetFileAttribule fonksiyonu ile bir dosyanin ozellik bilgisi elde edilebilir.</li><li>GetFileSize ve GetFileSizeEx fonksiyonu dosya uzunlugunu elde etmekte kullanilir.</li><li>MoveFile ve MoveFileEx dosyayi tasimakta gullanilir.</li><li>CreateDirectory ve CreateDirectoryEx fonksiyonlari yeni bir dizin yaratmak icin kullanilir</li><li>RemoveDirectory Fonksiyonu bos bor klasoru silebilir.</li><li>Ici dolu kladoru tek hamlede silen bir API fonsiyonu yoktur ancak shell fonksiyonu vardir.</li></ul><h3>Dizin Iceriginin elde edilmesi</h3><ul><li>Windows da bir dizin icerigini elde etmek icin 3 API fonksiyonu kullanilir.</li><li>Bunlar FindFirsFile, FindNextFile ve FileClose fonksiyonlaridir.</li><li>fonksiyonlar su sekilde kullanilirlar.</li><li>Once bir kes findfirstfile kullanilir. birden fazla dosyanin elde edilmesi hedeflenmisse bu fonksiyon bize ilk dosyanin bilerini verir.</li><li>Bundan sonra bir dongu icerisinde find next file cagirilarak diger dosyalarin bilgileri elde edilebilir.</li><li>En sonunda da FindClose cagirilarak islem sonlandirilir.</li><li>Bı fonksıyonlarda tum dızın ıcerıgını elde ederız. Her dizinin icerisinde nokta ve cift nokta dizinleri bulunur. Bular dizin yaratilirken olusur ve bunlar istense de silinemezler.</li><li>Dizinler de dosya gibi islem gorurler. Yani biz bu fonksiyonlarla dizinleri de bulabiliriz.</li></ul><pre>/*-----------------------------------------------------------------------------<br>    Dosyanın sonuna ekleme yapmak<br>-------------------------------------------------------------------------------*/</pre><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;Windows.h&gt;</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status);</pre><pre>int main(void)<br>{<br>    HANDLE hFile;<br>    DWORD dwWritten;</pre><pre>    if ((hFile = CreateFile(&quot;test.dat&quot;, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,<br>                        FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE)<br>        ExitSys(&quot;CreateFile&quot;, EXIT_FAILURE);</pre><pre>    SetFilePointer(hFile, 0, 0, FILE_END);</pre><pre>    if (!WriteFile(hFile, &quot;ankara&quot;, 6, &amp;dwWritten, NULL) )<br>        ExitSys(&quot;WriteFile&quot;, EXIT_FAILURE);</pre><pre>    CloseHandle(hFile);</pre><pre>    return 0;<br>}</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status)<br>{<br>    DWORD dwLastError = GetLastError();<br>    LPTSTR lpszErr;<br>    <br>    if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwLastError,<br>                    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &amp;lpszErr, 0, NULL)) {<br>        fprintf(stderr, &quot;%s: %s&quot;, lpszMsg, lpszErr);<br>        LocalFree(lpszErr);<br>    }<br>    <br>    exit(status);<br>}<br>Oz yinelemeli olarak dizin agacini dolasasn bir fonksiyon yazilacak\<br>/*-----------------------------------------------------------------------------------------------------------<br>    Dizin içerğinin elde edilmesi<br>-----------------------------------------------------------------------------------------------------------*/</pre><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;Windows.h&gt;</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status);</pre><pre>int main(void)<br>{<br>    HANDLE hFind;<br>    WIN32_FIND_DATA fd;<br>    char path[MAX_PATH];</pre><pre>    printf(&quot;Path:&quot;);<br>    gets(path);</pre><pre>    hFind = FindFirstFile(path,  &amp;fd);<br>    if (hFind == INVALID_HANDLE_VALUE)<br>        ExitSys(&quot;FindFirstFile&quot;, EXIT_FAILURE);</pre><pre>    do {<br>        printf(&quot;%-30s %lu\n&quot;, fd.cFileName, fd.nFileSizeLow);<br>    } while (FindNextFile(hFind, &amp;fd));</pre><pre>    FindClose(hFind);</pre><pre>    return 0;<br>}</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status)<br>{<br>    DWORD dwLastError = GetLastError();<br>    LPTSTR lpszErr;<br>    <br>    if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwLastError,<br>                    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &amp;lpszErr, 0, NULL)) {<br>        fprintf(stderr, &quot;%s: %s&quot;, lpszMsg, lpszErr);<br>        LocalFree(lpszErr);<br>    }<br>    <br>    exit(status);<br>}<br>/*----------------------------------------------------------------<br>    Dizin ağacının dolaşılması<br>------------------------------------------------------------------*/</pre><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;Windows.h&gt;</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status);<br>void WalkDir(LPCTSTR path);<br>void WalkDirRecur(LPCTSTR path);</pre><pre>int main(void)<br>{<br>    char path[MAX_PATH];</pre><pre>    printf(&quot;Path:&quot;);<br>    gets(path);</pre><pre>    WalkDir(path);<br></pre><pre>    return 0;<br>}</pre><pre>void WalkDir(LPCTSTR path)<br>{<br>    char cwd[1024];</pre><pre>    if (!GetCurrentDirectory(1024, cwd))<br>        ExitSys(&quot;GetCurrentDirectory&quot;, EXIT_FAILURE);</pre><pre>    WalkDirRecur(path);</pre><pre>    if (!SetCurrentDirectory(cwd))<br>        return;<br>}</pre><pre>void WalkDirRecur(LPCTSTR path)<br>{<br>    HANDLE hFind;<br>    WIN32_FIND_DATA fd;</pre><pre>    if (!SetCurrentDirectory(path))<br>        return;<br>    <br>    hFind = FindFirstFile(&quot;*.*&quot;,  &amp;fd);<br>    if (hFind == INVALID_HANDLE_VALUE)<br>        return;</pre><pre>    do {<br>        if (!strcmp(fd.cFileName, &quot;.&quot;) || !strcmp(fd.cFileName, &quot;..&quot;))<br>            continue;<br>        if (fd.dwFileAttributes &amp; FILE_ATTRIBUTE_DIRECTORY) {<br>            WalkDirRecur(fd.cFileName);<br>            if (!SetCurrentDirectory(&quot;..&quot;))<br>                return;<br>        }<br>        else<br>            printf(&quot;%-30s %lu\n&quot;, fd.cFileName, fd.nFileSizeLow);<br>    } while (FindNextFile(hFind, &amp;fd));</pre><pre>    FindClose(hFind);<br>}</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status)<br>{<br>    DWORD dwLastError = GetLastError();<br>    LPTSTR lpszErr;<br>    <br>    if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwLastError,<br>                    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &amp;lpszErr, 0, NULL)) {<br>        fprintf(stderr, &quot;%s: %s&quot;, lpszMsg, lpszErr);<br>        LocalFree(lpszErr);<br>    }<br>    <br>    exit(status);<br>}</pre><pre>/*------------------------------------------------------------<br>    Dizin ağacının ağaç biçiminde yazdırılması<br>-------------------------------------------------------------*/</pre><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;Windows.h&gt;</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status);<br>void WalkDir(LPCTSTR path);<br>void WalkDirRecur(LPCTSTR path);</pre><pre>int main(void)<br>{<br>    char path[MAX_PATH];</pre><pre>    printf(&quot;Path:&quot;);<br>    gets(path);<br>    printf(&quot;\n&quot;);</pre><pre>    WalkDir(path);</pre><pre>    return 0;<br>}</pre><pre>void WalkDir(LPCTSTR path)<br>{<br>    char cwd[1024];</pre><pre>    if (!GetCurrentDirectory(1024, cwd))<br>        ExitSys(&quot;GetCurrentDirectory&quot;, EXIT_FAILURE);<br>    <br>    WalkDirRecur(path, 0);</pre><pre>    if (!SetCurrentDirectory(cwd))<br>        return;<br>}</pre><pre>void WalkDirRecur(LPCTSTR path, int space)<br>{<br>    HANDLE hFind;<br>    WIN32_FIND_DATA fd;<br>    int i;</pre><pre>    if (!SetCurrentDirectory(path))<br>        return;<br>    <br>    hFind = FindFirstFile(&quot;*.*&quot;,  &amp;fd);<br>    if (hFind == INVALID_HANDLE_VALUE)<br>        return;</pre><pre>    do {<br>        if (!strcmp(fd.cFileName, &quot;.&quot;) || !strcmp(fd.cFileName, &quot;..&quot;))<br>            continue;<br>        if (fd.dwFileAttributes &amp; FILE_ATTRIBUTE_DIRECTORY) {<br>            for (i = 0; i &lt; space; ++i)<br>                putchar(&#39; &#39;);<br>            printf(&quot;%s\n&quot;, fd.cFileName);<br>            space += 4;<br>            WalkDirRecur(fd.cFileName, space);<br>            space -= 4;<br>            if (!SetCurrentDirectory(&quot;..&quot;))<br>                return;<br>        }</pre><pre>    } while (FindNextFile(hFind, &amp;fd));</pre><pre>    FindClose(hFind);<br>}</pre><pre>void ExitSys(LPCTSTR lpszMsg, int status)<br>{<br>    DWORD dwLastError = GetLastError();<br>    LPTSTR lpszErr;<br>    <br>    if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwLastError,<br>                    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &amp;lpszErr, 0, NULL)) {<br>        fprintf(stderr, &quot;%s: %s&quot;, lpszMsg, lpszErr);<br>        LocalFree(lpszErr);<br>    }<br>    <br>    exit(status);<br>}</pre><h3>}</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=996f702c162" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>