{"id":23461,"date":"2023-04-19T08:07:45","date_gmt":"2023-04-19T08:07:45","guid":{"rendered":"https:\/\/www.booksofall.com\/?post_type=product&#038;p=23461"},"modified":"2023-04-19T08:22:42","modified_gmt":"2023-04-19T08:22:42","slug":"unix-lecture-notes-chapter-02","status":"publish","type":"product","link":"https:\/\/www.booksofall.com\/fr\/unix-lecture-notes-chapter-02\/","title":{"rendered":"UNIX Lecture Notes &#8211; Chapter 02"},"content":{"rendered":"<h2>2.1 Introduction<\/h2>\n<p>This chapter introduces the two primary methods of I\/O possible in a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Unix\">UNIX<\/a>: buffered and unbuffered. By trying to write the who and <a href=\"https:\/\/www.geeksforgeeks.org\/cp-command-linux-examples\/\">cp commands<\/a>, we will learn explore how to create, open, read, write, and close arbitrary \u001cles. &#8220;Arbitrary&#8221; in this context means that they are not necessarily text files. We will write several different versions of the who command, simply to illustrate different approaches to the problem of reading from a \u001cfile. They will differ in their performance characteristics and their portability. The chapter uses this exercise to introduce the UNIX concept of time, and the first of several important databases provided by the kernel, as well as the kernel&#8217;s interface to those databases. We also write two different versions of a simplified cp command, one using read() and write(), and the other using memory-mapped I\/O.<\/p>\n<p>2.2 Commands Are (Usually) Programs<\/p>\n<p>In UNIX, most commands are programs, almost always written in <a href=\"https:\/\/en.wikipedia.org\/wiki\/C_(programming_language)\">C<\/a>. Some commands are not programs; they are built into the shell and therefore are called shell builtins. Exactly which commands are builtins varies from one shell to another1, but there are some that are common to almost all shells, such as cd and exit. When you type cd, for example, the shell does not run the cd program; it jumps to the internal code that implements the cd command itself. You can think of the shell as containing a C switch statement inside a loop. When it sees that the command is a built in, it jumps to the code to execute it. Some commands, such as <a href=\"https:\/\/www.ibm.com\/docs\/en\/aix\/7.1?topic=p-pwd-command\">pwd<\/a>, are both shell builtins and programs. By default the shell built in will be executed if the user types pwd; to get the program version, one can either precede the command with a backslash &#8220;\\&#8221;, as in \\pwd, or type the full path name, \/bin\/pwd.<\/p>\n<p>Command programs are located in one of several directories, the most common being \/bin, \/usr\/bin, and \/usr\/local\/bin. The \/usr\/local\/bin directory is traditionally used as a repository for commands that do not come with the UNIX distribution and have been added as local extras. Many packages that are installed after the operating system installation are placed in subdirectories of \/usr\/local. Administrative commands, such as those for creating and modifying user accounts, are found in \/usr\/sbin. Many UNIX systems still retain the old \/usr\/ucb directory. (The &#8220;ucb&#8221; in \/usr\/ucb stands for the University of California at Berkeley. The \/usr\/ucb directory, if it exists, contains commands that are part of the BSD distributions. Some of the commands in \/usr\/ucb are also in \/usr\/bin and have di\u001bfferent semantics. If the same command exists in both \/usr\/bin and in some other directory such as \/usr\/ucb, the<a href=\"https:\/\/www.ibm.com\/docs\/en\/aix\/7.1?topic=accounts-path-environment-variable\"> PATH environment<\/a> variable just like the one used in <a href=\"https:\/\/windows.microsoft.com\/\">Windows<\/a> and <a href=\"https:\/\/en.wikipedia.org\/wiki\/Disk_operating_system\">DOS<\/a>, determines which command will be run. The PATH variable contains a list of the directories to search when the command is typed without a leading path. Whichever directory is earliest in the list is the one whose version of the command is used. Thus, if more exists in both \/usr\/ucb and \/usr\/bin, as well as in your working directory, and \/usr\/bin precedes \/usr\/ucb which precedes \u0010.\u0011 in your PATH variable, and if you type<\/p>\n<p><em>$ more myfile<\/em><\/p>\n<p>then \/usr\/bin\/more will run. If instead you type<\/p>\n<p><em>$ .\/more myfile<\/em><\/p>\n<p>then your PATH is not searched and your private more program will run. If you type<\/p>\n<p><em>$ \/usr\/ucb\/more myfile<\/em><\/p>\n<p>then your PATH is not searched and \/usr\/ucb\/more will run.<\/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-02-1bs0xg1ton?p=1\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n","protected":false},"featured_media":23465,"template":"","meta":{"_yoast_wpseo_title":"","_yoast_wpseo_metadesc":"There are 2 primary methods of I\/O possible in a UNIX, which are buffered and unbuffered. Learn more about them in this informative note now!"},"product_brand":[],"product_cat":[376],"product_tag":[],"class_list":{"0":"post-23461","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 02 - BooksOfAll French<\/title>\n<meta name=\"description\" content=\"There are 2 primary methods of I\/O possible in a UNIX, which are buffered and unbuffered. Learn more about them in this informative note now!\" \/>\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\/fr\/unix-lecture-notes-chapter-02\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"UNIX Lecture Notes - Chapter 02 - BooksOfAll French\" \/>\n<meta property=\"og:description\" content=\"There are 2 primary methods of I\/O possible in a UNIX, which are buffered and unbuffered. Learn more about them in this informative note now!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.booksofall.com\/fr\/unix-lecture-notes-chapter-02\/\" \/>\n<meta property=\"og:site_name\" content=\"BooksOfAll French\" \/>\n<meta property=\"article:modified_time\" content=\"2023-04-19T08:22:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2023\/04\/UNIX-Lecture-Notes-cover-02.jpg\" \/><meta property=\"og:image\" content=\"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2023\/04\/UNIX-Lecture-Notes-cover-02.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"827\" \/>\n\t<meta property=\"og:image:height\" content=\"1169\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2023\/04\/UNIX-Lecture-Notes-cover-02.jpg\" \/>\n<meta name=\"twitter:label1\" content=\"Dur\u00e9e de lecture estim\u00e9e\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.booksofall.com\/fr\/unix-lecture-notes-chapter-02\/\",\"url\":\"https:\/\/www.booksofall.com\/fr\/unix-lecture-notes-chapter-02\/\",\"name\":\"UNIX Lecture Notes - Chapter 02 - BooksOfAll French\",\"isPartOf\":{\"@id\":\"https:\/\/www.booksofall.com\/fr\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.booksofall.com\/fr\/unix-lecture-notes-chapter-02\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.booksofall.com\/fr\/unix-lecture-notes-chapter-02\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2023\/04\/UNIX-Lecture-Notes-cover-02.jpg\",\"datePublished\":\"2023-04-19T08:07:45+00:00\",\"dateModified\":\"2023-04-19T08:22:42+00:00\",\"description\":\"There are 2 primary methods of I\/O possible in a UNIX, which are buffered and unbuffered. Learn more about them in this informative note now!\",\"breadcrumb\":{\"@id\":\"https:\/\/www.booksofall.com\/fr\/unix-lecture-notes-chapter-02\/#breadcrumb\"},\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.booksofall.com\/fr\/unix-lecture-notes-chapter-02\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\/\/www.booksofall.com\/fr\/unix-lecture-notes-chapter-02\/#primaryimage\",\"url\":\"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2023\/04\/UNIX-Lecture-Notes-cover-02.jpg\",\"contentUrl\":\"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2023\/04\/UNIX-Lecture-Notes-cover-02.jpg\",\"width\":\"827\",\"height\":\"1169\",\"caption\":\"UNIX Lecture Notes - Chapter 02\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.booksofall.com\/fr\/unix-lecture-notes-chapter-02\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.booksofall.com\/fr\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Categories\",\"item\":\"https:\/\/www.booksofall.com\/fr\/categories\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"UNIX Lecture Notes &#8211; Chapter 02\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.booksofall.com\/fr\/#website\",\"url\":\"https:\/\/www.booksofall.com\/fr\/\",\"name\":\"BooksOfAll French\",\"description\":\"Biggest IT eBooks library and learning resources - Free eBooks for programming, computing, artificial intelligence and more.\",\"publisher\":{\"@id\":\"https:\/\/www.booksofall.com\/fr\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.booksofall.com\/fr\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"fr-FR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.booksofall.com\/fr\/#organization\",\"name\":\"BooksOfAll French\",\"url\":\"https:\/\/www.booksofall.com\/fr\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\/\/www.booksofall.com\/fr\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2022\/06\/booksofall-logo-2.png\",\"contentUrl\":\"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2022\/06\/booksofall-logo-2.png\",\"width\":166,\"height\":30,\"caption\":\"BooksOfAll French\"},\"image\":{\"@id\":\"https:\/\/www.booksofall.com\/fr\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"UNIX Lecture Notes - Chapter 02 - BooksOfAll French","description":"There are 2 primary methods of I\/O possible in a UNIX, which are buffered and unbuffered. Learn more about them in this informative note now!","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\/fr\/unix-lecture-notes-chapter-02\/","og_locale":"fr_FR","og_type":"article","og_title":"UNIX Lecture Notes - Chapter 02 - BooksOfAll French","og_description":"There are 2 primary methods of I\/O possible in a UNIX, which are buffered and unbuffered. Learn more about them in this informative note now!","og_url":"https:\/\/www.booksofall.com\/fr\/unix-lecture-notes-chapter-02\/","og_site_name":"BooksOfAll French","article_modified_time":"2023-04-19T08:22:42+00:00","og_image":[{"url":"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2023\/04\/UNIX-Lecture-Notes-cover-02.jpg","type":"","width":"","height":""},{"width":827,"height":1169,"url":"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2023\/04\/UNIX-Lecture-Notes-cover-02.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_image":"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2023\/04\/UNIX-Lecture-Notes-cover-02.jpg","twitter_misc":{"Dur\u00e9e de lecture estim\u00e9e":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.booksofall.com\/fr\/unix-lecture-notes-chapter-02\/","url":"https:\/\/www.booksofall.com\/fr\/unix-lecture-notes-chapter-02\/","name":"UNIX Lecture Notes - Chapter 02 - BooksOfAll French","isPartOf":{"@id":"https:\/\/www.booksofall.com\/fr\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.booksofall.com\/fr\/unix-lecture-notes-chapter-02\/#primaryimage"},"image":{"@id":"https:\/\/www.booksofall.com\/fr\/unix-lecture-notes-chapter-02\/#primaryimage"},"thumbnailUrl":"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2023\/04\/UNIX-Lecture-Notes-cover-02.jpg","datePublished":"2023-04-19T08:07:45+00:00","dateModified":"2023-04-19T08:22:42+00:00","description":"There are 2 primary methods of I\/O possible in a UNIX, which are buffered and unbuffered. Learn more about them in this informative note now!","breadcrumb":{"@id":"https:\/\/www.booksofall.com\/fr\/unix-lecture-notes-chapter-02\/#breadcrumb"},"inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.booksofall.com\/fr\/unix-lecture-notes-chapter-02\/"]}]},{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/www.booksofall.com\/fr\/unix-lecture-notes-chapter-02\/#primaryimage","url":"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2023\/04\/UNIX-Lecture-Notes-cover-02.jpg","contentUrl":"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2023\/04\/UNIX-Lecture-Notes-cover-02.jpg","width":"827","height":"1169","caption":"UNIX Lecture Notes - Chapter 02"},{"@type":"BreadcrumbList","@id":"https:\/\/www.booksofall.com\/fr\/unix-lecture-notes-chapter-02\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.booksofall.com\/fr\/"},{"@type":"ListItem","position":2,"name":"Categories","item":"https:\/\/www.booksofall.com\/fr\/categories\/"},{"@type":"ListItem","position":3,"name":"UNIX Lecture Notes &#8211; Chapter 02"}]},{"@type":"WebSite","@id":"https:\/\/www.booksofall.com\/fr\/#website","url":"https:\/\/www.booksofall.com\/fr\/","name":"BooksOfAll French","description":"Biggest IT eBooks library and learning resources - Free eBooks for programming, computing, artificial intelligence and more.","publisher":{"@id":"https:\/\/www.booksofall.com\/fr\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.booksofall.com\/fr\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"fr-FR"},{"@type":"Organization","@id":"https:\/\/www.booksofall.com\/fr\/#organization","name":"BooksOfAll French","url":"https:\/\/www.booksofall.com\/fr\/","logo":{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/www.booksofall.com\/fr\/#\/schema\/logo\/image\/","url":"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2022\/06\/booksofall-logo-2.png","contentUrl":"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2022\/06\/booksofall-logo-2.png","width":166,"height":30,"caption":"BooksOfAll French"},"image":{"@id":"https:\/\/www.booksofall.com\/fr\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/www.booksofall.com\/fr\/wp-json\/wp\/v2\/product\/23461","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.booksofall.com\/fr\/wp-json\/wp\/v2\/product"}],"about":[{"href":"https:\/\/www.booksofall.com\/fr\/wp-json\/wp\/v2\/types\/product"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.booksofall.com\/fr\/wp-json\/wp\/v2\/media\/23465"}],"wp:attachment":[{"href":"https:\/\/www.booksofall.com\/fr\/wp-json\/wp\/v2\/media?parent=23461"}],"wp:term":[{"taxonomy":"product_brand","embeddable":true,"href":"https:\/\/www.booksofall.com\/fr\/wp-json\/wp\/v2\/product_brand?post=23461"},{"taxonomy":"product_cat","embeddable":true,"href":"https:\/\/www.booksofall.com\/fr\/wp-json\/wp\/v2\/product_cat?post=23461"},{"taxonomy":"product_tag","embeddable":true,"href":"https:\/\/www.booksofall.com\/fr\/wp-json\/wp\/v2\/product_tag?post=23461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}