📄 operating_systems.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head> <title></title> <link rel="stylesheet" media="screen" type="text/css" href="./style.css" /> <link rel="stylesheet" media="screen" type="text/css" href="./design.css" /> <link rel="stylesheet" media="print" type="text/css" href="./print.css" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><a href=start.html>start</a></br><div class="toc"><div class="tocheader toctoggle" id="toc__header">Table of Contents</div><div id="toc__inside"><ul class="toc"><li class="clear"><ul class="toc"><li class="level2"><div class="li"><span class="li"><a href="#operating_systems" class="toc">Operating Systems</a></span></div><ul class="toc"><li class="level3"><div class="li"><span class="li"><a href="#introduction_to_linux" class="toc">Introduction to Linux</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#what_is_linux" class="toc">What is Linux?</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#loggin_on" class="toc">Loggin On</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#the_file_system" class="toc">The File System</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#the_file_system_hierarchy_standard" class="toc">The File System Hierarchy Standard</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#file_permissions" class="toc">File Permissions</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#commands" class="toc">Commands</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#standard_input_output_error" class="toc">Standard Input, Output, Error</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#redirection_and_pipes" class="toc">Redirection and Pipes</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#activities_excercises" class="toc">Activities/Excercises</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#introduction_to_uclinux" class="toc">Introduction to uClinux</a></span></div></li></ul></li></ul></li></ul></div></div><h2><a name="operating_systems" id="operating_systems">Operating Systems</a></h2><div class="level2"></div><!-- SECTION [1-29] --><h3><a name="introduction_to_linux" id="introduction_to_linux">Introduction to Linux</a></h3><div class="level3"><p>Linux is an operating system that was initially created as a hobby by a young student, Linus Torvalds, at the University of Helsinki in Finland. Linus had an interest in Minix, a small UNIX system, and decided to develop a system that exceeded the Minix standards. He began his work in 1991 when he released version 0.02 and worked steadily until 1994 when version 1.0 of the Linux Kernel was released. The kernel, at the heart of all Linux systems, is developed and released under the GNU General Public License (GNU <acronym title="GNU General Public License">GPL</acronym>) and its source code is freely available to everyone. It is this kernel that forms the base around which a Linux operating system is developed. There are now literally hundreds of companies and organizations and an equal number of individuals that have released their own versions of operating systems based on the Linux kernel.</p><p>Because of Linux’s success on the x86 desktop, and the proliferation and porting to various processor architectures over the past two years, Linux has become very popular on embedded devices, especially consumer products, telecom routers and switches, Internet appliances, and industrial and automotive devices.</p><p>Using Linux in embedded devices which require some intelligence is attractive for many reasons: </p><ul><li class="level1"><div class="li">it is a mature, robust operating system</div></li><li class="level1"><div class="li">it supports a large number of devices, file systems, and networking protocols</div></li><li class="level1"><div class="li">upgrades and new features are constantly being added, tested and refined by a large community of programmers and users</div></li><li class="level1"><div class="li">it gives everyone from developers to end users complete visibility of the source code</div></li><li class="level1"><div class="li">a large number of applications (such as GNU software) exist which require little to no porting effort</div></li><li class="level1"><div class="li">the low cost of Linux</div></li></ul><p>Some examples of Linux in embedded systems can be found at <a href="http://www.linuxdevices.com/" class="urlextern" title="http://www.linuxdevices.com/" rel="nofollow">Linux Devices</a>.</p></div><!-- SECTION [30-1906] --><h3><a name="what_is_linux" id="what_is_linux">What is Linux?</a></h3><div class="level3"><p>Linux is a monolithic, multitasking, multiuser operating system (<acronym title="Operating System">OS</acronym>) which is a UNIX workalike. It is modularly designed with well understood interdependencies, which allows one to tailor Linux for a variety of purposes. In this course, Linux exists on the development workstation as a full blown <acronym title="Operating System">OS</acronym> with an incredibly large variety of features. However, it also exists on the target system as a very small, focused <acronym title="Operating System">OS</acronym> appropriate for an embedded system.</p><p>An exciting attribute of Linux is that it can be run on a wide variety of microprocessors and microcontrollers. Once you are comfortable with Linux, you will find this to be a great advantage in the embedded systems arena. In particular, your development platform is a Linux box which can be used for many different embedded targets spanning a range of processor architectures, but all running Linux. </p><p>It is not the purpose of this introductory chapter to explore Linux in either great depth or breadth. The assumption is that the course participants are quite computer literate, but may have little previous experience with this particular <acronym title="Operating System">OS</acronym>. Hence our goal is to get up and running on a generic Linux box. To accomplish this the following sections will look at: </p><ul><li class="level1"><div class="li">logging on to a Linux system</div></li><li class="level1"><div class="li">the file system</div></li><li class="level1"><div class="li">a selection of commands</div></li><li class="level1"><div class="li">editing text files</div></li></ul><p>Then we’ll close out the chapter with some activities/exercises followed by salient references.</p></div><!-- SECTION [1907-3359] --><h3><a name="loggin_on" id="loggin_on">Loggin On</a></h3><div class="level3"><p>If you are a new Linux user and have your own machine, then you will be able to log in as root or as a user. Our assumption here is that you are logging in as a user. Working as root (also called super user or system administrator) level should be reserved for tasks that really require it e.g. many system administration tasks. When Linux boots up, it either boots into the X Windows System (providing a <acronym title="Graphical User Interface">GUI</acronym>) or into console mode (no <acronym title="Graphical User Interface">GUI</acronym>). In either case, you will be prompted to log on. The logon is done in two steps in response to two successive prompts requiring that you: </p><ul><li class="level1"><div class="li"> enter your username</div></li><li class="level1"><div class="li"> enter your password</div></li></ul><p>So the system administrator must provide you a username and password ahead of time. Upon successful logon, the <acronym title="Operating System">OS</acronym> starts a shell which responds to your input. There are many possible shells with the bash shell being the default shell for most Linux distributions. However, an embedded system is likely to use a more compact and less powerful shell. The shell interprets commands you enter at the command line, but also is a powerful scripting language. In particular, the shell can interpret text files which are written using the appropriate shell’s grammar. It is beyond the scope of this course to investigate shell scripting. At any rate, once successfully logged in, you can enter commands and, in the X Windows environment, point and click on various icons.</p><p> ’ </p></div><!-- SECTION [3360-5110] --><h3><a name="the_file_system" id="the_file_system">The File System</a></h3><div class="level3"><p>Linux, like most operating systems, has a hierarchical file structure. Application developers would like sufficient standardization in that hierarchy (and in other aspects of Linux) that they need not tailor their application’s installation and operation for each style of Linux distribution. There is an evolving <a href="http://www.linuxbase.org/" class="urlextern" title="http://www.linuxbase.org/" rel="nofollow">Linux Standard Base</a> and perhaps the most mature component is the file system hierarchy. However, the space and performance constraints of an embedded system will force an embedded Linux to stray from the standard. Nor is that particularly serious; an embedded system is a special purpose system, less likely to cause an application developer pain. In this section we’ll look at the file system hierarchy standard and then at the hierarchy found in uClinux, as an example of an embedded system. Note that our embedded system development will typically be on the Linux workstation where the standard is hopefully followed. At the same time an understanding of the uClinux hierarchy will give us insight into the embedded Linux world.</p></div><!-- SECTION [5111-6213] --><h3><a name="the_file_system_hierarchy_standard" id="the_file_system_hierarchy_standard">The File System Hierarchy Standard</a></h3><div class="level3"><p>The File System Hierarchy Standard, which at this writing is at Version 2.3 can be found <a href="http://www.pathname.com/fhs/" class="urlextern" title="http://www.pathname.com/fhs/" rel="nofollow">here</a> We’ll give an overview of what we need for this course, but you are encouraged to look at the standard for the underlying rationale.</p><p>The root of the file hierarchy is symbolized simply by /. There is some confusion possible because one of the top level subdirectories under / is called root, but the latter is essentially a home directory for the root user (system administrator). The immediate subdirectories of / are described in the following table. The File System Hierarchy Standard discusses each of these directories in some detail, not only the contents, but accepted conventions for their usage. Of course, the subdirectories contain files and further subdirectories and so on. </p><p>Note that a directory is actually one of several kinds of files from the perspective of the <acronym title="Operating System">OS</acronym>, but it is convenient to make the distinction between directories and other files here. All common distributions allow one additional directory at the same level as those of Table 1, the proc directory. It is not part of the standard, but deserves mention. It is often called a pseudo directory. It contains information about the executing kernel. The files hold data on such things as the resource usage of current processes, what CPU is present, interrupt allocation, I/O port allocations, pci bus components, devices, modules currently installed, and so on. Much of the information is generated dynamically when it is accessed.</p><table class="inline"> <tr> <td class="centeralign"> <em><strong>Directory Name</strong></em> </td><td class="centeralign"> <em><strong>Purpose/Contents</strong></em> </td> </tr> <tr> <td>bin</td><td>essential command binaries which may be used by the system administrator and by ordinary users, required for system</td> </tr> <tr> <td>boot</td><td>boot kernel image and configuration files used by the boot loader</td> </tr> <tr> <td>dev</td><td>device files</td> </tr> <tr> <td>etc</td><td>host-specific configuration files</td> </tr> <tr> <td><code>home</code></td><td>user home directories</td> </tr> <tr> <td><code>lib</code></td><td>essential shared libraries and kernel modules</td> </tr> <tr> <td><code>mnt</code><code> </code></td><td>mount point for temporarily mounting file systems such as those on a CDROM or floppy disk</td> </tr> <tr> <td><code>opt </code></td><td>add-on application software packages</td> </tr> <tr> <td><code>root</code></td><td>the root user’s home directory</td> </tr> <tr> <td><code>sbin</code></td><td>system binaries, essential for system administration, but not for system boot</td> </tr> <tr> <td><code>tmp</code></td><td>location of temporary files</td> </tr> <tr> <td><code>usr</code></td><td>secondary hierarchy, intended as shareable, read- only data. Here you’ll find games, include files used by C programs, the linux source code hierarchy, and so on</td> </tr> <tr> <td><code>var</code></td><td>variable data such as spool directories and log files.</td> </tr></table><br /></div><h4><a name="the_file_system_hierarchy_in_uclinux" id="the_file_system_hierarchy_in_uclinux">The file system hierarchy in uClinux</a></h4><div class="level4"><p>The directories at the top level of the unmodified uClinux hierarchy are tabulated next. As would be expected, these ‘standard/ directories are much sparser than a workstation resident Linux. Keep in mind that we do our development on our workstation rather than on the target. For example, if we write a C program to incorporate into our STAMP/uClinux target, it is written and compiled on the workstation - so there is no need for the C program include files to be in the uClinux hierarchy.</p></div><h4><a name="pathnames" id="pathnames">Pathnames</a></h4><div class="level4"><p>If your username is, say, jsmythe, then when you log on you will be placed in <code>jsmythe/</code> as your current working directory. Where is this located with respect to the root of the file hierarchy? The top level under root contains the subdirectories of Table 1, which includes the home subdirectory. </p><p>user home directories including <code>jsmythe/</code> (the trailing slash indicates a directory, but may be omitted at the end of a pathname). Designating the root of the file system by a leading, solitary slash (/), we find the jsmythe log on directory by navigating like so / → home → jsmythe. This is compacted as a pathname </p><p><code>/home/jsmythe </code>If you used an editor to create the file vita.txt in this home directory, it would be found at <code>/home/jsmythe/vita.txt </code></p><p> <code>/ </code><code>home/</code><code>jsmythe</code><code>jsmythe/</code><code>vita.txt</code> </p><p> A pathname that starts at the root of the file hierarchy starts with / and is called an absolute pathname. Clearly if you are 42 levels deep in the hierarchy, absolute pathnames become unwieldy. Hence, Linux also provides relative pathnames. Let’s look at some examples of relative pathnames. If you have logged on to your home directory at <code>/home/jsmythe</code>, where you have created a file <code>vita.txt</code>, then its absolute pathname is, as before, <code>/home/jsmythe/vita.txt</code> but working from within the home directory <code>/home/jsmythe/</code>, you can refer to this file as <code>vita.txt</code> or as <code>./vita.txt</code> The dot (.) indicates that the path starts at the current working directory; so, in our example, it effectively replaces <code>/home/jsmythe</code>. Hence, when working within <code>/home/jsmythe</code>, all three of the following are equivalent: <code>/home/jsmythe/vita.txt ./vita.txt vita.txt.</code> Similarly the double dot (..) represents the parent directory of the current working directory.</p></div><!-- SECTION [6214-11270] --><h3><a name="file_permissions" id="file_permissions">File Permissions</a></h3><div class="level3"><p>File permissions are part of the security system. They help </p><ul><li class="level1"><div class="li">protect the <acronym title="Operating System">OS</acronym> from users, whether malicious or clumsy</div></li><li class="level1"><div class="li">protect each user from other users</div></li></ul><p>Permissions cover </p><ul><li class="level1"><div class="li">reading a file</div>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -