{"id":465,"date":"2020-08-18T19:23:47","date_gmt":"2020-08-18T20:23:47","guid":{"rendered":"http:\/\/www.linux-tutorial.info\/?page_id=77"},"modified":"2020-08-22T19:26:18","modified_gmt":"2020-08-22T20:26:18","slug":"this-is-the-page-title-toplevel-298","status":"publish","type":"page","link":"http:\/\/www.linux-tutorial.info\/?page_id=465","title":{"rendered":"Process Files"},"content":{"rendered":"\n<title>ProcessFiles<\/title>\n<p>\n<img decoding=\"async\" src=\"files.gif\"><br \/>\n<p>\nFigure: A Process&#8217;s Files\n<p>\n<p>The figure above shows that there are two data structures that describe\nfile system specific information for each process in the system.\nThe first, the <tt>fs_struct<\/tt>\n<p>\ncontains pointers to this process&#8217;s VFS inodes and its <tt>umask<\/tt>.\nThe <tt>umask<\/tt> is the default mode that new files will be created in, and it can be\nchanged via system calls.\n<p>\nThe second data structure, the <tt>files_struct<\/tt>, contains information about\nall of the files that this process is currently using.\nPrograms read from <em>standard input<\/em> and write to <em>standard output<\/em>.\nAny error messages should go to <em>standard error<\/em>.\nThese may be files, terminal input\/output or a real device but so far as the program\nis concerned they are all treated as files.\nEvery file has its own descriptor and the <tt>files_struct<\/tt> contains pointers to\nup to 256 <tt>file<\/tt> data structures, each one describing a file being used by this\nprocess.\nThe <tt>f_mode<\/tt> field describes what mode the file has been created in; read only,\nread and write or write only.\n<tt>f_pos<\/tt> holds the position in the file where the next read or write operation\nwill occur.\n<tt>f_inode<\/tt> points at the VFS inode describing the file and <tt>f_ops<\/tt> is a pointer\nto a vector of routine addresses; one for each function that you might wish to perform\non a file.\nThere is, for example, a write data function.\nThis abstraction of the interface is very powerful and allows Linux to support\na wide variety of file types.\nIn Linux, pipes are implemented using this mechanism as we shall see later.\n<p>\nEvery time a file is opened, one of the free <tt>file<\/tt> pointers in the <tt>files_struct<\/tt>\nis used to point to the new <tt>file<\/tt> structure.\nLinux processes expect three file descriptors to be open when they start.\nThese are known as <em>standard input<\/em>, <em>standard output<\/em> and <em>standard error<\/em>\nand they are usually inherited from the creating parent process.\nAll accesses to files are via standard system calls which pass or return file\ndescriptors.\nThese descriptors are indices into the process&#8217;s <tt>fd<\/tt> vector, so <em>standard input<\/em>,\n<em>standard output<\/em> and <em>standard error<\/em> have file descriptors 0, 1 and 2.\nEach access to the file uses the <tt>file<\/tt> data structure&#8217;s file operation routines to\ntogether with the VFS inode to achieve its needs.\n","protected":false},"excerpt":{"rendered":"<p>ProcessFiles Figure: A Process&#8217;s Files The figure above shows that there are two data structures that describe file system specific information for each process in the system. The first, the fs_struct contains pointers to this process&#8217;s VFS inodes and its &hellip; <a href=\"http:\/\/www.linux-tutorial.info\/?page_id=465\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-465","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/465","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=465"}],"version-history":[{"count":1,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/465\/revisions"}],"predecessor-version":[{"id":668,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/465\/revisions\/668"}],"wp:attachment":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}