{"id":23545,"date":"2023-04-20T09:58:35","date_gmt":"2023-04-20T09:58:35","guid":{"rendered":"https:\/\/www.booksofall.com\/de\/?post_type=product&#038;p=23545"},"modified":"2023-04-20T09:58:35","modified_gmt":"2023-04-20T09:58:35","slug":"unix-lecture-notes-chapter-08","status":"publish","type":"product","link":"https:\/\/www.booksofall.com\/de\/unix-lecture-notes-chapter-08\/","title":{"rendered":"UNIX Lecture Notes &#8211; Chapter 08"},"content":{"rendered":"<p>8.1 Introduction<\/p>\n<p>Processes that cooperate in order to complete one or more tasks almost always need to communicate with each other. Sometimes the communication requires sharing data. One method of sharing data is by sharing a common file. If at least one of the processes modifies the \u001cfile, then the fi\u001cle must be accessed in mutual exclusion. Sharing a fi\u001cle is essentially like sharing a<a href=\"https:\/\/www.webopedia.com\/definitions\/memory-resident\/\"> memory-resident<\/a> resource in that both are a form of communication that uses a shared resource that is accessed in mutual exclusion. Another paradigm involves passing data back and forth through some type of communication channel that provides the required mutual exclusion. A pipe is an example of this, as is a socket. This type of communication is broadly known as a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Message_passing\">message-passing<\/a> solution to the problem.<\/p>\n<p>This chapter is concerned only with message-passing types of communication. We will begin with unnamed pipes, after which we will look at named pipes, also known as <a href=\"https:\/\/en.wikipedia.org\/wiki\/FIFO_(computing_and_electronics)\">FIFO<\/a> &#8216;s, and then look at sockets. Part I is exclusively related to pipes.<\/p>\n<p>8.2 Unnamed Pipes<\/p>\n<p>You are familiar with how to use pipes at the command level. A command such as<\/p>\n<p>$ last | grep &#8216;reboot&#8217;<\/p>\n<p>connects the output of last to the input of grep, so that the only lines of output will be those lines of last that contain the word &#8216;reboot&#8217;. The &#8216;|&#8217; is a bash operator; it causes bash to start the last command and the grep command simultaneously, and to direct the standard output of last into the standard input of grep.<\/p>\n<p>Although &#8216;|&#8217; is a bash operator, it uses the lower-level, underlying pipe facility of <a href=\"https:\/\/www.opengroup.org\/membership\/forums\/platform\/unix\">UNIX<\/a>, which was invented by <a href=\"https:\/\/en.wikipedia.org\/wiki\/Douglas_McIlroy\">Douglas Mcilroy<\/a>, and was incorporated into UNIX in 1973. You can visualize the pipe mechanism as a special file or buffer that acts quite literally like a physical pipe, connecting the output of last to the input of grep, as in Figure 8.1.<\/p>\n<p>The last program does not know that it is writing to a pipe and grep does not know that it is reading from a pipe. Moreover, if last tries to write to the pipe faster than grep can drain it, last will block, and if grep tries to read from an empty pipe because it is reading faster than last can write, grep will block, and both of these actions are handled behind the scenes by the kernel.<\/p>\n<p>What then is a pipe? Although a pipe may seem like a fi\u001cle, it is not a fi\u001cle, and there is no \u001cfile pointer associated with it. It is conceptually like a conveyor belt consisting of a \u001cfixed number of logical blocks that can be filled and emptied. Each write to the pipe \u001cfills as many blocks as are needed to satisfy it, provided that it does not exceed the maximum pipe size, and if the pipe size limit was not reached, a new block is made available for the next write. Filled blocks are conveyed to the read-end of the pipe, where they are emptied when they are read. These types of pipes are called unnamed pipes because they do not exist anywhere in the \u001cfile system. They have no names.<\/p>\n<p>An unnamed pipe1 in UNIX is created with the pipe() system call.<\/p>\n<p>#include &lt;unistd.h&gt; int pipe(int filedes[2]);<\/p>\n<p>The system call pipe(fd), given an integer array fd of size 2, creates a pair of fi\u001cle descriptors, fd[0] and fd[1], pointing to the &#8220;read-end&#8221; and &#8220;write-end&#8221; of a pipe inode respectively. If it is successful, it returns a 0, otherwise it returns -1. The process can then write to the write-end, fd[1], using the write() system call, and can read from the read-end, fd[0], using the read() system call. The read and write-ends are opened automatically as a result of the pipe() call. Written data are read in \u001cfirst-in-fi\u001crst-out (FIFO) order. The following program (pipedemo0.c in the demos directory) demonstrates this simple case.<\/p>\n","protected":false},"excerpt":{"rendered":"<p><iframe style=\"width: 100%; height: 750px; border: none;\" src=\"https:\/\/online.visual-paradigm.com\/share\/book\/unix-lecture-notes-chapter-08-1bs0xe3768?p=1\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n","protected":false},"featured_media":23549,"template":"","meta":{"_yoast_wpseo_title":"","_yoast_wpseo_metadesc":"Communication is necessary when working, while the way we share the our message and data is them very important. Learn more with notes here."},"product_brand":[],"product_cat":[376],"product_tag":[],"class_list":{"0":"post-23545","1":"product","2":"type-product","3":"status-publish","4":"has-post-thumbnail","6":"product_cat-unix-lecture-notes","8":"first","9":"instock","10":"shipping-taxable","11":"product-type-simple"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>UNIX Lecture Notes - Chapter 08 - BooksOfAll German<\/title>\n<meta name=\"description\" content=\"Communication is necessary when working, while the way we share the our message and data is them very important. Learn more with notes here.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.booksofall.com\/de\/unix-lecture-notes-chapter-08\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"UNIX Lecture Notes - Chapter 08 - BooksOfAll German\" \/>\n<meta property=\"og:description\" content=\"Communication is necessary when working, while the way we share the our message and data is them very important. Learn more with notes here.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.booksofall.com\/de\/unix-lecture-notes-chapter-08\/\" \/>\n<meta property=\"og:site_name\" content=\"BooksOfAll German\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.booksofall.com\/de\/wp-content\/uploads\/sites\/9\/2023\/04\/UNIX-Lecture-Notes-cover-UNIX-Lecture-Notes-Chapter_08.jpg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.booksofall.com\/de\/wp-content\/uploads\/sites\/9\/2023\/04\/UNIX-Lecture-Notes-cover-UNIX-Lecture-Notes-Chapter_08.jpg\" \/>\n<meta name=\"twitter:label1\" content=\"Gesch\u00e4tzte Lesezeit\" \/>\n\t<meta name=\"twitter:data1\" content=\"3\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.booksofall.com\/de\/unix-lecture-notes-chapter-08\/\",\"url\":\"https:\/\/www.booksofall.com\/de\/unix-lecture-notes-chapter-08\/\",\"name\":\"UNIX Lecture Notes - Chapter 08 - BooksOfAll German\",\"isPartOf\":{\"@id\":\"https:\/\/www.booksofall.com\/de\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.booksofall.com\/de\/unix-lecture-notes-chapter-08\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.booksofall.com\/de\/unix-lecture-notes-chapter-08\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.booksofall.com\/de\/wp-content\/uploads\/sites\/9\/2023\/04\/UNIX-Lecture-Notes-cover-UNIX-Lecture-Notes-Chapter_08.jpg\",\"datePublished\":\"2023-04-20T09:58:35+00:00\",\"description\":\"Communication is necessary when working, while the way we share the our message and data is them very important. Learn more with notes here.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.booksofall.com\/de\/unix-lecture-notes-chapter-08\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.booksofall.com\/de\/unix-lecture-notes-chapter-08\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/www.booksofall.com\/de\/unix-lecture-notes-chapter-08\/#primaryimage\",\"url\":\"https:\/\/www.booksofall.com\/de\/wp-content\/uploads\/sites\/9\/2023\/04\/UNIX-Lecture-Notes-cover-UNIX-Lecture-Notes-Chapter_08.jpg\",\"contentUrl\":\"https:\/\/www.booksofall.com\/de\/wp-content\/uploads\/sites\/9\/2023\/04\/UNIX-Lecture-Notes-cover-UNIX-Lecture-Notes-Chapter_08.jpg\",\"width\":\"827\",\"height\":\"1169\",\"caption\":\"UNIX Lecture Notes - Chapter 08\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.booksofall.com\/de\/unix-lecture-notes-chapter-08\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.booksofall.com\/de\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Categories\",\"item\":\"https:\/\/www.booksofall.com\/de\/categories\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"UNIX Lecture Notes &#8211; Chapter 08\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.booksofall.com\/de\/#website\",\"url\":\"https:\/\/www.booksofall.com\/de\/\",\"name\":\"BooksOfAll German\",\"description\":\"Biggest IT eBooks library and learning resources - Free eBooks for programming, computing, artificial intelligence and more.\",\"publisher\":{\"@id\":\"https:\/\/www.booksofall.com\/de\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.booksofall.com\/de\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"de\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.booksofall.com\/de\/#organization\",\"name\":\"BooksOfAll German\",\"url\":\"https:\/\/www.booksofall.com\/de\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/www.booksofall.com\/de\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.booksofall.com\/de\/wp-content\/uploads\/sites\/9\/2022\/06\/booksofall-logo-2.png\",\"contentUrl\":\"https:\/\/www.booksofall.com\/de\/wp-content\/uploads\/sites\/9\/2022\/06\/booksofall-logo-2.png\",\"width\":166,\"height\":30,\"caption\":\"BooksOfAll German\"},\"image\":{\"@id\":\"https:\/\/www.booksofall.com\/de\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"UNIX Lecture Notes - Chapter 08 - BooksOfAll German","description":"Communication is necessary when working, while the way we share the our message and data is them very important. Learn more with notes here.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.booksofall.com\/de\/unix-lecture-notes-chapter-08\/","og_locale":"de_DE","og_type":"article","og_title":"UNIX Lecture Notes - Chapter 08 - BooksOfAll German","og_description":"Communication is necessary when working, while the way we share the our message and data is them very important. Learn more with notes here.","og_url":"https:\/\/www.booksofall.com\/de\/unix-lecture-notes-chapter-08\/","og_site_name":"BooksOfAll German","og_image":[{"url":"https:\/\/www.booksofall.com\/de\/wp-content\/uploads\/sites\/9\/2023\/04\/UNIX-Lecture-Notes-cover-UNIX-Lecture-Notes-Chapter_08.jpg","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_image":"https:\/\/www.booksofall.com\/de\/wp-content\/uploads\/sites\/9\/2023\/04\/UNIX-Lecture-Notes-cover-UNIX-Lecture-Notes-Chapter_08.jpg","twitter_misc":{"Gesch\u00e4tzte Lesezeit":"3\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.booksofall.com\/de\/unix-lecture-notes-chapter-08\/","url":"https:\/\/www.booksofall.com\/de\/unix-lecture-notes-chapter-08\/","name":"UNIX Lecture Notes - Chapter 08 - BooksOfAll German","isPartOf":{"@id":"https:\/\/www.booksofall.com\/de\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.booksofall.com\/de\/unix-lecture-notes-chapter-08\/#primaryimage"},"image":{"@id":"https:\/\/www.booksofall.com\/de\/unix-lecture-notes-chapter-08\/#primaryimage"},"thumbnailUrl":"https:\/\/www.booksofall.com\/de\/wp-content\/uploads\/sites\/9\/2023\/04\/UNIX-Lecture-Notes-cover-UNIX-Lecture-Notes-Chapter_08.jpg","datePublished":"2023-04-20T09:58:35+00:00","description":"Communication is necessary when working, while the way we share the our message and data is them very important. Learn more with notes here.","breadcrumb":{"@id":"https:\/\/www.booksofall.com\/de\/unix-lecture-notes-chapter-08\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.booksofall.com\/de\/unix-lecture-notes-chapter-08\/"]}]},{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/www.booksofall.com\/de\/unix-lecture-notes-chapter-08\/#primaryimage","url":"https:\/\/www.booksofall.com\/de\/wp-content\/uploads\/sites\/9\/2023\/04\/UNIX-Lecture-Notes-cover-UNIX-Lecture-Notes-Chapter_08.jpg","contentUrl":"https:\/\/www.booksofall.com\/de\/wp-content\/uploads\/sites\/9\/2023\/04\/UNIX-Lecture-Notes-cover-UNIX-Lecture-Notes-Chapter_08.jpg","width":"827","height":"1169","caption":"UNIX Lecture Notes - Chapter 08"},{"@type":"BreadcrumbList","@id":"https:\/\/www.booksofall.com\/de\/unix-lecture-notes-chapter-08\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.booksofall.com\/de\/"},{"@type":"ListItem","position":2,"name":"Categories","item":"https:\/\/www.booksofall.com\/de\/categories\/"},{"@type":"ListItem","position":3,"name":"UNIX Lecture Notes &#8211; Chapter 08"}]},{"@type":"WebSite","@id":"https:\/\/www.booksofall.com\/de\/#website","url":"https:\/\/www.booksofall.com\/de\/","name":"BooksOfAll German","description":"Biggest IT eBooks library and learning resources - Free eBooks for programming, computing, artificial intelligence and more.","publisher":{"@id":"https:\/\/www.booksofall.com\/de\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.booksofall.com\/de\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"de"},{"@type":"Organization","@id":"https:\/\/www.booksofall.com\/de\/#organization","name":"BooksOfAll German","url":"https:\/\/www.booksofall.com\/de\/","logo":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/www.booksofall.com\/de\/#\/schema\/logo\/image\/","url":"https:\/\/www.booksofall.com\/de\/wp-content\/uploads\/sites\/9\/2022\/06\/booksofall-logo-2.png","contentUrl":"https:\/\/www.booksofall.com\/de\/wp-content\/uploads\/sites\/9\/2022\/06\/booksofall-logo-2.png","width":166,"height":30,"caption":"BooksOfAll German"},"image":{"@id":"https:\/\/www.booksofall.com\/de\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/www.booksofall.com\/de\/wp-json\/wp\/v2\/product\/23545","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.booksofall.com\/de\/wp-json\/wp\/v2\/product"}],"about":[{"href":"https:\/\/www.booksofall.com\/de\/wp-json\/wp\/v2\/types\/product"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.booksofall.com\/de\/wp-json\/wp\/v2\/media\/23549"}],"wp:attachment":[{"href":"https:\/\/www.booksofall.com\/de\/wp-json\/wp\/v2\/media?parent=23545"}],"wp:term":[{"taxonomy":"product_brand","embeddable":true,"href":"https:\/\/www.booksofall.com\/de\/wp-json\/wp\/v2\/product_brand?post=23545"},{"taxonomy":"product_cat","embeddable":true,"href":"https:\/\/www.booksofall.com\/de\/wp-json\/wp\/v2\/product_cat?post=23545"},{"taxonomy":"product_tag","embeddable":true,"href":"https:\/\/www.booksofall.com\/de\/wp-json\/wp\/v2\/product_tag?post=23545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}