﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-我自闲庭信步,悠然自得,不亦乐乎.-随笔分类-UNIX/Linux</title><link>http://www.cppblog.com/huyi/category/1054.html</link><description>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
------ Keep life simple&lt;br&gt;

GMail/GTalk/MSN:huyi.zg@gmail.com</description><language>zh-cn</language><lastBuildDate>Wed, 28 May 2008 14:11:52 GMT</lastBuildDate><pubDate>Wed, 28 May 2008 14:11:52 GMT</pubDate><ttl>60</ttl><item><title>Linux启动协议Ver.2.04</title><link>http://www.cppblog.com/huyi/archive/2006/06/20/8745.html</link><dc:creator>HuYi</dc:creator><author>HuYi</author><pubDate>Tue, 20 Jun 2006 06:46:00 GMT</pubDate><guid>http://www.cppblog.com/huyi/archive/2006/06/20/8745.html</guid><wfw:comment>http://www.cppblog.com/huyi/comments/8745.html</wfw:comment><comments>http://www.cppblog.com/huyi/archive/2006/06/20/8745.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/huyi/comments/commentRss/8745.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/huyi/services/trackbacks/8745.html</trackback:ping><description><![CDATA[
		<p>       THE LINUX/I386 BOOT PROTOCOL<br />       ----------------------------</p>
		<p>      H. Peter Anvin &lt;<a href="mailto:hpa@zytor.com">hpa@zytor.com</a>&gt;<br />   Last update 2005-09-02</p>
		<p>On the i386 platform, the Linux kernel uses a rather complicated boot<br />convention.  This has evolved partially due to historical aspects, as<br />well as the desire in the early days to have the kernel itself be a<br />bootable image, the complicated PC memory model and due to changed<br />expectations in the PC industry caused by the effective demise of<br />real-mode DOS as a mainstream operating system.</p>
		<p>Currently, four versions of the Linux/i386 boot protocol exist.</p>
		<p>Old kernels: zImage/Image support only.  Some very early kernels<br />  may not even support a command line.</p>
		<p>Protocol 2.00: (Kernel 1.3.73) Added bzImage and initrd support, as<br />  well as a formalized way to communicate between the<br />  boot loader and the kernel.  setup.S made relocatable,<br />  although the traditional setup area still assumed<br />  writable.</p>
		<p>Protocol 2.01: (Kernel 1.3.76) Added a heap overrun warning.</p>
		<p>Protocol 2.02: (Kernel 2.4.0-test3-pre3) New command line protocol.<br />  Lower the conventional memory ceiling. No overwrite<br />  of the traditional setup area, thus making booting<br />  safe for systems which use the EBDA from SMM or 32-bit<br />  BIOS entry points.  zImage deprecated but still<br />  supported.</p>
		<p>Protocol 2.03: (Kernel 2.4.18-pre1) Explicitly makes the highest possible<br />  initrd address available to the bootloader.</p>
		<p>Protocol 2.04: (Kernel 2.6.14) Extend the syssize field to four bytes.</p>
		<p>
				<br />**** MEMORY LAYOUT</p>
		<p>The traditional memory map for the kernel loader, used for Image or<br />zImage kernels, typically looks like:</p>
		<p> |    |<br />0A0000 +------------------------+<br /> |  Reserved for BIOS  | Do not use.  Reserved for BIOS EBDA.<br />09A000 +------------------------+<br /> |  Stack/heap/cmdline  | For use by the kernel real-mode code.<br />098000 +------------------------+ <br /> |  Kernel setup   | The kernel real-mode code.<br />090200 +------------------------+<br /> |  Kernel boot sector  | The kernel legacy boot sector.<br />090000 +------------------------+<br /> |  Protected-mode kernel | The bulk of the kernel image.<br />010000 +------------------------+<br /> |  Boot loader   | &lt;- Boot sector entry point 0000:7C00<br />001000 +------------------------+<br /> |  Reserved for MBR/BIOS |<br />000800 +------------------------+<br /> |  Typically used by MBR |<br />000600 +------------------------+ <br /> |  BIOS use only  |<br />000000 +------------------------+</p>
		<p>
				<br />When using bzImage, the protected-mode kernel was relocated to<br />0x100000 ("high memory"), and the kernel real-mode block (boot sector,<br />setup, and stack/heap) was made relocatable to any address between<br />0x10000 and end of low memory. Unfortunately, in protocols 2.00 and<br />2.01 the command line is still required to live in the 0x9XXXX memory<br />range, and that memory range is still overwritten by the early kernel.<br />The 2.02 protocol resolves that problem.</p>
		<p>It is desirable to keep the "memory ceiling" -- the highest point in<br />low memory touched by the boot loader -- as low as possible, since<br />some newer BIOSes have begun to allocate some rather large amounts of<br />memory, called the Extended BIOS Data Area, near the top of low<br />memory.  The boot loader should use the "INT 12h" BIOS call to verify<br />how much low memory is available.</p>
		<p>Unfortunately, if INT 12h reports that the amount of memory is too<br />low, there is usually nothing the boot loader can do but to report an<br />error to the user.  The boot loader should therefore be designed to<br />take up as little space in low memory as it reasonably can.  For<br />zImage or old bzImage kernels, which need data written into the<br />0x90000 segment, the boot loader should make sure not to use memory<br />above the 0x9A000 point; too many BIOSes will break above that point.</p>
		<p>
				<br />**** THE REAL-MODE KERNEL HEADER</p>
		<p>In the following text, and anywhere in the kernel boot sequence, "a<br />sector" refers to 512 bytes.  It is independent of the actual sector<br />size of the underlying medium.</p>
		<p>The first step in loading a Linux kernel should be to load the<br />real-mode code (boot sector and setup code) and then examine the<br />following header at offset 0x01f1.  The real-mode code can total up to<br />32K, although the boot loader may choose to load only the first two<br />sectors (1K) and then examine the bootup sector size.</p>
		<p>The header looks like:</p>
		<p>Offset Proto Name  Meaning<br />/Size</p>
		<p>01F1/1 ALL(1 setup_sects The size of the setup in sectors<br />01F2/2 ALL root_flags If set, the root is mounted readonly<br />01F4/4 2.04+(2 syssize  The size of the 32-bit code in 16-byte paras<br />01F8/2 ALL ram_size DO NOT USE - for bootsect.S use only<br />01FA/2 ALL vid_mode Video mode control<br />01FC/2 ALL root_dev Default root device number<br />01FE/2 ALL boot_flag 0xAA55 magic number<br />0200/2 2.00+ jump  Jump instruction<br />0202/4 2.00+ header  Magic signature "HdrS"<br />0206/2 2.00+ version  Boot protocol version supported<br />0208/4 2.00+ realmode_swtch Boot loader hook (see below)<br />020C/2 2.00+ start_sys The load-low segment (0x1000) (obsolete)<br />020E/2 2.00+ kernel_version Pointer to kernel version string<br />0210/1 2.00+ type_of_loader Boot loader identifier<br />0211/1 2.00+ loadflags Boot protocol option flags<br />0212/2 2.00+ setup_move_size Move to high memory size (used with hooks)<br />0214/4 2.00+ code32_start Boot loader hook (see below)<br />0218/4 2.00+ ramdisk_image initrd load address (set by boot loader)<br />021C/4 2.00+ ramdisk_size initrd size (set by boot loader)<br />0220/4 2.00+ bootsect_kludge DO NOT USE - for bootsect.S use only<br />0224/2 2.01+ heap_end_ptr Free memory after setup end<br />0226/2 N/A pad1  Unused<br />0228/4 2.02+ cmd_line_ptr 32-bit pointer to the kernel command line<br />022C/4 2.03+ initrd_addr_max Highest legal initrd address</p>
		<p>(1) For backwards compatibility, if the setup_sects field contains 0, the<br />    real value is 4.</p>
		<p>(2) For boot protocol prior to 2.04, the upper two bytes of the syssize<br />    field are unusable, which means the size of a bzImage kernel<br />    cannot be determined.</p>
		<p>If the "HdrS" (0x53726448) magic number is not found at offset 0x202,<br />the boot protocol version is "old".  Loading an old kernel, the<br />following parameters should be assumed:</p>
		<p> Image type = zImage<br /> initrd not supported<br /> Real-mode kernel must be located at 0x90000.</p>
		<p>Otherwise, the "version" field contains the protocol version,<br />e.g. protocol version 2.01 will contain 0x0201 in this field.  When<br />setting fields in the header, you must make sure only to set fields<br />supported by the protocol version in use.</p>
		<p>The "kernel_version" field, if set to a nonzero value, contains a<br />pointer to a null-terminated human-readable kernel version number<br />string, less 0x200.  This can be used to display the kernel version to<br />the user.  This value should be less than (0x200*setup_sects).  For<br />example, if this value is set to 0x1c00, the kernel version number<br />string can be found at offset 0x1e00 in the kernel file.  This is a<br />valid value if and only if the "setup_sects" field contains the value<br />14 or higher.</p>
		<p>Most boot loaders will simply load the kernel at its target address<br />directly.  Such boot loaders do not need to worry about filling in<br />most of the fields in the header.  The following fields should be<br />filled out, however:</p>
		<p>  vid_mode:<br /> Please see the section on SPECIAL COMMAND LINE OPTIONS.</p>
		<p>  type_of_loader:<br /> If your boot loader has an assigned id (see table below), enter<br /> 0xTV here, where T is an identifier for the boot loader and V is<br /> a version number.  Otherwise, enter 0xFF here.</p>
		<p> Assigned boot loader ids:<br /> 0  LILO<br /> 1  Loadlin<br /> 2  bootsect-loader<br /> 3  SYSLINUX<br /> 4  EtherBoot<br /> 5  ELILO<br /> 7  GRuB<br /> 8  U-BOOT</p>
		<p> Please contact &lt;<a href="mailto:hpa@zytor.com">hpa@zytor.com</a>&gt; if you need a bootloader ID<br /> value assigned.</p>
		<p>  loadflags, heap_end_ptr:<br /> If the protocol version is 2.01 or higher, enter the<br /> offset limit of the setup heap into heap_end_ptr and set the<br /> 0x80 bit (CAN_USE_HEAP) of loadflags.  heap_end_ptr appears to<br /> be relative to the start of setup (offset 0x0200).</p>
		<p>  setup_move_size: <br /> When using protocol 2.00 or 2.01, if the real mode<br /> kernel is not loaded at 0x90000, it gets moved there later in<br /> the loading sequence.  Fill in this field if you want<br /> additional data (such as the kernel command line) moved in<br /> addition to the real-mode kernel itself.</p>
		<p>  ramdisk_image, ramdisk_size:<br /> If your boot loader has loaded an initial ramdisk (initrd),<br /> set ramdisk_image to the 32-bit pointer to the ramdisk data<br /> and the ramdisk_size to the size of the ramdisk data.</p>
		<p> The initrd should typically be located as high in memory as<br /> possible, as it may otherwise get overwritten by the early<br /> kernel initialization sequence.  However, it must never be<br /> located above the address specified in the initrd_addr_max<br /> field. The initrd should be at least 4K page aligned.</p>
		<p>  cmd_line_ptr:<br /> If the protocol version is 2.02 or higher, this is a 32-bit<br /> pointer to the kernel command line.  The kernel command line<br /> can be located anywhere between the end of setup and 0xA0000.<br /> Fill in this field even if your boot loader does not support a<br /> command line, in which case you can point this to an empty<br /> string (or better yet, to the string "auto".)  If this field<br /> is left at zero, the kernel will assume that your boot loader<br /> does not support the 2.02+ protocol.</p>
		<p>  ramdisk_max:<br /> The maximum address that may be occupied by the initrd<br /> contents.  For boot protocols 2.02 or earlier, this field is<br /> not present, and the maximum address is 0x37FFFFFF.  (This<br /> address is defined as the address of the highest safe byte, so<br /> if your ramdisk is exactly 131072 bytes long and this field is<br /> 0x37FFFFFF, you can start your ramdisk at 0x37FE0000.)</p>
		<p>
				<br />**** THE KERNEL COMMAND LINE</p>
		<p>The kernel command line has become an important way for the boot<br />loader to communicate with the kernel.  Some of its options are also<br />relevant to the boot loader itself, see "special command line options"<br />below.</p>
		<p>The kernel command line is a null-terminated string currently up to<br />255 characters long, plus the final null.  A string that is too long<br />will be automatically truncated by the kernel, a boot loader may allow<br />a longer command line to be passed to permit future kernels to extend<br />this limit.</p>
		<p>If the boot protocol version is 2.02 or later, the address of the<br />kernel command line is given by the header field cmd_line_ptr (see<br />above.)  This address can be anywhere between the end of the setup<br />heap and 0xA0000.</p>
		<p>If the protocol version is *not* 2.02 or higher, the kernel<br />command line is entered using the following protocol:</p>
		<p> At offset 0x0020 (word), "cmd_line_magic", enter the magic<br /> number 0xA33F.</p>
		<p> At offset 0x0022 (word), "cmd_line_offset", enter the offset<br /> of the kernel command line (relative to the start of the<br /> real-mode kernel).<br /> <br /> The kernel command line *must* be within the memory region<br /> covered by setup_move_size, so you may need to adjust this<br /> field.</p>
		<p>
				<br />**** SAMPLE BOOT CONFIGURATION</p>
		<p>As a sample configuration, assume the following layout of the real<br />mode segment (this is a typical, and recommended layout):</p>
		<p> 0x0000-0x7FFF Real mode kernel<br /> 0x8000-0x8FFF Stack and heap<br /> 0x9000-0x90FF Kernel command line</p>
		<p>Such a boot loader should enter the following fields in the header:</p>
		<p> unsigned long base_ptr; /* base address for real-mode segment */</p>
		<p> if ( setup_sects == 0 ) {<br />  setup_sects = 4;<br /> }</p>
		<p> if ( protocol &gt;= 0x0200 ) {<br />  type_of_loader = &lt;type code&gt;;<br />  if ( loading_initrd ) {<br />   ramdisk_image = &lt;initrd_address&gt;;<br />   ramdisk_size = &lt;initrd_size&gt;;<br />  }<br />  if ( protocol &gt;= 0x0201 ) {<br />   heap_end_ptr = 0x9000 - 0x200;<br />   loadflags |= 0x80; /* CAN_USE_HEAP */<br />  }<br />  if ( protocol &gt;= 0x0202 ) {<br />   cmd_line_ptr = base_ptr + 0x9000;<br />  } else {<br />   cmd_line_magic = 0xA33F;<br />   cmd_line_offset = 0x9000;<br />   setup_move_size = 0x9100;<br />  }<br /> } else {<br />  /* Very old kernel */</p>
		<p>  cmd_line_magic = 0xA33F;<br />  cmd_line_offset = 0x9000;</p>
		<p>  /* A very old kernel MUST have its real-mode code<br />     loaded at 0x90000 */</p>
		<p>  if ( base_ptr != 0x90000 ) {<br />   /* Copy the real-mode kernel */<br />   memcpy(0x90000, base_ptr, (setup_sects+1)*512);<br />   /* Copy the command line */<br />   memcpy(0x99000, base_ptr+0x9000, 256);</p>
		<p>   base_ptr = 0x90000;   /* Relocated */<br />  }</p>
		<p>  /* It is recommended to clear memory up to the 32K mark */<br />  memset(0x90000 + (setup_sects+1)*512, 0,<br />         (64-(setup_sects+1))*512);<br /> }</p>
		<p>
				<br />**** LOADING THE REST OF THE KERNEL</p>
		<p>The 32-bit (non-real-mode) kernel starts at offset (setup_sects+1)*512<br />in the kernel file (again, if setup_sects == 0 the real value is 4.)<br />It should be loaded at address 0x10000 for Image/zImage kernels and<br />0x100000 for bzImage kernels.</p>
		<p>The kernel is a bzImage kernel if the protocol &gt;= 2.00 and the 0x01<br />bit (LOAD_HIGH) in the loadflags field is set:</p>
		<p> is_bzImage = (protocol &gt;= 0x0200) &amp;&amp; (loadflags &amp; 0x01);<br /> load_address = is_bzImage ? 0x100000 : 0x10000;</p>
		<p>Note that Image/zImage kernels can be up to 512K in size, and thus use<br />the entire 0x10000-0x90000 range of memory.  This means it is pretty<br />much a requirement for these kernels to load the real-mode part at<br />0x90000.  bzImage kernels allow much more flexibility.</p>
		<p>
				<br />**** SPECIAL COMMAND LINE OPTIONS</p>
		<p>If the command line provided by the boot loader is entered by the<br />user, the user may expect the following command line options to work.<br />They should normally not be deleted from the kernel command line even<br />though not all of them are actually meaningful to the kernel.  Boot<br />loader authors who need additional command line options for the boot<br />loader itself should get them registered in<br />Documentation/kernel-parameters.txt to make sure they will not<br />conflict with actual kernel options now or in the future.</p>
		<p>  vga=&lt;mode&gt;<br /> &lt;mode&gt; here is either an integer (in C notation, either<br /> decimal, octal, or hexadecimal) or one of the strings<br /> "normal" (meaning 0xFFFF), "ext" (meaning 0xFFFE) or "ask"<br /> (meaning 0xFFFD).  This value should be entered into the<br /> vid_mode field, as it is used by the kernel before the command<br /> line is parsed.</p>
		<p>  mem=&lt;size&gt;<br /> &lt;size&gt; is an integer in C notation optionally followed by K, M<br /> or G (meaning &lt;&lt; 10, &lt;&lt; 20 or &lt;&lt; 30).  This specifies the end<br /> of memory to the kernel. This affects the possible placement<br /> of an initrd, since an initrd should be placed near end of<br /> memory.  Note that this is an option to *both* the kernel and<br /> the bootloader!</p>
		<p>  initrd=&lt;file&gt;<br /> An initrd should be loaded.  The meaning of &lt;file&gt; is<br /> obviously bootloader-dependent, and some boot loaders<br /> (e.g. LILO) do not have such a command.</p>
		<p>In addition, some boot loaders add the following options to the<br />user-specified command line:</p>
		<p>  BOOT_IMAGE=&lt;file&gt;<br /> The boot image which was loaded.  Again, the meaning of &lt;file&gt;<br /> is obviously bootloader-dependent.</p>
		<p>  auto<br /> The kernel was booted without explicit user intervention.</p>
		<p>If these options are added by the boot loader, it is highly<br />recommended that they are located *first*, before the user-specified<br />or configuration-specified command line.  Otherwise, "init=/bin/sh"<br />gets confused by the "auto" option.</p>
		<p>
				<br />**** RUNNING THE KERNEL</p>
		<p>The kernel is started by jumping to the kernel entry point, which is<br />located at *segment* offset 0x20 from the start of the real mode<br />kernel.  This means that if you loaded your real-mode kernel code at<br />0x90000, the kernel entry point is 9020:0000.</p>
		<p>At entry, ds = es = ss should point to the start of the real-mode<br />kernel code (0x9000 if the code is loaded at 0x90000), sp should be<br />set up properly, normally pointing to the top of the heap, and<br />interrupts should be disabled.  Furthermore, to guard against bugs in<br />the kernel, it is recommended that the boot loader sets fs = gs = ds =<br />es = ss.</p>
		<p>In our example from above, we would do:</p>
		<p> /* Note: in the case of the "old" kernel protocol, base_ptr must<br />    be == 0x90000 at this point; see the previous sample code */</p>
		<p> seg = base_ptr &gt;&gt; 4;</p>
		<p> cli(); /* Enter with interrupts disabled! */</p>
		<p> /* Set up the real-mode kernel stack */<br /> _SS = seg;<br /> _SP = 0x9000; /* Load SP immediately after loading SS! */</p>
		<p> _DS = _ES = _FS = _GS = seg;<br /> jmp_far(seg+0x20, 0); /* Run the kernel */</p>
		<p>If your boot sector accesses a floppy drive, it is recommended to<br />switch off the floppy motor before running the kernel, since the<br />kernel boot leaves interrupts off and thus the motor will not be<br />switched off, especially if the loaded kernel has the floppy driver as<br />a demand-loaded module!</p>
		<p>
				<br />**** ADVANCED BOOT TIME HOOKS</p>
		<p>If the boot loader runs in a particularly hostile environment (such as<br />LOADLIN, which runs under DOS) it may be impossible to follow the<br />standard memory location requirements.  Such a boot loader may use the<br />following hooks that, if set, are invoked by the kernel at the<br />appropriate time.  The use of these hooks should probably be<br />considered an absolutely last resort!</p>
		<p>IMPORTANT: All the hooks are required to preserve %esp, %ebp, %esi and<br />%edi across invocation.</p>
		<p>  realmode_swtch:<br /> A 16-bit real mode far subroutine invoked immediately before<br /> entering protected mode.  The default routine disables NMI, so<br /> your routine should probably do so, too.</p>
		<p>  code32_start:<br /> A 32-bit flat-mode routine *jumped* to immediately after the<br /> transition to protected mode, but before the kernel is<br /> uncompressed.  No segments, except CS, are set up; you should<br /> set them up to KERNEL_DS (0x18) yourself.</p>
		<p> After completing your hook, you should jump to the address<br /> that was in this field before your boot loader overwrote it.<br /></p>
<img src ="http://www.cppblog.com/huyi/aggbug/8745.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/huyi/" target="_blank">HuYi</a> 2006-06-20 14:46 <a href="http://www.cppblog.com/huyi/archive/2006/06/20/8745.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>vi常用命令图</title><link>http://www.cppblog.com/huyi/archive/2006/04/18/5808.html</link><dc:creator>HuYi</dc:creator><author>HuYi</author><pubDate>Tue, 18 Apr 2006 03:20:00 GMT</pubDate><guid>http://www.cppblog.com/huyi/archive/2006/04/18/5808.html</guid><wfw:comment>http://www.cppblog.com/huyi/comments/5808.html</wfw:comment><comments>http://www.cppblog.com/huyi/archive/2006/04/18/5808.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/huyi/comments/commentRss/5808.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/huyi/services/trackbacks/5808.html</trackback:ping><description><![CDATA[
		<img height="1252" alt="vi.linuxsir.org000.png.jpg" src="http://www.cppblog.com/images/cppblog_com/huyi/pic/200604/vi.linuxsir.org000.png.jpg" width="1218" border="0" />
<img src ="http://www.cppblog.com/huyi/aggbug/5808.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/huyi/" target="_blank">HuYi</a> 2006-04-18 11:20 <a href="http://www.cppblog.com/huyi/archive/2006/04/18/5808.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux下获取文件变更通知</title><link>http://www.cppblog.com/huyi/archive/2006/04/13/5462.html</link><dc:creator>HuYi</dc:creator><author>HuYi</author><pubDate>Thu, 13 Apr 2006 05:35:00 GMT</pubDate><guid>http://www.cppblog.com/huyi/archive/2006/04/13/5462.html</guid><wfw:comment>http://www.cppblog.com/huyi/comments/5462.html</wfw:comment><comments>http://www.cppblog.com/huyi/archive/2006/04/13/5462.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/huyi/comments/commentRss/5462.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/huyi/services/trackbacks/5462.html</trackback:ping><description><![CDATA[文章是在网上搜到的，我只是截取了其中一段。<br /><br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">#define</span><span style="COLOR: #000000"> _GNU_SOURCE /* needed to get the defines */ </span><span style="COLOR: #000000"><br /><img id="Codehighlighter1_62_115_Open_Image" onclick="this.style.display='none'; Codehighlighter1_62_115_Open_Text.style.display='none'; Codehighlighter1_62_115_Closed_Image.style.display='inline'; Codehighlighter1_62_115_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_62_115_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_62_115_Closed_Text.style.display='none'; Codehighlighter1_62_115_Open_Image.style.display='inline'; Codehighlighter1_62_115_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />#include </span><span id="Codehighlighter1_62_115_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id="Codehighlighter1_62_115_Open_Text"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"> in glibc 2.2 this has the needed <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />values defined </span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">volatile</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> event_fd; <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 信号处理例程 </span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> handler(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> sig, siginfo_t </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">si, </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">data) <br /><img id="Codehighlighter1_249_275_Open_Image" onclick="this.style.display='none'; Codehighlighter1_249_275_Open_Text.style.display='none'; Codehighlighter1_249_275_Closed_Image.style.display='inline'; Codehighlighter1_249_275_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_249_275_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_249_275_Closed_Text.style.display='none'; Codehighlighter1_249_275_Open_Image.style.display='inline'; Codehighlighter1_249_275_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_249_275_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_249_275_Open_Text"><span style="COLOR: #000000">{ <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />event_fd </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> si</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">si_fd; <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> main(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">) <br /><img id="Codehighlighter1_295_807_Open_Image" onclick="this.style.display='none'; Codehighlighter1_295_807_Open_Text.style.display='none'; Codehighlighter1_295_807_Closed_Image.style.display='inline'; Codehighlighter1_295_807_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_295_807_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_295_807_Closed_Text.style.display='none'; Codehighlighter1_295_807_Open_Image.style.display='inline'; Codehighlighter1_295_807_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_295_807_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_295_807_Open_Text"><span style="COLOR: #000000">{ <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000"> sigaction act; <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> fd; <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 登记信号处理例程 </span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #000000">act.sa_sigaction </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> handler; <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />sigemptyset(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">act.sa_mask); <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />act.sa_flags </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> SA_SIGINFO; <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />sigaction(SIGRTMIN, </span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">act, NULL); <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 需要了解当前目录"."的情况 </span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #000000">fd </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> open(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, O_RDONLY); <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />fcntl(fd, F_SETSIG, SIGRTMIN); <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />fcntl(fd, F_NOTIFY, DN_MODIFY</span><span style="COLOR: #000000">|</span><span style="COLOR: #000000">DN_CREATE</span><span style="COLOR: #000000">|</span><span style="COLOR: #000000">DN_MULTISHOT); <br /><img id="Codehighlighter1_598_691_Open_Image" onclick="this.style.display='none'; Codehighlighter1_598_691_Open_Text.style.display='none'; Codehighlighter1_598_691_Closed_Image.style.display='inline'; Codehighlighter1_598_691_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_598_691_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_598_691_Closed_Text.style.display='none'; Codehighlighter1_598_691_Open_Image.style.display='inline'; Codehighlighter1_598_691_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /></span><span id="Codehighlighter1_598_691_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id="Codehighlighter1_598_691_Open_Text"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"> we will now be notified if any of the files <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />in "." is modified or new files are created </span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"> <br /><img id="Codehighlighter1_704_804_Open_Image" onclick="this.style.display='none'; Codehighlighter1_704_804_Open_Text.style.display='none'; Codehighlighter1_704_804_Closed_Image.style.display='inline'; Codehighlighter1_704_804_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_704_804_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_704_804_Closed_Text.style.display='none'; Codehighlighter1_704_804_Open_Image.style.display='inline'; Codehighlighter1_704_804_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /></span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">) </span><span id="Codehighlighter1_704_804_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_704_804_Open_Text"><span style="COLOR: #000000">{ <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 收到信号后，就会执行信号处理例程。 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 而 pause() 也就结束了。 </span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #000000">pause(); <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Got event on fd=%d\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, event_fd); <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span></div><br />上面这一小段例程，对于熟悉 Linux 系统编程的读者朋友们来说，是很容易理解的。程序首先注册一个信号处理例程，然后通知 Kernel，我要观察 fd 上的 DN_MODIFY 和 DN_CREATE 和 DN_MULTISHOT 事件。（关于这些事件的详细定义，请读者朋友们参阅文后所列的参考资料。） Linux Kernel 收到这个请求后，把相应的 fd 的 inode 给做上记号，然后 Linux Kernel 和用户应用程序就自顾自去处理各自的别的事情去了。等到 inode 上发生了相应的事件，Linux Kernel 就把信号发给用户进程，于是开始执行信号处理例程，用户程序对文件系统上的变化也就可以及时的做出反应了。而在这整个过程中，系统以及用户程序的正常运行基本上未受到性能上的影响。这里还需要说明的是，dnotify 并没有通过增加新的系统调用来完成它的功能，而是通过 fcntl 来完成任务的。增加一个系统调用，相对来说是一个很大的手术，而且如果设计不当，处理得不好的话，伤疤会一直留在那里，这是 Linux Kernel 的开发者们所非常不愿意见到的事情。 <br /><p> </p><img src ="http://www.cppblog.com/huyi/aggbug/5462.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/huyi/" target="_blank">HuYi</a> 2006-04-13 13:35 <a href="http://www.cppblog.com/huyi/archive/2006/04/13/5462.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>gun常用工具手册集(chm版)</title><link>http://www.cppblog.com/huyi/archive/2006/04/12/5392.html</link><dc:creator>HuYi</dc:creator><author>HuYi</author><pubDate>Wed, 12 Apr 2006 07:09:00 GMT</pubDate><guid>http://www.cppblog.com/huyi/archive/2006/04/12/5392.html</guid><wfw:comment>http://www.cppblog.com/huyi/comments/5392.html</wfw:comment><comments>http://www.cppblog.com/huyi/archive/2006/04/12/5392.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/huyi/comments/commentRss/5392.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/huyi/services/trackbacks/5392.html</trackback:ping><description><![CDATA[
		<p>我把经常用到的GNU工具文档做成了chm文件，提供给需要的朋友下载。<br />包括如下手册：<br />    C library<br />    awk<br />    autogen<br />    automake<br />    bash<br />    tar<br />    gsasl<br />    sed<br /><a href="/Files/huyi/gnu.part1.rar"><br />http://www.cppblog.com/Files/huyi/gnu.part1.rar</a><br /><u><font color="#0000ff"><a href="/Files/huyi/gnu.part2.rar">http://www.cppblog.com/Files/huyi/gnu.part2.rar</a></font></u></p>
<img src ="http://www.cppblog.com/huyi/aggbug/5392.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/huyi/" target="_blank">HuYi</a> 2006-04-12 15:09 <a href="http://www.cppblog.com/huyi/archive/2006/04/12/5392.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>GCC参数祥解</title><link>http://www.cppblog.com/huyi/archive/2006/03/20/4354.html</link><dc:creator>HuYi</dc:creator><author>HuYi</author><pubDate>Mon, 20 Mar 2006 02:30:00 GMT</pubDate><guid>http://www.cppblog.com/huyi/archive/2006/03/20/4354.html</guid><wfw:comment>http://www.cppblog.com/huyi/comments/4354.html</wfw:comment><comments>http://www.cppblog.com/huyi/archive/2006/03/20/4354.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/huyi/comments/commentRss/4354.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/huyi/services/trackbacks/4354.html</trackback:ping><description><![CDATA[[介绍] <br />gcc and g++分别是gnu的c &amp; c++编译器 gcc/g++在执行编译工作的时候，总共需要4步 <br /><br />1.预处理,生成.i的文件[预处理器cpp] <br />2.将预处理后的文件不转换成汇编语言,生成文件.s[编译器egcs] <br />3.有汇编变为目标代码(机器代码)生成.o的文件[汇编器as] <br />4.连接目标代码,生成可执行程序[链接器ld] <br />[参数详解] <br />-x language filename <br />　 设定文件所使用的语言,使后缀名无效,对以后的多个有效.也就是根据约定C语言的后 <br />缀名称是.c的，而C++的后缀名是.C或者.cpp,如果你很个性，决定你的C代码文件的后缀 <br />名是.pig 哈哈，那你就要用这个参数,这个参数对他后面的文件名都起作用，除非到了 <br />下一个参数的使用。 <br />　　可以使用的参数吗有下面的这些 <br />　　`c', `objective-c', `c-header', `c++', `cpp-output', `assembler', and `a <br />ssembler-with-cpp'. <br />　　看到英文，应该可以理解的。 <br />　　例子用法: <br />　　gcc -x c hello.pig <br />　　 <br />-x none filename <br />　　关掉上一个选项，也就是让gcc根据文件名后缀，自动识别文件类型 <br />　　例子用法: <br />　　gcc -x c hello.pig -x none hello2.c <br />　　 <br />-c <br />　　只激活预处理,编译,和汇编,也就是他只把程序做成obj文件 <br />　　例子用法: <br />　　gcc -c hello.c <br />　　他将生成.o的obj文件 <br />-S <br />　　只激活预处理和编译，就是指把文件编译成为汇编代码。 <br />　　例子用法 <br />　　gcc -S hello.c <br />　　他将生成.s的汇编代码，你可以用文本编辑器察看 <br />-E <br />　　只激活预处理,这个不生成文件,你需要把它重定向到一个输出文件里面. <br />　　例子用法: <br />　　gcc -E hello.c &gt; pianoapan.txt <br />　　gcc -E hello.c | more <br />　　慢慢看吧,一个hello word 也要与处理成800行的代码 <br />-o <br />　　制定目标名称,缺省的时候,gcc 编译出来的文件是a.out,很难听,如果你和我有同感 <br />，改掉它,哈哈 <br />　　例子用法 <br />　　gcc -o hello.exe hello.c (哦,windows用习惯了) <br />　　gcc -o hello.asm -S hello.c <br />-pipe <br />　　使用管道代替编译中临时文件,在使用非gnu汇编工具的时候,可能有些问题 <br />　　gcc -pipe -o hello.exe hello.c <br />-ansi <br />　　关闭gnu c中与ansi c不兼容的特性,激活ansi c的专有特性(包括禁止一些asm inl <br />ine typeof关键字,以及UNIX,vax等预处理宏, <br />-fno-asm <br />　　此选项实现ansi选项的功能的一部分，它禁止将asm,inline和typeof用作关键字。 <br />　　　　 <br />-fno-strict-prototype <br />　　只对g++起作用,使用这个选项,g++将对不带参数的函数,都认为是没有显式的对参数 <br />的个数和类型说明,而不是没有参数. <br />　　而gcc无论是否使用这个参数,都将对没有带参数的函数,认为城没有显式说明的类型 <br /><br />　　 <br />-fthis-is-varialble <br />　　就是向传统c++看齐,可以使用this当一般变量使用. <br />　　 <br />-fcond-mismatch <br />　　允许条件表达式的第二和第三参数类型不匹配,表达式的值将为void类型 <br />　　 <br />-funsigned-char <br />-fno-signed-char <br />-fsigned-char <br />-fno-unsigned-char <br />　　这四个参数是对char类型进行设置,决定将char类型设置成unsigned char(前两个参 <br />数)或者 signed char(后两个参数) <br />　　 <br />-include file <br />　　包含某个代码,简单来说,就是便以某个文件,需要另一个文件的时候,就可以用它设 <br />定,功能就相当于在代码中使用#include&lt;filename&gt; <br />　　例子用法: <br />　　gcc hello.c -include /root/pianopan.h <br />　　 <br />-imacros file <br />　　将file文件的宏,扩展到gcc/g++的输入文件,宏定义本身并不出现在输入文件中 <br />　　 <br />-Dmacro <br />　　相当于C语言中的#define macro <br />　　 <br />-Dmacro=defn <br />　　相当于C语言中的#define macro=defn <br />　　 <br />-Umacro <br />　　相当于C语言中的#undef macro <br />-undef <br />　　取消对任何非标准宏的定义 <br />　　 <br />-Idir <br />　　在你是用#include"file"的时候,gcc/g++会先在当前目录查找你所制定的头文件,如 <br />果没有找到,他回到缺省的头文件目录找,如果使用-I制定了目录,他 <br />　　回先在你所制定的目录查找,然后再按常规的顺序去找. <br />　　对于#include&lt;file&gt;,gcc/g++会到-I制定的目录查找,查找不到,然后将到系统的缺 <br />省的头文件目录查找 <br />　　 <br />-I- <br />　　就是取消前一个参数的功能,所以一般在-Idir之后使用 <br />　　 <br />-idirafter dir <br />　　在-I的目录里面查找失败,讲到这个目录里面查找. <br />　　 <br />-iprefix prefix <br />-iwithprefix dir <br />　　一般一起使用,当-I的目录查找失败,会到prefix+dir下查找 <br />　　 <br />-nostdinc <br />　　使编译器不再系统缺省的头文件目录里面找头文件,一般和-I联合使用,明确限定头 <br />文件的位置 <br />　　 <br />-nostdin C++ <br />　　规定不在g++指定的标准路经中搜索,但仍在其他路径中搜索,.此选项在创libg++库 <br />使用 <br />　　 <br />-C <br />　　在预处理的时候,不删除注释信息,一般和-E使用,有时候分析程序，用这个很方便的 <br /><br />　　 <br />-M <br />　　生成文件关联的信息。包含目标文件所依赖的所有源代码你可以用gcc -M hello.c <br />来测试一下，很简单。 <br />　　 <br />-MM <br />　　和上面的那个一样，但是它将忽略由#include&lt;file&gt;造成的依赖关系。 <br />　　 <br />-MD <br />　　和-M相同，但是输出将导入到.d的文件里面 <br />　　 <br />-MMD <br />　　和-MM相同，但是输出将导入到.d的文件里面 <br />　　 <br />-Wa,option <br />　　此选项传递option给汇编程序;如果option中间有逗号,就将option分成多个选项,然 <br />后传递给会汇编程序 <br />　　 <br />-Wl.option <br />　　此选项传递option给连接程序;如果option中间有逗号,就将option分成多个选项,然 <br />后传递给会连接程序. <br />　　 <br />-llibrary <br />　　制定编译的时候使用的库 <br />　　例子用法 <br />　　gcc -lcurses hello.c <br />　　使用ncurses库编译程序 <br />　　 <br />-Ldir <br />　　制定编译的时候，搜索库的路径。比如你自己的库，可以用它制定目录，不然 <br />　　编译器将只在标准库的目录找。这个dir就是目录的名称。 <br />　　 <br />-O0 <br />-O1 <br />-O2 <br />-O3 <br />　　编译器的优化选项的4个级别，-O0表示没有优化,-O1为缺省值，-O3优化级别最高　 <br />　 　　 <br />-g <br />　　只是编译器，在编译的时候，产生调试信息。 <br />　　 <br />-gstabs <br />　　此选项以stabs格式声称调试信息,但是不包括gdb调试信息. <br />　　 <br />-gstabs+ <br />　　此选项以stabs格式声称调试信息,并且包含仅供gdb使用的额外调试信息. <br />　　 <br />-ggdb <br />　　此选项将尽可能的生成gdb的可以使用的调试信息. <br />-static <br />　　此选项将禁止使用动态库，所以，编译出来的东西，一般都很大，也不需要什么 <br />动态连接库，就可以运行. <br />-share <br />　　此选项将尽量使用动态库，所以生成文件比较小，但是需要系统由动态库. <br />-traditional <br />　　试图让编译器支持传统的C语言特性 <br />[参考资料] <br />-Linux/UNIX高级编程 <br />　　中科红旗软件技术有限公司编著.清华大学出版社出版 <br />-Gcc man page <br />　　 <br />[ChangeLog] <br />-2002-08-10 <br />　　ver 0.1 发布最初的文档 <br />-2002-08-11 <br />　　ver 0.11 修改文档格式 <br />-2002-08-12 <br />　　ver 0.12 加入了对静态库，动态库的参数 <br />-2002-08-16 <br />　　ver 0.16 增加了gcc编译的4个阶段的命令 <br />运行 gcc/egcs <br />**********运行 gcc/egcs*********************** <br />　　GCC 是 GNU 的 C 和 C++ 编译器。实际上，GCC 能够编译三种语言：C、C++ 和 O <br />bject C（C 语言的一种面向对象扩展）。利用 gcc 命令可同时编译并连接 C 和 C++ <br />源程序。 <br />　　如果你有两个或少数几个 C 源文件，也可以方便地利用 GCC 编译、连接并生成可 <br />执行文件。例如，假设你有两个源文件 main.c 和 factorial.c 两个源文件，现在要编 <br />译生成一个计算阶乘的程序。 <br />代码: <br />----------------------- <br />清单 factorial.c <br />----------------------- <br />int factorial (int n) <br />{ <br />　　if (n &lt;= 1) <br />　　　return 1; <br />　　else <br />　　　return factorial (n - 1) * n; <br />} <br />----------------------- <br />清单 main.c <br />----------------------- <br />#include　&lt;stdio.h&gt; <br />#include　&lt;unistd.h&gt; <br />int factorial (int n); <br />int main (int argc, char **argv) <br />{ <br />　　int n; <br />　　if (argc &lt; 2) <br />　　{ <br />　　　　printf ("Usage: %s n\n", argv [0]); <br />　　　　return -1; <br />　　} <br />　　else <br />　　{ <br />　　　n = atoi (argv[1]); <br />　　　printf ("Factorial of %d is %d.\n", n, factorial (n)); <br />　　 } <br />　　return 0; <br />} <br />----------------------- <br />利用如下的命令可编译生成可执行文件，并执行程序： <br />$ gcc -o factorial main.c factorial.c <br />$ ./factorial 5 <br />Factorial of 5 is 120. <br />　　GCC 可同时用来编译 C 程序和 C++ 程序。一般来说，C 编译器通过源文件的后缀 <br />名来判断是 C 程序还是 C++ 程序。在 Linux 中，C 源文件的后缀名为 .c，而 C++ 源 <br />文件的后缀名为 .C 或 .cpp。但是，gcc 命令只能编译 C++ 源文件，而不能自动和 C <br />++ 程序使用的库连接。因此，通常使用 g++ 命令来完成 C++ 程序的编译和连接，该程 <br />序会自动调用 gcc 实现编译。假设我们有一个如下的 C++ 源文件（hello.C）： <br />#include &lt;iostream&gt; <br />void main (void) <br />{ <br />　　cout &lt;&lt; "Hello, world!" &lt;&lt; endl; <br />} <br />则可以如下调用 g++ 命令编译、连接并生成可执行文件： <br />$ g++ -o hello hello.C <br />$ ./hello <br />Hello, world! <br />**********************gcc/egcs 的主要选项********* <br />gcc 命令的常用选项 <br />选项 解释 <br />-ansi 只支持 ANSI 标准的 C 语法。这一选项将禁止 GNU C 的某些特色， <br />例如 asm 或 typeof 关键词。 <br />-c 只编译并生成目标文件。 <br />-DMACRO 以字符串“1”定义 MACRO 宏。 <br />-DMACRO=DEFN 以字符串“DEFN”定义 MACRO 宏。 <br />-E 只运行 C 预编译器。 <br />-g 生成调试信息。GNU 调试器可利用该信息。 <br />-IDIRECTORY 指定额外的头文件搜索路径DIRECTORY。 <br />-LDIRECTORY 指定额外的函数库搜索路径DIRECTORY。 <br />-lLIBRARY 连接时搜索指定的函数库LIBRARY。 <br />-m486 针对 486 进行代码优化。 <br />-o FILE 生成指定的输出文件。用在生成可执行文件时。 <br />-O0 不进行优化处理。 <br />-O 或 -O1 优化生成代码。 <br />-O2 进一步优化。 <br />-O3 比 -O2 更进一步优化，包括 inline 函数。 <br />-shared 生成共享目标文件。通常用在建立共享库时。 <br />-static 禁止使用共享连接。 <br />-UMACRO 取消对 MACRO 宏的定义。 <br />-w 不生成任何警告信息。 <br />-Wall 生成所有警告信息。<img src ="http://www.cppblog.com/huyi/aggbug/4354.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/huyi/" target="_blank">HuYi</a> 2006-03-20 10:30 <a href="http://www.cppblog.com/huyi/archive/2006/03/20/4354.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++对并行运算的支持</title><link>http://www.cppblog.com/huyi/archive/2006/03/13/4089.html</link><dc:creator>HuYi</dc:creator><author>HuYi</author><pubDate>Mon, 13 Mar 2006 07:22:00 GMT</pubDate><guid>http://www.cppblog.com/huyi/archive/2006/03/13/4089.html</guid><wfw:comment>http://www.cppblog.com/huyi/comments/4089.html</wfw:comment><comments>http://www.cppblog.com/huyi/archive/2006/03/13/4089.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/huyi/comments/commentRss/4089.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/huyi/services/trackbacks/4089.html</trackback:ping><description><![CDATA[<P>MPICH：支持大规模，复杂的集群编程，强力支持SPMD模型，也支持SMP，MPP和多用户配置。<BR>PVM：&nbsp;&nbsp;&nbsp; 支持异构环境集群编程，很容易用于单用户，中小规模的集群应用程序，支持MPP。<BR>MICO：&nbsp; 支持分布式和面向对象的并行编程，包括对agent和多agent编程的良好支持。<BR>POSIX： 支持函数或对象级单个应用程序内的并行处理，可以用来利用SMP，MPP的优势。</P><img src ="http://www.cppblog.com/huyi/aggbug/4089.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/huyi/" target="_blank">HuYi</a> 2006-03-13 15:22 <a href="http://www.cppblog.com/huyi/archive/2006/03/13/4089.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[小知识]信号量和自旋锁</title><link>http://www.cppblog.com/huyi/archive/2006/03/09/3937.html</link><dc:creator>HuYi</dc:creator><author>HuYi</author><pubDate>Thu, 09 Mar 2006 08:02:00 GMT</pubDate><guid>http://www.cppblog.com/huyi/archive/2006/03/09/3937.html</guid><wfw:comment>http://www.cppblog.com/huyi/comments/3937.html</wfw:comment><comments>http://www.cppblog.com/huyi/archive/2006/03/09/3937.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/huyi/comments/commentRss/3937.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/huyi/services/trackbacks/3937.html</trackback:ping><description><![CDATA[<P>信号量：<BR>简单点说，就是<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 一个整数变量i。<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2 一个等待进程链表。<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3 一对P/V操作函数。<BR>P将i减1，如果i&lt;0了，就把当前正在运行的进程加入到进程链表中，并阻塞之。<BR>V将i加1，如果i&gt;=0,则激活链表中的1个或者多个进程。<BR>同时适用于单处理器和多处理器<BR><BR>自旋锁：<BR>在多处理器中，如果修改一些内核结构所需要的时间非常短（短于把进程插入进程链表中并挂起它所需要的时间），则应该使用自旋锁。</P>
<P>&nbsp;</P><img src ="http://www.cppblog.com/huyi/aggbug/3937.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/huyi/" target="_blank">HuYi</a> 2006-03-09 16:02 <a href="http://www.cppblog.com/huyi/archive/2006/03/09/3937.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[小知识]存储器管理区</title><link>http://www.cppblog.com/huyi/archive/2006/03/07/3842.html</link><dc:creator>HuYi</dc:creator><author>HuYi</author><pubDate>Tue, 07 Mar 2006 09:11:00 GMT</pubDate><guid>http://www.cppblog.com/huyi/archive/2006/03/07/3842.html</guid><wfw:comment>http://www.cppblog.com/huyi/comments/3842.html</wfw:comment><comments>http://www.cppblog.com/huyi/archive/2006/03/07/3842.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/huyi/comments/commentRss/3842.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/huyi/services/trackbacks/3842.html</trackback:ping><description><![CDATA[80x86体系结构的两种硬件约束：<BR>1。ISA总线直接存储器存取（DMA）只能对RAM的前16MB寻址。<BR>2。在大RAM的32位机中，由于线性地址空间太小的原因，CPU不能直接访问所有物理存储器。<BR><BR>所以，Linux把物理存储器分为三个管理区：<BR>ZONE_DMA &lt;= 16MB<BR>16MB &lt; ZONE_NORMAL &lt; 896MB<BR>ZONE_HIGHMEM &gt; 896MB<BR><BR>在64位机中没有使用ZONE_HIGHNEN<img src ="http://www.cppblog.com/huyi/aggbug/3842.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/huyi/" target="_blank">HuYi</a> 2006-03-07 17:11 <a href="http://www.cppblog.com/huyi/archive/2006/03/07/3842.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>