<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7128755548240021396</id><updated>2024-10-07T13:01:39.937+08:00</updated><category term="bash"/><category term="kernel"/><category term="gstreamer"/><category term="linuxprogram"/><category term="tcpip stack"/><category term="iptables"/><category term="linux admin"/><category term="翻墙"/><title type='text'>chenrui</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://chennrui.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://chennrui.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>big bang</name><uri>http://www.blogger.com/profile/07380722230385048574</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQEwGR3hniNIaoAuRxuoFMsyO_esdj85N9t60Bj4qln24_y7qj8mnx8taxn-KrBbc2zQBfJviUXvScqSs7OD3zJBpP5wimbihfo-Y9yHnpYezKHlkxxt5YRkQ2wyrFDA/s220/linux-logo.png'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>23</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7128755548240021396.post-7715051637536638061</id><published>2011-08-07T17:58:00.000+08:00</published><updated>2011-08-07T17:58:12.062+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="kernel"/><category scheme="http://www.blogger.com/atom/ns#" term="tcpip stack"/><title type='text'>tcpip stack(2) -- L3 send and receve</title><content type='html'>&lt;style type=&quot;text/css&quot;&gt;
 &lt;!--
  @page { margin: 0.79in }
  H2 { margin-top: 0.18in; margin-bottom: 0.18in; line-height: 173%; page-break-inside: avoid }
  H2.western { font-family: &quot;Liberation Serif&quot;, serif; font-size: 14pt }
  H2.cjk { font-family: &quot;DejaVu Sans&quot;; font-size: 14pt }
  H2.ctl { font-family: &quot;DejaVu Sans&quot;; font-size: 16pt }
  P { margin-bottom: 0.08in }
 --&gt;
 
&lt;/style&gt;  &lt;br /&gt;
&lt;ol&gt;&lt;li&gt;&lt;h2 class=&quot;western&quot;&gt;&lt;span style=&quot;font-family: DejaVu Sans;&quot;&gt;数据传输的数据结构&lt;/span&gt;&lt;/h2&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;div style=&quot;margin-bottom: 0in; margin-left: 0.58in;&quot;&gt;&lt;span style=&quot;font-family: DejaVu Sans;&quot;&gt;在&lt;/span&gt;BSD Socket&lt;span style=&quot;font-family: DejaVu Sans;&quot;&gt;层使用&lt;/span&gt;struct msghdr&lt;span style=&quot;font-family: DejaVu Sans;&quot;&gt;保存数据。在&lt;/span&gt;INET Socket&lt;span style=&quot;font-family: DejaVu Sans;&quot;&gt;层以下使用&lt;/span&gt;struct sk_buff&lt;span style=&quot;font-family: DejaVu Sans;&quot;&gt;保存数据，这个结构被整个网络协议栈使用，如&lt;/span&gt;MAC&lt;span style=&quot;font-family: DejaVu Sans;&quot;&gt;或其他&lt;/span&gt;L2&lt;span style=&quot;font-family: DejaVu Sans;&quot;&gt;链路协议，三层&lt;/span&gt;IP&lt;span style=&quot;font-family: DejaVu Sans;&quot;&gt;，四层&lt;/span&gt;TCP&lt;span style=&quot;font-family: DejaVu Sans;&quot;&gt;或&lt;/span&gt;UDP&lt;span style=&quot;font-family: DejaVu Sans;&quot;&gt;等。并且其中的成员变量在结构从一层向另一层传递时解析本层的数据头。&lt;/span&gt;&lt;/div&gt;&lt;ol start=&quot;2&quot;&gt;&lt;li&gt;&lt;h2 class=&quot;western&quot;&gt;&lt;span style=&quot;font-family: DejaVu Sans;&quot;&gt;网络层数据收发&lt;/span&gt;&lt;/h2&gt;a.发送数据&lt;/li&gt;
&lt;/ol&gt;&amp;nbsp;raw_sendmsg&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |- ip_router_output_flow 根据saddr和daddr在rt_hash_table中查找路由表。&lt;br /&gt;
&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; 如果没有找到则查找fib，并__mkroute_output创建struct rtable。将rtable加入rt_hash_table&lt;br /&gt;
&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; neigh_create:根据rtable-&amp;gt;dst_entry创建struct neigh邻居,设置定时操作neigh_timer_handler,&lt;br /&gt;
&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; arp_constructor设置arp处理函数&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; |&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; |- ip_append_data&amp;nbsp;&amp;nbsp; 将大数据分片,创建struct sk_buffer,并将其加入struct sk-&amp;gt;sk_write_queue&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; |&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; |- ip_push_pending_frames&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |- ip_finish_skb&amp;nbsp; 构造ip头&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |- ip_send_skb&lt;br /&gt;
&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; |&lt;br /&gt;
&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; |- ip_local_output--&amp;gt; dst_output--&amp;gt;ip_output (__mkroute_output中指定rth-&amp;gt;dst.output=ip_output)&lt;br /&gt;
&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; |&lt;br /&gt;
&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; |- ip_finish_output&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 如果在hh_cache中找到daddr信息则将数据传到driver&lt;br /&gt;
&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;&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; 否则调用struct dst_entry-&amp;gt;neighbour-&amp;gt;output (neigh_resolve_output)&lt;br /&gt;
&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; |- neigh_resolve_output&lt;br /&gt;
&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; |&lt;br /&gt;
&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; |- neigh_event_send&amp;nbsp; 更改邻居状态为NUD_INCOMPLETE,neigh_timer_handler将发送arp请求(arp_solicit)&lt;br /&gt;
&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; ......&lt;br /&gt;
&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; |- apr_rev -&amp;gt; neigh_update&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 接收arp报文,更新邻居系统&lt;br /&gt;
&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; |&lt;br /&gt;
&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; |- neigh_resolve_output&lt;br /&gt;
&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; |&lt;br /&gt;
&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; |- neigh_hh_init&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 更新hh_cache&lt;br /&gt;
&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; |&lt;br /&gt;
&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; |- dev_hard_header&amp;nbsp;&amp;nbsp; 初始化以太网报文头&lt;br /&gt;
&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; |&lt;br /&gt;
&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; |- dev_queue_xmit 数据发送至硬件抽象层(neigh-&amp;gt;ops-&amp;gt;queue_xmit) &lt;br /&gt;
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;br /&gt;
&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; |- dev-&amp;gt;netdev_ops-&amp;gt;ndo_start_xmit&amp;nbsp; 驱动数据发送函数&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.发送数据 &lt;br /&gt;
&amp;nbsp;|- netif_rx&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; 驱动创建skb后调用此函数，函数skb加入struct softnet_data-&amp;gt;input_pkt_queue中，之后出发软中断&lt;br /&gt;
&amp;nbsp;|&amp;nbsp; ......&lt;br /&gt;
&amp;nbsp;|- net_rx_action&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 数据接收软中断&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; |- process_backlog&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; |- __skb_dequeue&amp;nbsp; 从softnet_data-&amp;gt;input_pkt_queue接收数据&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |- __netif_receive_skb&amp;nbsp; 调用struct packet_type-&amp;gt;func(inet_init是注册ip_packet_type)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |- ip_rcv&amp;nbsp;&amp;nbsp; 解析ip头&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;br /&gt;
&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; |- ip_rcv_finish&lt;br /&gt;
&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; |&lt;br /&gt;
&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; |- ip_route_input_common&amp;nbsp;&amp;nbsp;&amp;nbsp; 查找路由表，如果没有则加入fib和rt_hash_table&lt;br /&gt;
&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; |&lt;br /&gt;
&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; |- ip_local_deliver&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; (struct dst_entry-&amp;gt;input)&lt;br /&gt;
&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; |&lt;br /&gt;
&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; |- ip_local_deliver_finish&lt;br /&gt;
&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; |&lt;br /&gt;
&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; |- raw_v4_input&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 将skb加入struct sock-&amp;gt;sk_receive_queue&lt;br /&gt;
&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; |&lt;br /&gt;
&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; |- 如果数据不是raw类型，则进入L4处理函数struct net_protocol-&amp;gt;handler</content><link rel='replies' type='application/atom+xml' href='http://chennrui.blogspot.com/feeds/7715051637536638061/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://chennrui.blogspot.com/2011/08/tcpip-stack2-l3-send-and-receve.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/7715051637536638061'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/7715051637536638061'/><link rel='alternate' type='text/html' href='http://chennrui.blogspot.com/2011/08/tcpip-stack2-l3-send-and-receve.html' title='tcpip stack(2) -- L3 send and receve'/><author><name>big bang</name><uri>http://www.blogger.com/profile/07380722230385048574</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQEwGR3hniNIaoAuRxuoFMsyO_esdj85N9t60Bj4qln24_y7qj8mnx8taxn-KrBbc2zQBfJviUXvScqSs7OD3zJBpP5wimbihfo-Y9yHnpYezKHlkxxt5YRkQ2wyrFDA/s220/linux-logo.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7128755548240021396.post-6343405963473264843</id><published>2011-07-31T17:52:00.001+08:00</published><updated>2011-07-31T17:54:54.987+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="kernel"/><category scheme="http://www.blogger.com/atom/ns#" term="tcpip stack"/><title type='text'>tcpip stack(1) -- init</title><content type='html'>1. socket_init()建立vfsmount文件系统&lt;br /&gt;
static struct vfsmount *sock_mnt __read_mostly;&lt;br /&gt;
static int __init sock_init(void)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; skb_init(); //为socket buffer创建高速缓存&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; init_inodecache(); //为struct sock_alloc创建高速缓存&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; //创建已安装文件系统&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; register_filesystem(&amp;amp;sock_fs_type);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; sock_mnt = kern_mount(&amp;amp;sock_fs_type);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static struct file_system_type sock_fs_type = {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; .name =  &quot;sockfs&quot;,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; .mount = sockfs_mount,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; .kill_sb = kill_anon_super,&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
static struct file_system_type *file_systems;&lt;br /&gt;
int register_filesystem(struct file_system_type * fs)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; struct file_system_type ** p;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; /*将sock_fs_type注册到全局的file_systems中*/&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; p = find_filesystem(fs-&amp;gt;name, strlen(fs-&amp;gt;name)); &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; if(p)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return error;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *p = fs;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
函数kern_mount()将调用vfs_kern_mount()创建vfsmount&lt;br /&gt;
struct vfsmount *&lt;br /&gt;
vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; struct vfsmount *mnt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; struct dentry *root;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; mnt = alloc_vfsmnt(name);  //从高速缓存中获取vsfmount结构&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; root = mount_fs(type, flags, name, data);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; //建立vfsmount与dentry的对应关系&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; mnt-&amp;gt;mnt_root = root;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; mnt-&amp;gt;mnt_sb = root-&amp;gt;d_sb;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; mnt-&amp;gt;mnt_mountpoint = mnt-&amp;gt;mnt_root;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; mnt-&amp;gt;mnt_parent = mnt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return mnt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
创建dentry对象&lt;br /&gt;
struct dentry *&lt;br /&gt;
mount_fs(struct file_system_type *type, int flags, const char *name, void *data)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; struct dentry *root;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; struct super_block *sb;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; root = type-&amp;gt;mount(type, flags, name, data); //调用sock_fs_type中的sockfs_mount()&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; sb = root-&amp;gt;d_sb;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return root;&lt;br /&gt;
}&lt;br /&gt;
sockfs_mount()将调用mount_pseudo()&lt;br /&gt;
static const struct super_operations sockfs_ops = {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; .alloc_inode = sock_alloc_inode,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; .destroy_inode = sock_destroy_inode,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; .statfs  = simple_statfs,&lt;br /&gt;
};&lt;br /&gt;
static const struct dentry_operations sockfs_dentry_operations = {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; .d_dname  = sockfs_dname,&lt;br /&gt;
};&lt;br /&gt;
struct dentry *mount_pseudo(struct file_system_type *fs_type, char *name,&lt;br /&gt;
const struct super_operations *ops,&lt;br /&gt;
const struct dentry_operations *dops, unsigned long magic)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; struct super_block *s = sget(fs_type, NULL, set_anon_super, NULL);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; //创建super block并注册到全局super_blocks中&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; struct dentry *dentry;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; struct inode *root;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; root = new_inode(s); //创建inode对象&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; dentry = d_alloc(NULL, &amp;amp;d_name); //创建dentry对象&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; //将创建的3个对象建立联系&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ……&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return dentry;&lt;br /&gt;
}&lt;br /&gt;
初始化完成后：sock_mnt-&amp;gt;vfsmount-&amp;gt;dentry-&amp;gt;inode-&amp;gt;superblock&lt;br /&gt;
2. inet_init()网络网络层初始化&lt;br /&gt;
static int __init inet_init(void)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; proto_register(/*tcp, udp, raw*/); //将inet socket结构proto注册到proto_list中&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; sock_register(&amp;amp;inet_family_ops); //将协议族net_proto_family注册到net_families中&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; inet_add_protocol(/*tcp, udp, icmp*/); &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; //将协议处理接口结构net_protocol注册到inet_protos中&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; //建立inetsw链表与inetsw_array数组的对应关系&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; for (r = &amp;amp;inetsw[0]; r &amp;lt; &amp;amp;inetsw[SOCK_MAX]; ++r)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INIT_LIST_HEAD(r);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; for (q = inetsw_array; q &amp;lt; &amp;amp;inetsw_array[INETSW_ARRAY_LEN]; ++q)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; inet_register_protosw(q);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ……&lt;br /&gt;
}&lt;br /&gt;
Socket基本结构：&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvCkhrE43mW3Gm1z1DLUsTzS8n4mQsH6xMKIkFXC1HYPXC0wIv9B_T_XZ18MHBwDgybjU0JkAi5jcrgDsLOaFuGtQ8eeSXBWx8iJR_JYAlDUMT0H3OtQvtlsnfPlnVbZf1heIvJAls9SsB/s1600/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;223&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvCkhrE43mW3Gm1z1DLUsTzS8n4mQsH6xMKIkFXC1HYPXC0wIv9B_T_XZ18MHBwDgybjU0JkAi5jcrgDsLOaFuGtQ8eeSXBWx8iJR_JYAlDUMT0H3OtQvtlsnfPlnVbZf1heIvJAls9SsB/s320/1.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
3. socket()&lt;br /&gt;
SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; struct socket *sock;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; /*调用sock_alloc创建struct socket_alloc，其中包含struct socket和struct inode;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 调用sock-&amp;gt;create()--------&amp;gt;inet_create()创建struct sock&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; retval = sock_create(family, type, protocol, &amp;amp;sock); &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; //创建文件描述符struct file，将file指针放入fd数组中&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; retval = sock_map_fd(sock,flags&amp;amp;(O_CLOEXEC|O_NONBLOCK)); &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return retval;&lt;br /&gt;
}&lt;br /&gt;
结构如图：&lt;br /&gt;
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct socket_alloc&lt;br /&gt;
&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;&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; |-------------|&lt;br /&gt;
&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;&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; socket &amp;nbsp;&amp;nbsp;     |------&amp;gt;sock&lt;br /&gt;
&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;&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; |-------------|&lt;br /&gt;
&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; |----dentry-&amp;gt;|&amp;nbsp;&amp;nbsp; inode &amp;nbsp;&amp;nbsp;      |------------&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; Struct file-&amp;gt;path-|&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;      Super_block&lt;br /&gt;
&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; |----fsmount-&amp;gt;dentry-&amp;gt;inode------&amp;gt;&lt;br /&gt;
&lt;br /&gt;
用户进程通过文件描述符就可以找到INET socket。BSD socket层从已注册的INET proto_ops结构中调用INET层socket支持例程来执行工作。例如，一个ipv4的BSD socket建立请求，将用到下层的INET socket的建立函数。为了不把BSD socket与tcpip的特定信息搞混，INET socket层使用它自己的数据结构struct sock，它与BSD socket结构相连。Sock结构的协议操作指针也在初始化时建立，它依赖于被请求的协议。如果请求时TCP，那么sock结构的协议操作指针将指向TCP连接所必须的TCP协议操作集。&lt;br /&gt;
4. net_dev_ini ()网络设备抽象层初始化&lt;br /&gt;
static int __init net_dev_init(void)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; //Initialise the packet receive queues.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; for (i = 0; i &amp;lt; NR_CPUS; i++) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct softnet_data *queue;           queue = &amp;amp;per_cpu(softnet_data, i);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; skb_queue_head_init(&amp;amp;queue-&amp;gt;input_pkt_queue);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; queue-&amp;gt;throttle = 0;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; queue-&amp;gt;cng_level = 0;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; queue-&amp;gt;avg_blog = 10; /* arbitrary non-zero */&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; queue-&amp;gt;completion_queue = NULL;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INIT_LIST_HEAD(&amp;amp;queue-&amp;gt;poll_list);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set_bit(__LINK_STATE_START, &amp;amp;queue-&amp;gt;backlog_dev.state);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; queue-&amp;gt;backlog_dev.weight = weight_p;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; queue-&amp;gt;backlog_dev.poll = process_backlog;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; atomic_set(&amp;amp;queue-&amp;gt;backlog_dev.refcnt, 1);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; open_softirq(NET_TX_SOFTIRQ, net_tx_action, NULL);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; open_softirq(NET_RX_SOFTIRQ, net_rx_action, NULL);&lt;br /&gt;
}&lt;br /&gt;
为每个CPU创建一个struct softnet_data的队列，表示要交给此CPU处理的数据包。并注册网络相关的软中断。&lt;br /&gt;
网络设备抽象层通过struct net_device调用指定的device driver与设备通信。&lt;br /&gt;
5. device driver initialize&lt;br /&gt;
用insmod加载驱动模块时，内核会默认执行模块中的module_init()函数&lt;br /&gt;
static int __init xxx_init_module (void)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return pci_register_driver(&amp;amp;xxx_pci_driver);&lt;br /&gt;
}&lt;br /&gt;
module_init(xxx_init_module);&lt;br /&gt;
&lt;br /&gt;
pci_register_driver()注册设备驱动程序(struct pci_driver)&lt;br /&gt;
int __pci_register_driver(struct pci_driver *drv, struct module *owner,&lt;br /&gt;
const char *mod_name)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; /*将strcut pci_driver加到总线链表中，并执行.probe()初始化设备驱动 */&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; driver_register(&amp;amp;drv-&amp;gt;driver);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; /* 为驱动创建sysfs文件 */&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; pci_create_newid_file(drv);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; pci_create_removeid_file(drv);&lt;br /&gt;
}&lt;br /&gt;
strcut pci_driver-&amp;gt;probe()调用驱动初始化函数初始化struct net_device&lt;br /&gt;
static int __devinit xxx_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; struct net_device *dev = NULL;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; xxx_init_board (pdev, &amp;amp;dev);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; /* 设备抽象层提供驱动操作函数 */&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; dev-&amp;gt;open = xxx_open;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; dev-&amp;gt;hard_start_xmit =xxx_start_xmit;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; dev-&amp;gt;poll = xxx_poll;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; dev-&amp;gt;stop = xxx_close;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; dev-&amp;gt;do_ioctl = netdev_ioctl;&lt;br /&gt;
}</content><link rel='replies' type='application/atom+xml' href='http://chennrui.blogspot.com/feeds/6343405963473264843/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://chennrui.blogspot.com/2011/07/tcpip-stack1-init.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/6343405963473264843'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/6343405963473264843'/><link rel='alternate' type='text/html' href='http://chennrui.blogspot.com/2011/07/tcpip-stack1-init.html' title='tcpip stack(1) -- init'/><author><name>big bang</name><uri>http://www.blogger.com/profile/07380722230385048574</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQEwGR3hniNIaoAuRxuoFMsyO_esdj85N9t60Bj4qln24_y7qj8mnx8taxn-KrBbc2zQBfJviUXvScqSs7OD3zJBpP5wimbihfo-Y9yHnpYezKHlkxxt5YRkQ2wyrFDA/s220/linux-logo.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvCkhrE43mW3Gm1z1DLUsTzS8n4mQsH6xMKIkFXC1HYPXC0wIv9B_T_XZ18MHBwDgybjU0JkAi5jcrgDsLOaFuGtQ8eeSXBWx8iJR_JYAlDUMT0H3OtQvtlsnfPlnVbZf1heIvJAls9SsB/s72-c/1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7128755548240021396.post-1557368281081172335</id><published>2011-07-31T17:32:00.000+08:00</published><updated>2011-07-31T17:32:44.479+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="kernel"/><title type='text'>study kernel(3) -- memory,vfs</title><content type='html'>一、 内存及内存管理&lt;br /&gt;
1. 内存地址&lt;br /&gt;
三种不同的地址：&lt;br /&gt;
1． 逻辑地址：每个逻辑地址都有一个段和偏移量组成，偏移量指明从段开始的地方到实际地址之间的距离。Linux中逻辑地址总是与线性地址一致。&lt;br /&gt;
2． 线性地址：虚拟地址。32位系统有4G的线性地址，64位系统有8G线性地址。&lt;br /&gt;
3． 物理地址：物理内存的实际地址。&lt;br /&gt;
地址转换关系：&lt;br /&gt;
逻辑地址通过分段单元转换为线性地址，之后再通过分页单元转换为物理地址。&lt;br /&gt;
2. 页&lt;br /&gt;
页：线性地址被分成固定长度为单位的组。页内部连续的线性地址被映射到连续的物理地址中。页既指一组线性地址，又指这组地址中的数据。Linux每一页有4KB容量。&lt;br /&gt;
页框：或物理页。一个页框包含一个页，因此页框长度与页长度一致。页可存放在任何一个物理页中。页框就是物理内存。&lt;br /&gt;
页表：保存线性地址和物理地址之间映射的页。&lt;br /&gt;
内核中用页述符struct page描述每一个页框的状态信息，所有的页描述符都保存在mem_map数组中。&lt;br /&gt;
struct page {&lt;br /&gt;
unsigned long flags; //描述页框状态&lt;br /&gt;
atomic_t _count;  //页框的引用计数&lt;br /&gt;
atomic_t _mapcount; //页框中页表数目&lt;br /&gt;
void *virtual;;   //页框的虚拟地址&lt;br /&gt;
……&lt;br /&gt;
}&lt;br /&gt;
转换关系如图：&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSnU0KhpTFRD_aDP38XvMNzfax-U1jwUpY3GoJ97zrUdSzAUBw4p8IzgWOPoksXVL_sx0cVUzbahBIG9DZt3l57rsI46RJff8u5NKgzX7NMXflT3i6bxvSI1xEr8GUwFoto76_g_p5kKKO/s1600/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;216&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSnU0KhpTFRD_aDP38XvMNzfax-U1jwUpY3GoJ97zrUdSzAUBw4p8IzgWOPoksXVL_sx0cVUzbahBIG9DZt3l57rsI46RJff8u5NKgzX7NMXflT3i6bxvSI1xEr8GUwFoto76_g_p5kKKO/s320/1.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
3. 内存管理区&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUyREdg6znWHNClxmLYuLIzqEgEVP4YiGKKLqLjppTd7BOiE1snxaacPeNaFzXEj3jQ7skLFR2x0xjgz4c2iE6Vc7DWSzmQug10OQtYqd8qWvTpAEYiCPtBMQQXmtjUkjE-rg7iWstYOcM/s1600/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;136&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUyREdg6znWHNClxmLYuLIzqEgEVP4YiGKKLqLjppTd7BOiE1snxaacPeNaFzXEj3jQ7skLFR2x0xjgz4c2iE6Vc7DWSzmQug10OQtYqd8qWvTpAEYiCPtBMQQXmtjUkjE-rg7iWstYOcM/s320/1.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
内核物理内存划分为不同的区，并用struct zone描述每个区。每个管理区的分配器可以在他的物理内存区域添加删除页框。&lt;br /&gt;
&lt;br /&gt;
4. slab分配器&lt;br /&gt;
slab层把不同对象划分为高速缓存组，每个高速缓存被划分为多个slab，每个slabe由一个或多个连续的页框组成，页框中包含对象的数据结构。&lt;br /&gt;
如struct inode由inode_cachep高速缓存进行分配。这个高速缓存有一个或多个slab组成。每个slab包含尽可能多的struct indoe对象。当内核请求分配新的inode结构时，内核从部分满或空的slab返回一个指向已分配但未使用的结构的指针。当内核用完后，slab分配器把该对象标记为空闲。&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpxLsCCN-Z74ej5sphVvpxpdXfjtoMGOs2Y-OG-KkRtu-jGEFYLMECBXS1OPl78AZni4q_qt54d_C8UGcTVmCnpa4_oe-8rFUcTu3_zsTQ1Yx0oOKGhnmyFlsA9P9iWzCwIJZhni49N3Ua/s1600/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;136&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpxLsCCN-Z74ej5sphVvpxpdXfjtoMGOs2Y-OG-KkRtu-jGEFYLMECBXS1OPl78AZni4q_qt54d_C8UGcTVmCnpa4_oe-8rFUcTu3_zsTQ1Yx0oOKGhnmyFlsA9P9iWzCwIJZhni49N3Ua/s320/1.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Slab的使用：(struct task_struct)&lt;br /&gt;
a. 创建高速缓存&lt;br /&gt;
static struct kmem_cache *task_struct_cachep; //全局变量&lt;br /&gt;
void __init fork_init(unsigned long mempages) //内核初始化调用&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; task_struct_cachep =&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; kmem_cache_create(&quot;task_struct&quot;, sizeof(struct task_struct),&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ARCH_MIN_TASKALIGN,SLAB_PANIC|SLAB_NOTRACK, NULL);&lt;br /&gt;
}&lt;br /&gt;
b. 申请进程描述符&lt;br /&gt;
当创建子进程会有如下过程&lt;br /&gt;
fork()-&amp;gt;sys_fork()-&amp;gt;do_fork()-&amp;gt;copy_process()-&amp;gt;dup_task_struct()&lt;br /&gt;
static struct task_struct *dup_task_struct(struct task_struct *orig)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; struct task_struct *tsk;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; tsk = kmem_cache_alloc (task_struct_cachep, GFP_KERNEL); &lt;br /&gt;
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //从高速缓存中返回一个进程描述符的指针&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ……&lt;br /&gt;
}&lt;br /&gt;
c. 释放进程描述符&lt;br /&gt;
当进程被销毁时会有如下过程：&lt;br /&gt;
free_task()-&amp;gt;free_task_struct()&lt;br /&gt;
即执行kmem_cache_free(task_struct_cachep, (tsk))，将tsk所指的进程描述符标记为空闲。&lt;br /&gt;
二、 进程地址空间&lt;br /&gt;
1. 进程虚拟内存的使用&lt;br /&gt;
Linux操作系统采用虚拟内存管理技术，使得每个进程都有各自互不干涉的进程地址空间。进程的可用32 位地址系统支持的全部4G 线性空间。进程的线性地址空间分成两部分：1. 从0x00000000 到 0xbfffffff 的线性地址，无论用户态还是内核态的进程都可以寻址。2. 从0xc0000000 到 0xffffffff 的线性地址，只有内核态的进程才能寻址。&lt;br /&gt;
对普通进程来讲，它都会涉及到5种不同的数据段。&lt;br /&gt;
1．代码段：代码段是用来存放可执行文件的操作指令，也就是说是它是可执行程序在内存种的镜像。代码段需要防止在运行时被非法修改，所以只准许读取操作，而不允许写入操作。&lt;br /&gt;
2．数据段：数据段用来存放可执行文件中已初始化全局变量，就是存放程序静态分配的变量和全局变量。可读可写。&lt;br /&gt;
3．BSS段：包含了程序中未初始化全局变量，在内存中 bss段全部置零。&lt;br /&gt;
4．堆：堆是用于存放进程运行中被动态分配的内存段，它大小并不固定，可动态扩张或缩减。当进程调用malloc等函数分配内存时，新分配的内存就被动态添加到堆上；当利用free等函数释放内存时，被释放的内存从堆中被剔除。&lt;br /&gt;
5. 栈：栈是用户存放程序临时创建的局部变量。除此以外在函数被调用时，其参数也会被压入发起调用的进程栈中，并且待到调用结束后，函数的返回值也回被存放回栈中。由于栈的先进先出特点，所以栈特别方便用来保存/恢复调用现场。从这个意义上将我们可以把堆栈看成一个临时数据寄存、交换的内存区。&lt;br /&gt;
2. 创建进程的地址空间&lt;br /&gt;
内核使用内存描述符struct mm_struct表示进程的地址空间。当创建新的进程时内核调用copy_mm()函数建立新进程的所有页表和内存描述符来创建进程的地址空间：&lt;br /&gt;
static int copy_mm(unsigned long clone_flags, struct task_struct * tsk)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; struct mm_struct * mm, *oldmm;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; oldmm = current-&amp;gt;mm;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (clone_flags &amp;amp; CLONE_VM) {  //线程使用父进程地址空间&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; atomic_inc(&amp;amp;oldmm-&amp;gt;mm_users);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mm = oldmm;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; goto good_mm;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; mm = dup_mm(tsk); //创建子进程地址空间&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
struct mm_struct *dup_mm(struct task_struct *tsk)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; struct mm_struct *mm, *oldmm = current-&amp;gt;mm;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; mm = allocate_mm(); //从slab中分配一个mm_struct&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; memcpy(mm, oldmm, sizeof(*mm));&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; mm_init(mm, tsk); //初始化结构体并为进程创建pgd和pte &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; init_new_context(tsk, mm);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; dup_mm_exe_file(oldmm, mm);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; dup_mmap(mm, oldmm); //创建VMA&lt;br /&gt;
}&lt;br /&gt;
VMA指定地址空间内连续区间上的一个独立内存范围来代表多种类型的内存区域。VMA用struct vm_area_struct描述。&lt;br /&gt;
static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; struct vm_area_struct *mpnt, tmp；&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; struct rb_node **rb_link, rb_parent；&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; //扫描父进程的VMA链表&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; for (mpnt = oldmm-&amp;gt;mmap; mpnt; mpnt = mpnt-&amp;gt;vm_next) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *tmp = *mpnt;  //复制父进程VMA&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //将复制的VMA插入到子进程的VMA链表和红黑树中&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _vma_link_rb(mm, tmp, rb_link, rb_parent);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rb_link = &amp;amp;tmp-&amp;gt;vm_rb.rb_right;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rb_parent = &amp;amp;tmp-&amp;gt;vm_rb;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; } &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*拷贝父进程所有vm_area_struct对应的页目录、页表。将父子进程中私&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 有的、可写的页标记为只读的，以便这种页面能用写时复制机制进行处理&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; copy_page_range(mm, oldmm, mpnt);&lt;br /&gt;
}&lt;br /&gt;
虚拟地址、虚拟地址区域、内存描述符之间关系如图：&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYPKZsiE-v5opQpHWnbn2GpTL9g-GIJ-G4vSRQQuQVjdttpM_0t8HlCwZKA7UcVLuWP08Gc1DdHYUwREVlmqguBekinDWuf3hunrUeJSebQPDyo_u8121tdR-1wdqY3lUUBNX5Swl-YdHU/s1600/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;144&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYPKZsiE-v5opQpHWnbn2GpTL9g-GIJ-G4vSRQQuQVjdttpM_0t8HlCwZKA7UcVLuWP08Gc1DdHYUwREVlmqguBekinDWuf3hunrUeJSebQPDyo_u8121tdR-1wdqY3lUUBNX5Swl-YdHU/s320/1.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;3. 缺页异常处理&lt;br /&gt;
内核中的函数直接获得动态内存，内核是操作系统中优先级最高的成分,可采用kmalloc/vmalloc分配连续和非连续线性区得到内存。&lt;br /&gt;
用户态进程调用malloc分配内存时，请求被认为是不紧迫的，因此，当用户态进程请求动态内存时，并没有立即获得实际的物理页框，而仅仅获得对一个新的VMA。这样，当用户进程真正向这些线性区写的时候，就会产生缺页异常，在缺页异常处理程序do_page_fault()中获得真正的物理内存。&lt;br /&gt;
&lt;br /&gt;
三、 虚拟文件系统&lt;br /&gt;
虚拟文件系统(VFS)是一个内核软件层，用来处理与Unix标准文件系统相关的所有系统调用。它与驱动程序联系的更加紧密。其分层结构如图：&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbMKMmJ2MLsHcUTHWwAZmmC8MmjrkXjccdhyQ_QQ6mR7kTTNO5hL2zbEEF6Df4-WAyFuqBSDrcRCXeC3I821IhniZ4waCggA9rxp92ZiJX-LL0U_QCQMQEXDv0hhU3-Bq8reDuUNve0pl7/s1600/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;185&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbMKMmJ2MLsHcUTHWwAZmmC8MmjrkXjccdhyQ_QQ6mR7kTTNO5hL2zbEEF6Df4-WAyFuqBSDrcRCXeC3I821IhniZ4waCggA9rxp92ZiJX-LL0U_QCQMQEXDv0hhU3-Bq8reDuUNve0pl7/s200/1.png&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;&lt;/div&gt;1. 主要数据结构&lt;br /&gt;
a. 超级块对象结构struct super_block&lt;br /&gt;
该结构保存了一个被安装在linux系统上的文件系统的信息。对于基于磁盘的文件系统，该结构一般和保存在磁盘上的&quot;文件系统控制块&quot;对应。也就是说如果是磁盘文件系统，该结构保存的磁盘文件系统的控制信息。&lt;br /&gt;
b. 索引节点对象结构struct inode&lt;br /&gt;
该结构中存储的是一个特定文件的一般信息，对于一个基于磁盘的文件系统，该结构对应磁盘上的文件数据控制块。每一个inode结构都对应一个inode节点号，这个节点号是唯一的，它也唯一标识一个文件系统中的文件。&lt;br /&gt;
c. 文件对象结构struct file&lt;br /&gt;
该结构中存储的是一个打开的文件和打开这个文件的进程间的交互信息。该结构保存在内核的内存区，在打开文件时被创建，关闭文件时被释放。&lt;br /&gt;
d. 目录项对象结构struct dentry&lt;br /&gt;
该结构存储的是目录实体和对应的文件的关联信息。&lt;br /&gt;
2. 各数据结构之间的关系&lt;br /&gt;
内核创建文件对象并返回文件描述符索引号给用户空间。文件对象引用目录项对象，后者引用索引节点对象。这两个对象都引用超级块对象。多个文件对象可以引用同一个目录项对象。一个目录项对象还可能引用另一个目录项对象。如图：&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBqT_Eleka8_iZX7_1wch6fcQ26lngV0pHboGL7Ad3dkbbMFU73RX8KT_vadB7-k9-JKb_15UdpowylLHJc9YwAX5AuX5giwizSAYVpo2x7tO9C5vpO1WSqOWQbCznRO8pVEfojsxbnNAC/s1600/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBqT_Eleka8_iZX7_1wch6fcQ26lngV0pHboGL7Ad3dkbbMFU73RX8KT_vadB7-k9-JKb_15UdpowylLHJc9YwAX5AuX5giwizSAYVpo2x7tO9C5vpO1WSqOWQbCznRO8pVEfojsxbnNAC/s1600/1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chennrui.blogspot.com/feeds/1557368281081172335/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://chennrui.blogspot.com/2011/07/study-kernel3-memoryvfs.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/1557368281081172335'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/1557368281081172335'/><link rel='alternate' type='text/html' href='http://chennrui.blogspot.com/2011/07/study-kernel3-memoryvfs.html' title='study kernel(3) -- memory,vfs'/><author><name>big bang</name><uri>http://www.blogger.com/profile/07380722230385048574</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQEwGR3hniNIaoAuRxuoFMsyO_esdj85N9t60Bj4qln24_y7qj8mnx8taxn-KrBbc2zQBfJviUXvScqSs7OD3zJBpP5wimbihfo-Y9yHnpYezKHlkxxt5YRkQ2wyrFDA/s220/linux-logo.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSnU0KhpTFRD_aDP38XvMNzfax-U1jwUpY3GoJ97zrUdSzAUBw4p8IzgWOPoksXVL_sx0cVUzbahBIG9DZt3l57rsI46RJff8u5NKgzX7NMXflT3i6bxvSI1xEr8GUwFoto76_g_p5kKKO/s72-c/1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7128755548240021396.post-4444437422663533696</id><published>2011-07-24T14:33:00.001+08:00</published><updated>2011-07-24T14:33:32.245+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="kernel"/><title type='text'>study kernel(2) -- sync, interrupt</title><content type='html'>三、 内核同步&lt;br /&gt;
1. 原子操作&lt;br /&gt;
linux提供了一系列C语言函数来实现内核中的原子操作，这些函数又分为两类，分别针对bit变量和整数变量进行原子操作。它们的共同点是在任何情况下都是原子的，内核代码可以安全的调用它们而不被中断，而且它们都依赖底层CPU的原子操作来实现-所有这些函数都是CPU架构相关的。其实现在atomic.h和bitops.h中&lt;br /&gt;
2. 禁止中断&lt;br /&gt;
CPU具备屏蔽中断和打开中断的功能，这项功能可以保证正在执行的内核控制路径不被中断处理程序所抢占，防止某些竞争条件的发生。Linux提供了local_irq_disable()/local_irq_enable()，local_irq_save()/local_irq_restone()来实现屏蔽/开启中断的功能。 &lt;br /&gt;
另外，内核提供的另外一些函数隐含的调用了屏蔽中断的功能，如spin_lock_irq()。中断机制对于内核的正常运行是非常重要的，因为异步I/O，进程调度等很多重要操作都依赖于中断，而在屏蔽中断期间所有的中断都无法得到处理，而必须延迟到解除屏蔽以后。所以长时间的屏蔽中断是很危险的，有可能造成数据丢失乃至系统崩溃等后果。这就要求在屏蔽了中断之后，当前的内核控制路径应当尽快的执行完临界区的代码，然后解除对中断的屏蔽。尤其需要注意的是，屏蔽中断后的内核控制路径不能调用有可能引起阻塞的函数，因为这些函数会使进程睡眠，然后主动调用schedule()来放弃CPU。&lt;br /&gt;
3. 自旋锁&lt;br /&gt;
自旋锁在试图加锁的时候，如果当前锁已经处于锁定状态，加锁进程就进行&quot;旋转&quot;，用一个死循环测试锁的状态，直到成功的取得锁。自旋锁的这种特性避免了调用进程的挂起，用&quot;旋转&quot;来取代进程切换。而上下文切换需要一定时间，并且会使高速缓冲失效，对系统性能影响是很大的，所以自旋锁在多处理器环境中非常方便。当然，被自旋锁所保护的&quot;临界代码&quot;一般都比较短，否则就会浪费过多的CPU资源。 &lt;br /&gt;
当一个内核控制路径与中断处理程序之间存在竞争条件时，需要使用中断安全版本的自旋锁spin_lock_irq()/spin_lock_irqsave()，这个函数首先禁止本地CPU上的中断，然后试图获得自旋锁，这样在执行临界区代码的时候，本地CPU不会被中断处理程序所抢占。同时，由于禁止的只是本地CPU上的中断，系统中其它CPU仍然可以对外部中断进程处理。 &lt;br /&gt;
自旋锁是互斥的，同一时刻只能有一个内核控制路径拥有自旋锁。&lt;br /&gt;
4. 信号量&lt;br /&gt;
信号量为了解决多个内核控制路径竞争资源的问题，这些内核控制路径可能是单处理器系统中分时执行的控制路径，也可能是多处理器系统中的并行执行的控制路径。在试图获得信号量的时候，如果信号量繁忙，相应的内核控制路径会挂起，直到信号量被释放的时候控制路径才恢复运行。使用信号量的时候，先声明一个semaphore类型的对象，然后调用函数sema_init()来初始化它。要想获得信号量的掌握权，需要调用函数down_interruptible()/down()，此时如果信号量忙，调用进程被挂起，加入到信号量的等待队列中去；释放信号量的时候则调用up()函数，系统同时会唤醒正在等待信号量的进程，唤醒的顺序与等待的顺序是一致的。&lt;br /&gt;
注：中断上下文只能用自旋锁，而任务睡眠时只能使用信号量。&lt;br /&gt;
四、 中断&lt;br /&gt;
中断由硬件设备生成，再由中断控制器向处理器发送相应信号。处理器检测到此信号，便中断自己的当前工作转而处理中断。此后处理器会通知系统已经产生中断，操作系统就可以对这个中断进行适当的处理。&lt;br /&gt;
IRQs(Interrupt ReQuests)：外设引起的中断应该被称为中断请求。中断请求号和中断号中间有一定的映射关系。这个映射关系和平台有关。&lt;br /&gt;
1. 中断处理的层次&lt;br /&gt;
中断的嵌套会带来很多问题，在中断处理函数重屏蔽其他中断源可以解决防止中断嵌套，但是长时间地屏蔽中断会导致内核遗漏掉一些重要的中断。 因此，中断处理函数重中断的屏蔽时间应该越短越好。&lt;br /&gt;
中断处理函数应满足下面两个要求：&lt;br /&gt;
a. 代码量应越少越好，以便中断函数的快速执行。 &lt;br /&gt;
b. 如果中断处理函数也可以并发，那么他们之间不得互相影响。 &lt;br /&gt;
上述两个条件中，后者可以通过优化中断处理函数的设计和编码来实现，但想实现前者，则不那么容易。 但实际上，并非中断处理程序的所有工作的重要性都是相同的，通常来讲，一个中断服务程序可根据其是否需要马上处理而分为三个部分：&lt;br /&gt;
Critical actions:&lt;br /&gt;
这个部分必须要在中断发上后马上执行，否则将无法保证系统的稳定性或者数据操作的正确性。 例如，当网卡上有数据包到达后，内核必须马上将数据从网卡挪到内存中，如果这个动作没有在中断发生后马上执行，该数据可能会被后续接收到的数据覆盖。 在进行这个 critical actions 的时候，其他的中断必须被关掉。 &lt;br /&gt;
Noncritical actions:&lt;br /&gt;
这些actions相比前面的critical actions重要性稍低，但是也应该尽快完成。 不同的是，它可以在打开其他中断的前提下进行，因此可能会被其他的中断所&quot;中断&quot;(受其他的中断影响)。 &lt;br /&gt;
Deferrable actions:&lt;br /&gt;
Deferrable actions 的重要性比前两者都低，可以不用放在中断处理函数中进行。内核可以等到没什么事情的时候再处理它。 &lt;br /&gt;
对中断处理函数的划分，并根据各个部分的不同的重要性，可以将中断函数拆成若干不同的片段，放在不同的上下文中执行， 很大程度上，在保证了系统事件完整性的前提下，防止了中断的嵌套。&lt;br /&gt;
2. 中断上半部&lt;br /&gt;
a) 中断的处理&lt;br /&gt;
struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = {&lt;br /&gt;
[0 ... NR_IRQS-1] = {&lt;br /&gt;
.handle_irq = handle_bad_irq,&lt;br /&gt;
.depth  = 1,&lt;br /&gt;
.lock  = __RAW_SPIN_LOCK_UNLOCKED(irq_desc-&amp;gt;lock),&lt;br /&gt;
}&lt;br /&gt;
};&lt;br /&gt;
中断处理函数do_IRQ()根据中断号被存放到irq_desc数组中；从irq_desc中，可以依据中断号，找到相应的中断处理程序。&lt;br /&gt;
struct irq_desc用于描述一个IRQ，其中：&lt;br /&gt;
handler_data: 指向一些与IRQ处理函数相关的数据。当中断发生时，handle_irq被调用。&lt;br /&gt;
action: 这个数据结构提供了当中断发生后需要执行的中断处理程序。&lt;br /&gt;
b) 中断处理程序的注册&lt;br /&gt;
static inline int __must_checkrequest_irq (unsigned int irq, irq_handler_t handler, &lt;br /&gt;
unsigned long flags, const char *name, void *dev)&lt;br /&gt;
{&lt;br /&gt;
return request_threaded_irq(irq, handler, NULL, flags, name, dev);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
request_threaded_irq首先从内核中获取了这个irq对应的irq_desc，然后创建结构体irqaction，设置action的handler, flags, name, dev_id。然后调用__setup_irq完成后续工作。&lt;br /&gt;
Flags标志：&lt;br /&gt;
SA_INTERRUPT：执行中断处理程序时屏蔽所有中断线。而默认没有这个标志时，除了正在运行的中断处理程序对应的中断线被屏蔽外，其他所有中断都是激活的。&lt;br /&gt;
SA_SAMPLE_RANDOM: 内核通过一系列的事件的相关信息来生成随机数,如果有这个标志，则调用rand_initialize_irq将IRQ添加到熵池所需的相关数据结构中。&lt;br /&gt;
SA_SHIRQ：可以在多个中断处理程序之间共享中断线。&lt;br /&gt;
3. 中断下半部&lt;br /&gt;
下半部的任务就是执行于中断处理密切相关但中断处理程序本身不执行的工作。提供如下几种机制：&lt;br /&gt;
c) 软中断&lt;br /&gt;
i. 注册软中断处理程序&lt;br /&gt;
软中断项：&lt;br /&gt;
struct softirq_action{&lt;br /&gt;
void (*action) (struct softirq_action *); //软中断处理程序&lt;br /&gt;
void *data;&lt;br /&gt;
}&lt;br /&gt;
软中断向量表：&lt;br /&gt;
static struct softirq_action softirq_vec[NR_SOFTIRQS];&lt;br /&gt;
函数open_softirq()通过软中断索引号注册软中断处理函数&lt;br /&gt;
&lt;br /&gt;
ii. 触发/禁止软中断&lt;br /&gt;
函数raise_softirq()/raise_softirq_irqoff()通过软中断索引号修改软中断状态寄存器irq_stat&lt;br /&gt;
&lt;br /&gt;
iii. 软中断守护线程函数do_softirq()核心部分代码：&lt;br /&gt;
void do_softirq(void){&lt;br /&gt;
struct softirq_action *h;&lt;br /&gt;
__u32 pending;&lt;br /&gt;
&lt;br /&gt;
if (in_interrupt())  //处于中断上下文则返回&lt;br /&gt;
return;&lt;br /&gt;
&lt;br /&gt;
pending = local_softirq_pending(); //查询软中断状态寄存器irq_stat判断事件是否发生&lt;br /&gt;
set_softirq_pending(0);&lt;br /&gt;
h = softirq_vec;   //软中断向量表&lt;br /&gt;
do{&lt;br /&gt;
if (pending &amp;amp; 1)  //事件发生则执行软中断处理程序 &lt;br /&gt;
h-&amp;gt;action(h);&lt;br /&gt;
h++;&lt;br /&gt;
pending &amp;gt;&amp;gt;= 1;&lt;br /&gt;
}while (pending);&lt;br /&gt;
}&lt;br /&gt;
d) tasklet&lt;br /&gt;
Tasklet为一个软中断，考虑到优先级问题，分别占用了软中断向量表中的0号和5号软中断。&lt;br /&gt;
i. 创建tasklet&lt;br /&gt;
struct tasklet_struct&lt;br /&gt;
{&lt;br /&gt;
struct tasklet_struct *next;&lt;br /&gt;
unsigned long state;&lt;br /&gt;
atomic_t count;&lt;br /&gt;
void (*func)(unsigned long);&lt;br /&gt;
unsigned long data;&lt;br /&gt;
};&lt;br /&gt;
调用DELCARE_TASKLET创建struct tasklet_struct结构体并注册tasklet处理程序。&lt;br /&gt;
调用tasklet_schedule()/tasklet_hi_schedule()将struct tasklet_struct加入tasklet向量表tasklet_vec/tasklet_hi_vec。&lt;br /&gt;
ii. tasklet注册软中断处理程序&lt;br /&gt;
在softirq_init()中调用注册tasklet软中断处理函数tasklet_action()/tasklet_hi_action()&lt;br /&gt;
static void tasklet_action(struct softirq_action *a){&lt;br /&gt;
struct tasklet_struct *list;&lt;br /&gt;
&lt;br /&gt;
list = __this_cpu_read(tasklet_vec.head); //读取tasklet向量表&lt;br /&gt;
&lt;br /&gt;
while (list) {&lt;br /&gt;
struct tasklet_struct *t = list;&lt;br /&gt;
list = list-&amp;gt;next;&lt;br /&gt;
if (!atomic_read(&amp;amp;t-&amp;gt;count)) &lt;br /&gt;
t-&amp;gt;func(t-&amp;gt;data);  //如果count为0则执行tasklet处理程序。&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
e) 软中断与tasklet的区别&lt;br /&gt;
软中断必须确保共享数据的安全，因为两个甚至更多相同类别的软中断有可能在不同的处理器上同步执行。而两个同类型的tasklet不能同时执行。</content><link rel='replies' type='application/atom+xml' href='http://chennrui.blogspot.com/feeds/4444437422663533696/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://chennrui.blogspot.com/2011/07/study-kernel2-sync-interrupt.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/4444437422663533696'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/4444437422663533696'/><link rel='alternate' type='text/html' href='http://chennrui.blogspot.com/2011/07/study-kernel2-sync-interrupt.html' title='study kernel(2) -- sync, interrupt'/><author><name>big bang</name><uri>http://www.blogger.com/profile/07380722230385048574</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQEwGR3hniNIaoAuRxuoFMsyO_esdj85N9t60Bj4qln24_y7qj8mnx8taxn-KrBbc2zQBfJviUXvScqSs7OD3zJBpP5wimbihfo-Y9yHnpYezKHlkxxt5YRkQ2wyrFDA/s220/linux-logo.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7128755548240021396.post-5983962703755003402</id><published>2011-07-24T14:33:00.000+08:00</published><updated>2011-07-24T14:33:10.477+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="kernel"/><title type='text'>study kernel(1) -- process, schedule</title><content type='html'>一、 进程&lt;br /&gt;
1. 进程描述符&lt;br /&gt;
内核用进程描述符task_struct表示用户空间中进程的所有信息。&lt;br /&gt;
task_struct 定义如下： &lt;br /&gt;
struct task_struct {&lt;br /&gt;
volatile long state;  //进程运行状态&lt;br /&gt;
struct thread_info;  //线程描述符&lt;br /&gt;
struct mm_struct;  //描述内存存储信息&lt;br /&gt;
struct tty_struct;  //与进程相关的tty&lt;br /&gt;
struct fs_struct;  //当前目录&lt;br /&gt;
struct signal_struct;  //所接收的信号&lt;br /&gt;
......&lt;br /&gt;
};&lt;br /&gt;
其中，state用于表示进程当前的运行状态进程状态：&lt;br /&gt;
1． TASK_RUNNING：进程正在执行或是可执行的，调度器可将其加入运行队列(runqueue)。&lt;br /&gt;
2． TASK_INTERRUPTIBLE/TASK_UNINTERRUPTIBLE：进程由于某些原因（通常是状态不满足）而被阻塞，当条件满足后，则会重新变成TASK_RUNNING。不同的是， TASK_INTERRUPTIBLE，可以响应内核发出的信号；而TASK_UNITERRUPTIBLE不响应内核发出的信号。&lt;br /&gt;
3． EXIT_ZOMBIE：进程已经结束，但此时任占用内核栈、thread_info、task_struct，为了向父进程提供信息。当父进程调用了wait4()后，信息会被释放。&lt;br /&gt;
4． __TASK_STOPPED：进程停止运行。&lt;br /&gt;
2. 创建进程&lt;br /&gt;
fork()系统调用的功能是为当前进程创建一子进程。调用此函数时，系统将调用宏指令_syscall0，并做最终调用内核接口sys_fork()。&lt;br /&gt;
asmlinkage int sys_fork(struct pt_regs regs)&lt;br /&gt;
{&lt;br /&gt;
return do_fork(SIGCHLD, regs.esp, ®s, 0, NULL, NULL);&lt;br /&gt;
}&lt;br /&gt;
SIGCHLD是在定义的一个宏，它告诉do_fork()函数应创建一个子进程，即创建并初始化进程描述符task_struct以及他包含的其他结构。&lt;br /&gt;
3. 创建内核线程&lt;br /&gt;
Linux内核可以看作一个服务进程。内核需要多个执行流并行，为了防止可能的阻塞，多线程化是必要的。内核线程的调度由内核负责，一个内核线程处于阻塞状态时不影响其他的内核线程，因为其是调度的基本单位。&lt;br /&gt;
内核线程是由kernel_thread()函数在内核态下创建的:&lt;br /&gt;
int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)&lt;br /&gt;
{&lt;br /&gt;
struct pt_regs regs;&lt;br /&gt;
memset(®s, 0, sizeof(regs));&lt;br /&gt;
......&lt;br /&gt;
/* Ok, create the new process.. */&lt;br /&gt;
return do_fork(flags|CLONE_VM|CLONE_UNTRACED, 0, ®s, 0, NULL, NULL);&lt;br /&gt;
}&lt;br /&gt;
内核线程的创建本质上也是建立了一个task_struct。其中CLONE_VM标志表示，避免复制进程的页表。内核线程和调用的进程(current)具备相同的进程空间，因为调用者运行在进程的内核态，所以进程在内核态时共享内核空间。&lt;br /&gt;
&lt;br /&gt;
二、 进程调度&lt;br /&gt;
4. 进程调度类型&lt;br /&gt;
Linux进程按照下面调度类型被调度：&lt;br /&gt;
SCHED_FIFO：先进先出的实时进程。如果没有其他可运行的更高优先级实时进程，该进程将一直占用CPU。&lt;br /&gt;
SCHED_RR：时间片轮转的实时进程。所有具有相同优先级的SCHED_RR实时进程公平分配CPU时间。&lt;br /&gt;
SCHED_NORMAL：普通的分时进程。&lt;br /&gt;
5. 普通进程调度&lt;br /&gt;
普通进程通过静态优先级nice值决定进程的基本时间片，nice值越小，静态优先级越高，进程获得的CPU时间更长。同时以nice值为基础并通过检查进程过去的情况设置优先级，既动态优先级。调度程序总是选择动态优先级高的进程投入运行。&lt;br /&gt;
Linux基于以动态优先级为基础的调度算法。内核为每个进程设置一个基本的优先级，但它允许调度程序根据需要来加减优先级，然后挑选优先级最高的进程投入运行。当进程时间片用完重新分配时间时，也会根据优先级值动态分配时间。&lt;br /&gt;
6. 实时进程调度&lt;br /&gt;
实时算法实现都是静态优先级，而不会设置动态优先级。这能保证优先级高的实时进程总能抢占优先级低的进程。&lt;br /&gt;
7. 更新时间片scheduler_tick()&lt;br /&gt;
void scheduler_tick(void)&lt;br /&gt;
{&lt;br /&gt;
struct task_struct *p = current;&lt;br /&gt;
&lt;br /&gt;
if (p-&amp;gt;array != rq-&amp;gt;active) { //如果current-&amp;gt;array没有指向runqueue，说&lt;br /&gt;
set_tsk_need_resched(p);          明进程已经过期但未被替换，则设置&lt;br /&gt;
goto out;                        need_resched字段以进行重新调度&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* current为SCHED_FIFO，进程不会被低优先级进程抢占，因此不更新时间片。&lt;br /&gt;
current为SCHED_RR，时间片将递减。若时间片用完，则重新计算时间片，设置need_resched字段，将进程加入runqueue尾部。&lt;br /&gt;
*/&lt;br /&gt;
if (rt_task(p)) {     &lt;br /&gt;
if ((p-&amp;gt;policy == SCHED_RR) &amp;amp;&amp;amp; !--p-&amp;gt;time_slice) {&lt;br /&gt;
p-&amp;gt;time_slice = task_timeslice(p);   //根据静态优先级计算时间片&lt;br /&gt;
set_tsk_need_resched(p);&lt;br /&gt;
requeue_task(p, rq-&amp;gt;active);&lt;br /&gt;
}&lt;br /&gt;
goto out_unlock;&lt;br /&gt;
}&lt;br /&gt;
/* 更新普通进程时间片。若时间片用完，设置need_resched字段，根据动态优先级设置进程优先级，根据静态优先级设置时间片。若时间片未用完，则检查进程是否可继续占用CPU。&lt;br /&gt;
*/&lt;br /&gt;
if (!--p-&amp;gt;time_slice) {&lt;br /&gt;
set_tsk_need_resched(p);&lt;br /&gt;
p-&amp;gt;prio = effective_prio(p);&lt;br /&gt;
p-&amp;gt;time_slice = task_timeslice(p);&lt;br /&gt;
} else {&lt;br /&gt;
......&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
8. 调度程序schedule()&lt;br /&gt;
调用schedule()函数分为直接调用和延迟调用。如果current进程因不能获得必要的资源要立即被阻塞，就直接调用schedule()；也可通过设置current的need_resched字段被设置，以延迟方式调用schedule()。由于总是在恢复用户态进程的执行前检查这个标志，所有schedule()将在不久之后的某个时间被调用。&lt;br /&gt;
asmlinkage void __sched schedule(void)&lt;br /&gt;
{&lt;br /&gt;
struct task_struct *prev, *next;&lt;br /&gt;
struct list_head *queue;&lt;br /&gt;
struct prio_array *array;&lt;br /&gt;
int idx;&lt;br /&gt;
struct rq *rq;&lt;br /&gt;
……&lt;br /&gt;
……&lt;br /&gt;
prev = current;&lt;br /&gt;
array = rq-&amp;gt;active;  //获取活动优先级队列&lt;br /&gt;
idx = sched_find_first_bit(array-&amp;gt;bitmap);   //通过优先级位图快速查找进程&lt;br /&gt;
queue = array-&amp;gt;queue + idx;&lt;br /&gt;
next = list_entry(queue-&amp;gt;next, struct task_struct, run_list); //返回进程描述符&lt;br /&gt;
if(prev != next)&lt;br /&gt;
context_switch();  //如果选中的进程不是当前进程则进行上下文切换&lt;br /&gt;
}&lt;br /&gt;
9. 用户抢占&lt;br /&gt;
内核即将返回用户空间时，如果need_resched标志被设置，会导致schedule()被调用，发生用户抢占。&lt;br /&gt;
10. 内核抢占&lt;br /&gt;
thread_info引入了preempt_count计数器。该计数器初始值为0，每当使用锁的 时候数值加1，释放锁的时候数值减1。当数值为0的时候，内核就可执行抢占。从中断返回内核空间的时候，内核会检查need_resched和preempt_count的值。如果need_resched被设置，并且preempt_count为0的话，这说明有一个更为重要的任务需要执行并且可以安全地抢占，此时调度程序就会调度(抢占当前进程)。如果preempt_count不为0，说明当前 任务持有锁，所以抢占是不安全的。这时，就会像通常那样直接从中断返回当前执行进程。 如果当前进程所持有的所有的锁都被释放了。那么preempt_count就会重新为0。此时，释放锁的代码会检查need_resched是否被设置。如果是的话，就会调用调度程序。</content><link rel='replies' type='application/atom+xml' href='http://chennrui.blogspot.com/feeds/5983962703755003402/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://chennrui.blogspot.com/2011/07/study-kernel1-process-schedule.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/5983962703755003402'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/5983962703755003402'/><link rel='alternate' type='text/html' href='http://chennrui.blogspot.com/2011/07/study-kernel1-process-schedule.html' title='study kernel(1) -- process, schedule'/><author><name>big bang</name><uri>http://www.blogger.com/profile/07380722230385048574</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQEwGR3hniNIaoAuRxuoFMsyO_esdj85N9t60Bj4qln24_y7qj8mnx8taxn-KrBbc2zQBfJviUXvScqSs7OD3zJBpP5wimbihfo-Y9yHnpYezKHlkxxt5YRkQ2wyrFDA/s220/linux-logo.png'/></author><thr:total>0</thr:total><georss:featurename>位置未知</georss:featurename><georss:point>nan nan</georss:point></entry><entry><id>tag:blogger.com,1999:blog-7128755548240021396.post-5386723690529705511</id><published>2011-05-19T22:29:00.000+08:00</published><updated>2011-05-19T22:29:26.109+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="linuxprogram"/><title type='text'>container_of()</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #110000; font-size: 12px;&quot;&gt;&lt;table class=&quot;highlighttable&quot; style=&quot;border-collapse: collapse; width: 1333px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;linenos&quot; style=&quot;background-color: #ddeeff; border-right-color: rgb(221, 221, 221); border-right-style: solid; border-right-width: 1px; color: grey; overflow-x: visible; overflow-y: visible; padding-bottom: 2px; padding-left: 2px; padding-right: 2px; padding-top: 2px; text-align: right; vertical-align: top; width: 18px;&quot;&gt;&lt;pre style=&quot;clear: none; float: none; line-height: 1.333; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: visible; overflow-y: visible; width: auto;&quot;&gt;1
 2
 3
 4
&lt;span class=&quot;special&quot; style=&quot;color: #f810b0;&quot;&gt; 5&lt;/span&gt;
 6
 7
 8
 9
&lt;span class=&quot;special&quot; style=&quot;color: #f810b0;&quot;&gt;10&lt;/span&gt;
11
12
13
14
&lt;span class=&quot;special&quot; style=&quot;color: #f810b0;&quot;&gt;15&lt;/span&gt;
16
17
18
19
&lt;span class=&quot;special&quot; style=&quot;color: #f810b0;&quot;&gt;20&lt;/span&gt;
21
22
23
24
&lt;span class=&quot;special&quot; style=&quot;color: #f810b0;&quot;&gt;25&lt;/span&gt;
26
27
28
29
&lt;span class=&quot;special&quot; style=&quot;color: #f810b0;&quot;&gt;30&lt;/span&gt;
31
32
33
34
&lt;span class=&quot;special&quot; style=&quot;color: #f810b0;&quot;&gt;35&lt;/span&gt;
36
37
38
39
&lt;span class=&quot;special&quot; style=&quot;color: #f810b0;&quot;&gt;40&lt;/span&gt;
41
42
43
44
&lt;span class=&quot;special&quot; style=&quot;color: #f810b0;&quot;&gt;45&lt;/span&gt;
46&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot; style=&quot;padding-bottom: 2px; padding-left: 2px; padding-right: 2px; padding-top: 2px; vertical-align: top;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: #f8f8f8; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; padding-bottom: 2px; padding-left: 2px; padding-right: 2px; padding-top: 2px; vertical-align: top;&quot;&gt;&lt;pre style=&quot;clear: none; float: none; line-height: 1.333; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: visible; overflow-y: visible; width: auto;&quot;&gt;&lt;span style=&quot;color: #bc7a00;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;

&lt;span style=&quot;color: #408080; font-style: italic;&quot;&gt;/*&lt;/span&gt;
&lt;span style=&quot;color: #408080; font-style: italic;&quot;&gt;    #define container_of(ptr, type, member) ({             \&lt;/span&gt;
&lt;span style=&quot;color: #408080; font-style: italic;&quot;&gt;                 const typeof( ((type *)0)-&amp;gt;member ) *__mptr = (ptr);     \&lt;/span&gt;
&lt;span style=&quot;color: #408080; font-style: italic;&quot;&gt;                 (type *)( (char *)__mptr - offsetof(type,member) );})&lt;/span&gt;


&lt;span style=&quot;color: #408080; font-style: italic;&quot;&gt;    #define offsetof(TYPE, MEMBER) ((size_t) &amp;amp;((TYPE *)0)-&amp;gt;MEMBER)&lt;/span&gt;
&lt;span style=&quot;color: #408080; font-style: italic;&quot;&gt;*/&lt;/span&gt;



&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;struct&lt;/span&gt; test {
    &lt;span style=&quot;color: #b00040;&quot;&gt;int&lt;/span&gt; a;
    &lt;span style=&quot;color: #b00040;&quot;&gt;char&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;*&lt;/span&gt;b;
};

&lt;span style=&quot;color: #b00040;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;main&lt;/span&gt;(&lt;span style=&quot;color: #b00040;&quot;&gt;int&lt;/span&gt; argc, &lt;span style=&quot;color: #b00040;&quot;&gt;char&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;*&lt;/span&gt;argv[])
{&lt;/pre&gt;&lt;pre style=&quot;clear: none; float: none; line-height: 1.333; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: visible; overflow-y: visible; width: auto;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;; line-height: normal; white-space: normal;&quot;&gt;&lt;pre style=&quot;clear: none; line-height: 1.333; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: visible; overflow-y: visible; width: auto;&quot;&gt;&lt;span style=&quot;color: #408080; font-style: italic;&quot;&gt;    //通过struct test成员b返回struct的入口地址&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;    &lt;span style=&quot;color: #408080; font-style: italic;&quot;&gt;//container_of(&amp;amp;tmp.b, (struct test), b);&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;clear: none; float: none; line-height: 1.333; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: visible; overflow-y: visible; width: auto;&quot;&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;clear: none; float: none; line-height: 1.333; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: visible; overflow-y: visible; width: auto;&quot;&gt;&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;    struct&lt;/span&gt; test tmp;
    &lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;struct&lt;/span&gt; test &lt;span style=&quot;color: #666666;&quot;&gt;*&lt;/span&gt;ptmp;
    &lt;span style=&quot;color: #b00040;&quot;&gt;int&lt;/span&gt; offset;
    tmp.a &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;10&lt;/span&gt;;

    printf(&lt;span style=&quot;color: #ba2121;&quot;&gt;&quot;&amp;amp;tmp.a = %02x, &amp;amp;tmp.b = %02x&lt;/span&gt;&lt;span style=&quot;color: #bb6622; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color: #ba2121;&quot;&gt;&quot;&lt;/span&gt;, &lt;span style=&quot;color: #666666;&quot;&gt;&amp;amp;&lt;/span&gt;tmp.a, &lt;span style=&quot;color: #666666;&quot;&gt;&amp;amp;&lt;/span&gt;tmp.b);

    &lt;span style=&quot;color: #408080; font-style: italic;&quot;&gt;//定义一个 _mptr指针， 类型为struct test结构体中b成员的类型&lt;/span&gt;
    &lt;span style=&quot;color: #408080; font-style: italic;&quot;&gt;//typeof 为获取（（（struct test＊）0）-&amp;gt;b)的类型，此处此类型为char*&lt;/span&gt;
    &lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;const&lt;/span&gt; typeof(((&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;struct&lt;/span&gt; test &lt;span style=&quot;color: #666666;&quot;&gt;*&lt;/span&gt;)&lt;span style=&quot;color: #666666;&quot;&gt;0&lt;/span&gt;)&lt;span style=&quot;color: #666666;&quot;&gt;-&amp;gt;&lt;/span&gt;b) &lt;span style=&quot;color: #666666;&quot;&gt;*&lt;/span&gt;_mptr &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;&amp;amp;&lt;/span&gt;tmp.b;
    printf(&lt;span style=&quot;color: #ba2121;&quot;&gt;&quot;_mptr = %02x&lt;/span&gt;&lt;span style=&quot;color: #bb6622; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color: #ba2121;&quot;&gt;&quot;&lt;/span&gt;, _mptr);


    &lt;span style=&quot;color: #408080; font-style: italic;&quot;&gt;//#define offsetof(TYPE, MEMBER) ((size_t) &amp;amp;((TYPE *)0)-&amp;gt;MEMBER)&lt;/span&gt;
    &lt;span style=&quot;color: #408080; font-style: italic;&quot;&gt;//TYPE是某struct的类型 0是一个假想TYPE类型struct,MEMBER是该struct中的一个成员.&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;clear: none; float: none; line-height: 1.333; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: visible; overflow-y: visible; width: auto;&quot;&gt;&lt;span style=&quot;color: #408080; font-style: italic;&quot;&gt;    //由于该struct的基地址为0, MEMBER的地址就是该成员相对与struct头地址的偏移量.&lt;/span&gt;
    offset &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; (&lt;span style=&quot;color: #b00040;&quot;&gt;int&lt;/span&gt;)(&lt;span style=&quot;color: #666666;&quot;&gt;&amp;amp;&lt;/span&gt;((&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;struct&lt;/span&gt; test &lt;span style=&quot;color: #666666;&quot;&gt;*&lt;/span&gt;)&lt;span style=&quot;color: #666666;&quot;&gt;0&lt;/span&gt;)&lt;span style=&quot;color: #666666;&quot;&gt;-&amp;gt;&lt;/span&gt;b);
    printf(&lt;span style=&quot;color: #ba2121;&quot;&gt;&quot;offset = %d&lt;/span&gt;&lt;span style=&quot;color: #bb6622; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color: #ba2121;&quot;&gt;&quot;&lt;/span&gt;, offset);

    &lt;span style=&quot;color: #408080; font-style: italic;&quot;&gt;//_mptr的地址减去MEMBER在该struct中的偏移量得到的地址, 再转换成type型指针. 该指针就是struct的入口地址了.&lt;/span&gt;
    ptmp &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; (&lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;struct&lt;/span&gt; test &lt;span style=&quot;color: #666666;&quot;&gt;*&lt;/span&gt;)((&lt;span style=&quot;color: #b00040;&quot;&gt;char&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;*&lt;/span&gt;)_mptr &lt;span style=&quot;color: #666666;&quot;&gt;-&lt;/span&gt; offset);
    
    printf(&lt;span style=&quot;color: #ba2121;&quot;&gt;&quot;tmp = %02x, ptmp = %02x&lt;/span&gt;&lt;span style=&quot;color: #bb6622; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color: #ba2121;&quot;&gt;&quot;&lt;/span&gt;, &lt;span style=&quot;color: #666666;&quot;&gt;&amp;amp;&lt;/span&gt;tmp, ptmp);
    printf(&lt;span style=&quot;color: #ba2121;&quot;&gt;&quot;ptmp-&amp;gt;a = %d&lt;/span&gt;&lt;span style=&quot;color: #bb6622; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color: #ba2121;&quot;&gt;&quot;&lt;/span&gt;, ptmp&lt;span style=&quot;color: #666666;&quot;&gt;-&amp;gt;&lt;/span&gt;a);
    &lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;0&lt;/span&gt;;
}&lt;/pre&gt;&lt;pre style=&quot;clear: none; float: none; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: visible; overflow-y: visible; width: auto;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 17px;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;clear: none; float: none; line-height: 1.333; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: visible; overflow-y: visible; width: auto;&quot;&gt;输出结果：&lt;/pre&gt;&lt;pre style=&quot;clear: none; float: none; line-height: 1.333; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: visible; overflow-y: visible; width: auto;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;; line-height: normal; white-space: normal;&quot;&gt;&lt;pre style=&quot;clear: none; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: visible; overflow-y: visible; width: auto;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 17px;&quot;&gt;$ ./a.out &lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;clear: none; float: none; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: visible; overflow-y: visible; width: auto;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 17px;&quot;&gt;&amp;amp;tmp.a = bfffe6a0, &amp;amp;tmp.b = bfffe6a4
_mptr = bfffe6a4
offset = 4
tmp = bfffe6a0, ptmp = bfffe6a0
ptmp-&amp;gt;a = 10&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://chennrui.blogspot.com/feeds/5386723690529705511/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://chennrui.blogspot.com/2011/05/containerof.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/5386723690529705511'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/5386723690529705511'/><link rel='alternate' type='text/html' href='http://chennrui.blogspot.com/2011/05/containerof.html' title='container_of()'/><author><name>big bang</name><uri>http://www.blogger.com/profile/07380722230385048574</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQEwGR3hniNIaoAuRxuoFMsyO_esdj85N9t60Bj4qln24_y7qj8mnx8taxn-KrBbc2zQBfJviUXvScqSs7OD3zJBpP5wimbihfo-Y9yHnpYezKHlkxxt5YRkQ2wyrFDA/s220/linux-logo.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7128755548240021396.post-7287231180774922557</id><published>2011-05-14T20:21:00.000+08:00</published><updated>2011-05-14T20:21:30.075+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="iptables"/><title type='text'>iptables command and rules</title><content type='html'>&lt;code&gt;$ iptables  [-t table] command [match] [target]&lt;/code&gt;        &lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;div&gt;&lt;code&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;iptables有5个链：PREROUTING，INPUT，FORWARD，OUTPUT，POSTROUTING；4个表：filter,nat,magle,raw.&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div&gt;&lt;code&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;4个表的优先级由高到低为：raw-&amp;gt;mangle-&amp;gt;nat-&amp;gt;filter.&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;code&gt;[-t table]&lt;/code&gt; 选项允许使用标准表之外的任何表。表是包含仅处理特定类型信息包的规则和链的信息包过滤表。该选项不是必需的，如果未指定， 则          &lt;code&gt;filter&lt;/code&gt; 用作缺省表。       &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;span class=&quot;text_import1&quot;&gt;filter&lt;/span&gt;：表用于一般的信息包过滤。包括链表：&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;span class=&quot;text_import2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; INPUT&lt;/span&gt;：主要与想要进入本机的封包有关；&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;span class=&quot;text_import2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; OUTPUT&lt;/span&gt;：主要与本机所要送出的封包有关；&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;span class=&quot;text_import2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FORWARD&lt;/span&gt;： 用于转发，与nat table 相关性较高。&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;span class=&quot;text_import1&quot;&gt;nat&lt;/span&gt;：主要在进行来源与目的之 IP 或 port 的转换，与 Linux 本机较无关，主要与 Linux    主机后的区域网路内电脑较有相关。包括链表：&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;span class=&quot;text_import2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PREROUTING&lt;/span&gt;：在进行路由判断之前所要进行的规则(DNAT/REDIRECT)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;span class=&quot;text_import2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; POSTROUTING&lt;/span&gt;：在进行路由判断之后所要进行的规则(SNAT/MASQUERADE)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;span class=&quot;text_import2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; OUTPUT&lt;/span&gt;：与发送出去的封包有关。&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;span class=&quot;text_import1&quot;&gt;mangle：&lt;/span&gt;该表包含一些规则来标记用于高级路由的信息包，该表包含          &lt;code&gt;PREROUTING&lt;/code&gt; 和          &lt;code&gt;OUTPUT&lt;/code&gt; 链。&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;RAW表只使用在PREROUTING链和OUTPUT链上,因为优先级最高，从而可以对收到的数据包在连接跟踪前进行处理。一但用户使用了RAW 表,在某个链上,RAW表处理完后,将跳过NAT表和 ip_conntrack处理,即不再做地址转换和数据包的链接跟踪处理了.RAW表可以应用在那些不需要做nat的情况下，以提高性能。如大量访问的web服务器，可以让80端口不再让iptables做数据包的链接跟踪处理，以提高用户的访问速度。&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;各链表关系如下：&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFR-NK-5DGOLDfB_2oDzaJ87ZTuU3zlXj_hlipIwlq5cQx5WJqpOSY3zrRk9vtTPztqbcywRoFL81x2ldqRBlkceh_Gt7JLghG08zViNA5NsxAbGAFdZ0Yx8D6dmhz6c0HBjChZ9KiPG5_/s1600/tables_traverse.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFR-NK-5DGOLDfB_2oDzaJ87ZTuU3zlXj_hlipIwlq5cQx5WJqpOSY3zrRk9vtTPztqbcywRoFL81x2ldqRBlkceh_Gt7JLghG08zViNA5NsxAbGAFdZ0Yx8D6dmhz6c0HBjChZ9KiPG5_/s640/tables_traverse.jpg&quot; width=&quot;376&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;text_import1&quot;&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://chennrui.blogspot.com/feeds/7287231180774922557/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://chennrui.blogspot.com/2011/05/iptables-command-and-rules.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/7287231180774922557'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/7287231180774922557'/><link rel='alternate' type='text/html' href='http://chennrui.blogspot.com/2011/05/iptables-command-and-rules.html' title='iptables command and rules'/><author><name>big bang</name><uri>http://www.blogger.com/profile/07380722230385048574</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQEwGR3hniNIaoAuRxuoFMsyO_esdj85N9t60Bj4qln24_y7qj8mnx8taxn-KrBbc2zQBfJviUXvScqSs7OD3zJBpP5wimbihfo-Y9yHnpYezKHlkxxt5YRkQ2wyrFDA/s220/linux-logo.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFR-NK-5DGOLDfB_2oDzaJ87ZTuU3zlXj_hlipIwlq5cQx5WJqpOSY3zrRk9vtTPztqbcywRoFL81x2ldqRBlkceh_Gt7JLghG08zViNA5NsxAbGAFdZ0Yx8D6dmhz6c0HBjChZ9KiPG5_/s72-c/tables_traverse.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7128755548240021396.post-3138730588489571801</id><published>2011-05-14T18:27:00.000+08:00</published><updated>2011-05-14T18:27:01.136+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="linuxprogram"/><title type='text'>hash list</title><content type='html'>&lt;ol&gt;&lt;li&gt;拉链法实现HASH链表&lt;pre&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000066; font-size: 10px; white-space: normal;&quot;&gt;&lt;ol&gt;&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;span class=&quot;co2&quot; style=&quot;color: #666666; font-style: italic;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;span class=&quot;co2&quot; style=&quot;color: #666666; font-style: italic;&quot;&gt;#include &amp;lt;string.h&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;span class=&quot;co2&quot; style=&quot;color: #666666; font-style: italic;&quot;&gt;#define N 14&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;span class=&quot;co2&quot; style=&quot;color: #666666; font-style: italic;&quot;&gt;#define M 14&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; typedef struct struct_node&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; int&amp;nbsp;&lt;a href=&quot;http://www.php.net/key&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;key&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; struct struct_node&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;*&lt;/span&gt;&lt;a href=&quot;http://www.php.net/next&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;next&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;}&lt;/span&gt;node&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; int get_hash_key&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;int&amp;nbsp;&lt;a href=&quot;http://www.php.net/key&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;key&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt;&amp;nbsp;&lt;a href=&quot;http://www.php.net/key&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;key&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;%&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;nu0&quot; style=&quot;color: #cc66cc;&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; node&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;**&lt;/span&gt;&lt;a href=&quot;http://www.php.net/hash_init&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;hash_init&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;node&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;**&lt;/span&gt;hash_table&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;int m&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; int i&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;nu0&quot; style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;for&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;&amp;lt;&lt;/span&gt;&amp;nbsp;m&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&amp;nbsp;i&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;++&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; hash_table&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;]&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;kw4&quot; style=&quot;color: #009900; font-weight: bold;&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt;&amp;nbsp;hash_table&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; node&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;**&lt;/span&gt;create_hash_table&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;node&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;**&lt;/span&gt;hash_table&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;int&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;*&lt;/span&gt;a&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; node&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;*&lt;/span&gt;m&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; int i&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;nu0&quot; style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;&lt;a href=&quot;http://www.php.net/key&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;key&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;for&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;&amp;lt;&lt;/span&gt;&amp;nbsp;N&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&amp;nbsp;i&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;++&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href=&quot;http://www.php.net/key&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;key&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;get_hash_key&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; m&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;node&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;malloc&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&lt;a href=&quot;http://www.php.net/sizeof&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;sizeof&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;node&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;!&lt;/span&gt;m&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href=&quot;http://www.php.net/printf&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;printf&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;st0&quot; style=&quot;color: blue;&quot;&gt;&quot;malloc failed.&lt;span class=&quot;es1&quot; style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href=&quot;http://www.php.net/exit&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;exit&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nu0&quot; style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; m&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot; style=&quot;color: #004000;&quot;&gt;key&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;a&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&amp;nbsp;hash_table&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;[&lt;/span&gt;&lt;a href=&quot;http://www.php.net/key&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;key&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;]&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;==&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;kw4&quot; style=&quot;color: #009900; font-weight: bold;&quot;&gt;NULL&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; hash_table&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;[&lt;/span&gt;&lt;a href=&quot;http://www.php.net/key&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;key&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;]&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;m&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; m&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot; style=&quot;color: #004000;&quot;&gt;next&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;kw4&quot; style=&quot;color: #009900; font-weight: bold;&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;continue&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; m&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot; style=&quot;color: #004000;&quot;&gt;next&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;hash_table&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;[&lt;/span&gt;&lt;a href=&quot;http://www.php.net/key&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;key&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; hash_table&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;[&lt;/span&gt;&lt;a href=&quot;http://www.php.net/key&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;key&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;]&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;m&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt;&amp;nbsp;hash_table&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; node&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;*&lt;/span&gt;search_node&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;node&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;**&lt;/span&gt;hash_table&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;int&amp;nbsp;&lt;a href=&quot;http://www.php.net/key&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;key&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; node&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;*&lt;/span&gt;p&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; int i&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;nu0&quot; style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;hash_key&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; hash_key&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;get_hash_key&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&lt;a href=&quot;http://www.php.net/key&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;key&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; p&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;hash_table&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;[&lt;/span&gt;hash_key&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;!&lt;/span&gt;p&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;kw4&quot; style=&quot;color: #009900; font-weight: bold;&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;while&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&amp;nbsp;p&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&amp;nbsp;p&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot; style=&quot;color: #004000;&quot;&gt;key&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;==&lt;/span&gt;&amp;nbsp;&lt;a href=&quot;http://www.php.net/key&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;key&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt;&amp;nbsp;p&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; p&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;p&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot; style=&quot;color: #004000;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;kw4&quot; style=&quot;color: #009900; font-weight: bold;&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; node&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;**&lt;/span&gt;delete_node&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;node&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;**&lt;/span&gt;hash_table&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;int&amp;nbsp;&lt;a href=&quot;http://www.php.net/key&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;key&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; node&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;*&lt;/span&gt;p&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,*&lt;/span&gt;q&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,*&lt;/span&gt;head&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; p&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;hash_table&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;[&lt;/span&gt;get_hash_key&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&lt;a href=&quot;http://www.php.net/key&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;key&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;!&lt;/span&gt;p&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href=&quot;http://www.php.net/printf&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;printf&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;st0&quot; style=&quot;color: blue;&quot;&gt;&quot;[-] no key in hash_table .&lt;span class=&quot;es1&quot; style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt;&amp;nbsp;hash_table&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&amp;nbsp;p&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot; style=&quot;color: #004000;&quot;&gt;next&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;==&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;kw4&quot; style=&quot;color: #009900; font-weight: bold;&quot;&gt;NULL&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; hash_table&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;[&lt;/span&gt;get_hash_key&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&lt;a href=&quot;http://www.php.net/key&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;key&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;]&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;kw4&quot; style=&quot;color: #009900; font-weight: bold;&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt;&amp;nbsp;hash_table&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;while&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&amp;nbsp;p&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;!=&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;kw4&quot; style=&quot;color: #009900; font-weight: bold;&quot;&gt;NULL&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&amp;nbsp;p&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot; style=&quot;color: #004000;&quot;&gt;key&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;==&lt;/span&gt;&amp;nbsp;&lt;a href=&quot;http://www.php.net/key&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;key&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&amp;nbsp;p&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;==&lt;/span&gt;&amp;nbsp;hash_table&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;[&lt;/span&gt;get_hash_key&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&lt;a href=&quot;http://www.php.net/key&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;key&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;]&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; hash_table&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;[&lt;/span&gt;get_hash_key&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&lt;a href=&quot;http://www.php.net/key&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;key&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;]&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;p&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot; style=&quot;color: #004000;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt;&amp;nbsp;hash_table&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; q&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot; style=&quot;color: #004000;&quot;&gt;next&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;p&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot; style=&quot;color: #004000;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt;&amp;nbsp;hash_table&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; q&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;p&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; p&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;p&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot; style=&quot;color: #004000;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;kw4&quot; style=&quot;color: #009900; font-weight: bold;&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; void print_node&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;node&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;*&lt;/span&gt;head&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;!&lt;/span&gt;head&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;while&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&amp;nbsp;head&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;!=&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;kw4&quot; style=&quot;color: #009900; font-weight: bold;&quot;&gt;NULL&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href=&quot;http://www.php.net/printf&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;printf&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;st0&quot; style=&quot;color: blue;&quot;&gt;&quot;&lt;span class=&quot;es6&quot; style=&quot;color: #009933; font-weight: bold;&quot;&gt;%d&lt;/span&gt;,&quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;head&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot; style=&quot;color: #004000;&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; head&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;head&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot; style=&quot;color: #004000;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; void print_hash_table&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;node&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;**&lt;/span&gt;hash_table&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; int i&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;nu0&quot; style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;for&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;&amp;lt;&lt;/span&gt;&amp;nbsp;M&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&amp;nbsp;i&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;++&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print_node&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;hash_table&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href=&quot;http://www.php.net/printf&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;printf&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;st0&quot; style=&quot;color: blue;&quot;&gt;&quot;&lt;span class=&quot;es1&quot; style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; void destroy_node&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;node&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;*&lt;/span&gt;head&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; node&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;*&lt;/span&gt;p&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;while&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&amp;nbsp;head&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;!=&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;kw4&quot; style=&quot;color: #009900; font-weight: bold;&quot;&gt;NULL&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; p&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;head&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot; style=&quot;color: #004000;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; free&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;head&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; head&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;p&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; void destroy_hash_table&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;node&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;**&lt;/span&gt;hash_table&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; int i&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;nu0&quot; style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;for&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&amp;nbsp;i&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;&amp;lt;&lt;/span&gt;&amp;nbsp;N&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&amp;nbsp;i&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;++&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; destroy_node&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;hash_table&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; int main&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;void&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; node&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;*&lt;/span&gt;hash_table&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;[&lt;/span&gt;M&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,*&lt;/span&gt;p&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,**&lt;/span&gt;s&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; int a&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;[&lt;/span&gt;N&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;]&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nu0&quot; style=&quot;color: #cc66cc;&quot;&gt;47&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot; style=&quot;color: #cc66cc;&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot; style=&quot;color: #cc66cc;&quot;&gt;29&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot; style=&quot;color: #cc66cc;&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot; style=&quot;color: #cc66cc;&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot; style=&quot;color: #cc66cc;&quot;&gt;92&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot; style=&quot;color: #cc66cc;&quot;&gt;22&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot; style=&quot;color: #cc66cc;&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot; style=&quot;color: #cc66cc;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot; style=&quot;color: #cc66cc;&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot; style=&quot;color: #cc66cc;&quot;&gt;37&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot; style=&quot;color: #cc66cc;&quot;&gt;89&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot; style=&quot;color: #cc66cc;&quot;&gt;94&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot; style=&quot;color: #cc66cc;&quot;&gt;21&lt;/span&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href=&quot;http://www.php.net/hash_init&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;hash_init&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;hash_table&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;M&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href=&quot;http://www.php.net/printf&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;printf&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;st0&quot; style=&quot;color: blue;&quot;&gt;&quot;[+] hash init ok.&lt;span class=&quot;es1&quot; style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; create_hash_table&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;hash_table&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;a&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href=&quot;http://www.php.net/printf&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;printf&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;st0&quot; style=&quot;color: blue;&quot;&gt;&quot;[+] hash table create ok.&lt;span class=&quot;es1&quot; style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; print_hash_table&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;hash_table&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href=&quot;http://www.php.net/printf&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;printf&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;st0&quot; style=&quot;color: blue;&quot;&gt;&quot;..................................&lt;span class=&quot;es1&quot; style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; p&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;search_node&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;hash_table&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot; style=&quot;color: #cc66cc;&quot;&gt;29&lt;/span&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href=&quot;http://www.php.net/printf&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;printf&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;st0&quot; style=&quot;color: blue;&quot;&gt;&quot;&lt;span class=&quot;es6&quot; style=&quot;color: #009933; font-weight: bold;&quot;&gt;%d&lt;/span&gt;&lt;span class=&quot;es1&quot; style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;p&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot; style=&quot;color: #004000;&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href=&quot;http://www.php.net/printf&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;printf&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;st0&quot; style=&quot;color: blue;&quot;&gt;&quot;..................................&lt;span class=&quot;es1&quot; style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; s&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt;&amp;nbsp;delete_node&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;hash_table&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot; style=&quot;color: #cc66cc;&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;!&lt;/span&gt;s&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href=&quot;http://www.php.net/printf&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;printf&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;st0&quot; style=&quot;color: blue;&quot;&gt;&quot;[-] hash_table NULL.&lt;span class=&quot;es1&quot; style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; print_hash_table&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;s&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; destroy_hash_table&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;hash_table&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li2&quot; style=&quot;color: #006060; font-weight: bold; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de2&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href=&quot;http://www.php.net/printf&quot; style=&quot;color: #000060;&quot;&gt;&lt;span class=&quot;kw3&quot; style=&quot;color: #990000;&quot;&gt;printf&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;st0&quot; style=&quot;color: blue;&quot;&gt;&quot;[+] destroy hash_table ok.&lt;span class=&quot;es1&quot; style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;kw1&quot; style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;nu0&quot; style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot; style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;color: #003030; font-weight: normal; font: normal normal normal 130%/normal &#39;Courier New&#39;, Courier, monospace; vertical-align: top;&quot;&gt;&lt;div class=&quot;de1&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: initial; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; color: #000020; font: normal normal normal 1em/1.2em monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;br0&quot; style=&quot;color: #009900;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ol&gt;</content><link rel='replies' type='application/atom+xml' href='http://chennrui.blogspot.com/feeds/3138730588489571801/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://chennrui.blogspot.com/2011/05/hash-list.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/3138730588489571801'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/3138730588489571801'/><link rel='alternate' type='text/html' href='http://chennrui.blogspot.com/2011/05/hash-list.html' title='hash list'/><author><name>big bang</name><uri>http://www.blogger.com/profile/07380722230385048574</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQEwGR3hniNIaoAuRxuoFMsyO_esdj85N9t60Bj4qln24_y7qj8mnx8taxn-KrBbc2zQBfJviUXvScqSs7OD3zJBpP5wimbihfo-Y9yHnpYezKHlkxxt5YRkQ2wyrFDA/s220/linux-logo.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7128755548240021396.post-8770927499617262440</id><published>2011-02-11T23:55:00.002+08:00</published><updated>2011-02-12T00:07:58.805+08:00</updated><title type='text'>MeeGo挺不住了</title><content type='html'>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2月11日，NOKIA宣布，与微软达成广泛战略合作关系，并将Windows Phone作为其主要的智能手机操作系统。并且MeeGo和移动解决方案业务主管阿尔伯托·托雷斯(Alberto Torres)已经于2月10日离职。&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; 同时有消息，首款MeeGo系统手机Nokia N9-00也不幸夭折。传说中的MeeGo，被视为诺基亚在高端智能手机市场上对抗苹果和谷歌的利器，看来大势已去。不知Intel有何感想，怀胎10月，流产了。&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Tieto，跟在Nokia后的小弟，你又何去何从？！。。。命运掌握在自己手中睡觉才踏实，觉醒吧。</content><link rel='replies' type='application/atom+xml' href='http://chennrui.blogspot.com/feeds/8770927499617262440/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://chennrui.blogspot.com/2011/02/meego.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/8770927499617262440'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/8770927499617262440'/><link rel='alternate' type='text/html' href='http://chennrui.blogspot.com/2011/02/meego.html' title='MeeGo挺不住了'/><author><name>big bang</name><uri>http://www.blogger.com/profile/07380722230385048574</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQEwGR3hniNIaoAuRxuoFMsyO_esdj85N9t60Bj4qln24_y7qj8mnx8taxn-KrBbc2zQBfJviUXvScqSs7OD3zJBpP5wimbihfo-Y9yHnpYezKHlkxxt5YRkQ2wyrFDA/s220/linux-logo.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7128755548240021396.post-1469341241103077933</id><published>2011-01-30T12:40:00.000+08:00</published><updated>2011-01-30T12:40:56.839+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="gstreamer"/><title type='text'>Gstreamer Pad</title><content type='html'>&lt;ul&gt;&lt;li&gt;The relationship between pad and caps  &lt;pre&gt;&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; |-name_template(eg:wavparse_src, wavparse_sink)
                       |
                       |-direction(src or sink)
  GstStaticPadTemplate-|
          |            |-presence(Sometimes, Always, request)
          |            |
          |            |                  |-GstCaps(String is stored in GstStruct)
          |            |-GstStaticCaps----|
          |                               |-String(support caps)
   gst_static_pad_template_get()
          |
          |           |-GstObject
          V           |
  GstPadTemplate------|-direction
          |           |
          |           |-presence
          |           |
          |           |-GstCaps
          |
   gst_pad_new_from_static_template()
          |
          |
          V    |-GstObject
  GstPad-------|-GstPadTemplate
               |...
&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;Add pad into element and set relation  &lt;pre&gt;gst_element_add_pad(element, pad)
  {
      _set_parent(element, pad) {
          pad-&amp;gt;parent = element
      }
  
      if(pad-&amp;gt;direction == src)
          element-&amp;gt;srcpads = pad
      else if(pad-&amp;gt;direction == sink)
          element-&amp;gt;sinkpads = pad
  
      element-&amp;gt;pads = pad
  }
  
  +---------+         +------------+         +---------+
  |      parent------&amp;gt;|  element   |&amp;lt;------parent      |
  | Gstpad  |&amp;lt;-----sinkpad      srcpad------&amp;gt;|  GstPad |
  +---------+         +------------+         +---------+
  
&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;Set pad active from srcpad to sinkpad     &lt;ol&gt;&lt;li&gt;element state change from READY to PAUSE, set pad active  &lt;pre&gt;gst_element_pads_activate(element, TRUE)
  {
      //set srcpad
      activate_pads(element-&amp;gt;srcpads, TRUE);
      //set sinkpad
      activate_pads(element-&amp;gt;sinkpads, TRUE);
  }
&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;check pad current mode and call pad-&amp;gt;activefunc  &lt;pre&gt;gst_pad_set_active(pad)
  {
      mode = GST_PAD_ACTIVATE_MODE(pad);
      if(mode == GST_ACTIVATE_PUSH || mode == GST_ACTIVATE_PULL) {
          //pad already activation
          return TRUE;
      }
      else if (mode == GST_ACTIVATE_NONE)
          GST_PAD_ACTIVATEFUNC(pad) (pad);
  }
&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;call pad-&amp;gt;activepushfunc or pad-&amp;gt;activepullfunc, default is pushfunc  &lt;pre&gt;gst_pad_activate_push(pad)
  {
      GST_PAD_ACTIVATE_MODE(pad) = GST_ACTIVATE_PUSH;
  
      GST_PAD_ACTIVATEPUSHFUNC(pad) (pad);
  }
  gst_pad_activate_pull(pad)
  {
      GST_PAD_ACTIVATE_MODE(pad) = GST_ACTIVATE_PULL;
  
      GST_PAD_ACTIVATEPULLFUNC(pad) (pad);
  }
&lt;/pre&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='http://chennrui.blogspot.com/feeds/1469341241103077933/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://chennrui.blogspot.com/2011/01/gstreamer-pad.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/1469341241103077933'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/1469341241103077933'/><link rel='alternate' type='text/html' href='http://chennrui.blogspot.com/2011/01/gstreamer-pad.html' title='Gstreamer Pad'/><author><name>big bang</name><uri>http://www.blogger.com/profile/07380722230385048574</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQEwGR3hniNIaoAuRxuoFMsyO_esdj85N9t60Bj4qln24_y7qj8mnx8taxn-KrBbc2zQBfJviUXvScqSs7OD3zJBpP5wimbihfo-Y9yHnpYezKHlkxxt5YRkQ2wyrFDA/s220/linux-logo.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7128755548240021396.post-6970667491375053553</id><published>2011-01-14T14:05:00.000+08:00</published><updated>2011-01-14T14:05:17.563+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="gstreamer"/><title type='text'>Gstreamer State Change</title><content type='html'>&lt;ul&gt;&lt;li&gt;Some concepts of States     &lt;ol&gt;&lt;li&gt;States defined in gstreamer         &lt;ul&gt;&lt;li&gt;GST_STATE_VOID_PENDING: the state of an element is not set.         &lt;/li&gt;
&lt;li&gt;GST_STATE_NULL: initial state of an element.         &lt;/li&gt;
&lt;li&gt;GST_STATE_READY: all sources are ready and can go to pause.         &lt;/li&gt;
&lt;li&gt;GST_STATE_PAUSE: ready to accept and process data.         &lt;/li&gt;
&lt;li&gt;GST_STATE_PLAYING: the GstClock is running and the data is flowing.         &lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Variables in GstElement         &lt;ul&gt;&lt;li&gt;current_state: the current state of an element.         &lt;/li&gt;
&lt;li&gt;next_state: the next state of an element.         &lt;/li&gt;
&lt;li&gt;pending_state: the final state the element should go to.         &lt;/li&gt;
&lt;li&gt;target_state: last state the element we set.         &lt;/li&gt;
&lt;li&gt;last_return: the last return value of an element state change.         &lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;The states switch         &lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieSQsDUSWZzMCAXe_zY1GrBg6vxiwtrA4M45GroCo2rAZfKkdT8uRmPyGZ2i_amv0LDwnAGVMTjY15qZSyNT0Xz1h3cV5ys0XJQ32ZHz-AYOEvpdPImuQmJRdl7W2x45J4dNMJMTuX5WGt/s1600/state_switch.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;95&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieSQsDUSWZzMCAXe_zY1GrBg6vxiwtrA4M45GroCo2rAZfKkdT8uRmPyGZ2i_amv0LDwnAGVMTjY15qZSyNT0Xz1h3cV5ys0XJQ32ZHz-AYOEvpdPImuQmJRdl7W2x45J4dNMJMTuX5WGt/s320/state_switch.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;Create a simple pipe to understand what are states  &lt;pre&gt;$ gst-launch-0.10 alsasrc ! audiorate ! filesink location=test.wav
&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;At the beginning, gstreamer core how to initialize each element     &lt;ol&gt;&lt;li&gt;Use funtion &lt;i&gt;gst_element_factory_make(&quot;alsasrc&quot;, &quot;sound&quot;)&lt;/i&gt; to create &lt;i&gt;alsasrc&lt;/i&gt; element     &lt;/li&gt;
&lt;li&gt;When create instance of alsasrc(sound), &lt;i&gt;gst_element_init()&lt;/i&gt; will initial state of the element.  &lt;pre&gt;GST_STATE_TARGET (element) = GST_STATE_NULL;            //target_state&lt;/pre&gt;&lt;pre&gt;GST_STATE_NEXT (element) = GST_STATE_VOID_PENDING;      //next_state&lt;/pre&gt;&lt;pre&gt;GST_STATE_PENDING (element) = GST_STATE_VOID_PENDING;   //pending_state&lt;/pre&gt;&lt;pre&gt;GST_STATE_RETURN (element) = GST_STATE_CHANGE_SUCCESS;  //last_return&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;GST_STATE (element) = GST_STATE_NULL;                   //current_state &lt;/pre&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;Use function &lt;i&gt;gst_bin_add_many&lt;/i&gt; to add elements to pipeline. Just add each element to GstBin-&amp;gt;children, didn&#39;t change state of element &lt;/li&gt;
&lt;li&gt;After link success I want to change state of pipeline from GST_STATE_NULL to GST_STATE_PLAYING     &lt;ol&gt;&lt;li&gt;Now the state of element is GST_STATE_NULL, first change the  state to GST_STATE_READY. All elements are added in GstBin-&amp;gt;cheldren,  when we change the state of pipeline to GST_STATE_READY, pipeline will  call &lt;i&gt;gst_bin_change_state_func&lt;/i&gt; to find child elemnt to change  state to GST_STATE_READY. each child element will call  plugin-&amp;gt;change_state which defined by ourselves.     &lt;/li&gt;
&lt;li&gt;If state change to GST_STATE_READY successfully, update  state of element, then try to change state of pipeline from  GST_STATE_READY to GST_STATE_PAUSE. Alsa call &lt;i&gt;gst_bin_change_state_func&lt;/i&gt;, the same as step 1.     &lt;/li&gt;
&lt;li&gt;If state change to GST_STATE_PAUSE successfully, update  state of element, then try to change state of pipeline from  GST_STATE_PAUSE to GST_STATE_READY. Alsa call &lt;i&gt;gst_bin_change_state_func&lt;/i&gt;, the same as step 1.     &lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;When accept message &lt;i&gt;GST_MESSAGE_EOS&lt;/i&gt;, try to change the state of pipeline from GST_STATE_PLAYING to GST_STATE_NULL &lt;/li&gt;
&lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='http://chennrui.blogspot.com/feeds/6970667491375053553/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://chennrui.blogspot.com/2011/01/gstreamer-state-change.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/6970667491375053553'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/6970667491375053553'/><link rel='alternate' type='text/html' href='http://chennrui.blogspot.com/2011/01/gstreamer-state-change.html' title='Gstreamer State Change'/><author><name>big bang</name><uri>http://www.blogger.com/profile/07380722230385048574</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQEwGR3hniNIaoAuRxuoFMsyO_esdj85N9t60Bj4qln24_y7qj8mnx8taxn-KrBbc2zQBfJviUXvScqSs7OD3zJBpP5wimbihfo-Y9yHnpYezKHlkxxt5YRkQ2wyrFDA/s220/linux-logo.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieSQsDUSWZzMCAXe_zY1GrBg6vxiwtrA4M45GroCo2rAZfKkdT8uRmPyGZ2i_amv0LDwnAGVMTjY15qZSyNT0Xz1h3cV5ys0XJQ32ZHz-AYOEvpdPImuQmJRdl7W2x45J4dNMJMTuX5WGt/s72-c/state_switch.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7128755548240021396.post-4000885310424958000</id><published>2011-01-07T14:19:00.000+08:00</published><updated>2011-01-07T14:19:39.621+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="linux admin"/><title type='text'>ubuntu samba server</title><content type='html'>&lt;ol&gt;&lt;li&gt;Installl samba  &lt;pre&gt;$ sudo apt-get install samba4&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;(install samba, server can not start, i don&#39;t know why)&lt;/pre&gt;&lt;pre&gt;$ sudo apt-get install smbclient
&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;Configure /etc/samba/smb.conf  &lt;pre&gt;[global]
      security = share&lt;/pre&gt;&lt;pre&gt;[share]
      comment = chenorui
      path = /home/chenorui/share
      public = yes
      guest ok = yes
      browsable = yes
      writable = no
&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;Restart samba server  &lt;pre&gt;$ sudo /etc/init.d/samba4 restart
&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;Look at what services are available on a server  &lt;pre&gt;$ smbclient -L //yourIP
  Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.5.4]
  
  Sharename       Type      Comment
  ---------       ----      -------
  IPC$            IPC       IPC Service (chenorui server (Samba, Ubuntu))
  share           Disk      chenorui
  HP-LaserJet-M1522 Printer   HP LaserJet M1522
  Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.5.4]
  
  Server               Comment
  ---------            -------
  
  Workgroup            Master
  ---------            -------
&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;Login share profile  &lt;pre&gt;$ smbclient //yourIP/share
  smb: \&amp;gt;
&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;mount share profile  &lt;pre&gt;$ sudo smbmount //yourIP/share /tmp/test
&lt;/pre&gt;&lt;/li&gt;
&lt;/ol&gt;</content><link rel='replies' type='application/atom+xml' href='http://chennrui.blogspot.com/feeds/4000885310424958000/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://chennrui.blogspot.com/2011/01/ubuntu-samba-server.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/4000885310424958000'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/4000885310424958000'/><link rel='alternate' type='text/html' href='http://chennrui.blogspot.com/2011/01/ubuntu-samba-server.html' title='ubuntu samba server'/><author><name>big bang</name><uri>http://www.blogger.com/profile/07380722230385048574</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQEwGR3hniNIaoAuRxuoFMsyO_esdj85N9t60Bj4qln24_y7qj8mnx8taxn-KrBbc2zQBfJviUXvScqSs7OD3zJBpP5wimbihfo-Y9yHnpYezKHlkxxt5YRkQ2wyrFDA/s220/linux-logo.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7128755548240021396.post-2524834359471145312</id><published>2011-01-05T17:03:00.000+08:00</published><updated>2011-01-05T17:03:04.117+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="gstreamer"/><title type='text'>gstreamer caps negotiation</title><content type='html'>协商过程中主要函数:&lt;br /&gt;
gst_pad_get_caps/gst_pad_set_getcaps_function, gst_pad_set_caps/gst_pad_set_setcaps_function。&lt;br /&gt;
&lt;br /&gt;
gst_pad_get_caps 函数用来返回该pad能接受的caps。首先检查getcaps函数指针是否为NULL，如果不是则调用getcaps函数，这是一个函数指针，我们可以通过gst_pad_set_getcaps_function来给这个函数指针赋值，从而实现自定义的get_caps函数的逻辑。完成后函数返回；如果getcaps函数指针为NULL，则gst_pad_get_caps函数从该pad的pad template中列出所有的caps，返回；如果该pad没有pad template，则gst_pad_get_caps函数检查该GstPad的caps成员是否为NULL，如果不为NULL，则返回这个 member；最后，如果前面的都不成立，则gst_pad_get_caps创建一个empty的GstCaps并返回，表示该pad目前没有caps。 &lt;br /&gt;
&lt;br /&gt;
get_pad_set_caps 函数用来设置指定pad的caps。该函数首先检查参数中给出的caps是否已经和目前该pad中的caps相同，如果是，则直接返回。如果不相同，则检查setcaps函数指针是否为NULL，如果不为NULL则调用setcaps函数。我们可以通过 gst_pad_set_setcaps_function函数来给setcaps这个函数指针赋值，这样就在gst_pad_set_caps函数中实现了自定义的逻辑。注意，gst_pad_set_caps函数会判断setcaps函数的返回值，如果是FALSE，则会直接报错return FALSE，这样的结果就是gst_pad_set_caps函数执行失败，caps negotiation失败。当setcaps函数执行完毕后，gst_pad_set_caps函数执行gst_caps_replace，将保存在该pad中的caps member替换成参数中指定的caps，然后函数结束。 &lt;br /&gt;
&lt;br /&gt;
PUSH MODE:&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;pre&gt;&lt;code&gt;&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; src              sink
              |                 |
              |  accepts?       |
  type A      |----------------&amp;gt;|
              |      yes        |
              |&amp;lt;----------------|
              |                 |
 get buffer   |  alloc_buf      |
 from pool    |----------------&amp;gt;| 
 with type A  |                 | Create buffer of type A.
              |                 |
 check type   |&amp;lt;----------------|
 and use A    |                 |
              |  push           |
 push buffer  |----------------&amp;gt;| Receive type A, reconfigure to
 with new type|                 | process type A.
              |                 |
&lt;/code&gt;&lt;/pre&gt;PUSH MODE下，总是由src pad发起negotiation，为了让src pad和peer sink pad都能接受的caps来，src pad会将自己的caps和peer sink pad的caps做intersect，这时就会调用函数gst_pad_get_caps，参数就是peer sink pad（一般直接使用gst_pad_peer_get_caps函数一步完成）。如果 peer sink pad没有设置getcaps函数指针的话，那就会直接返回peer sink pad template中的所有caps。接下去就是src pad调用gst_pad_set_caps，把自己的caps确定下来，再然后就是申请并分配buffer&lt;br /&gt;
&lt;br /&gt;
PULL MODE&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;src              sink
              |                 |
              |  accepts?       |
              |&amp;lt;----------------| type B
              |      yes        |
              |----------------&amp;gt;|
              |                 |
 get buffer   |  alloc_buf      |
 from pool    |----------------&amp;gt;| 
 with type A  |                 | Create buffer of new type B.
              |                 |
 check type   |&amp;lt;----------------|
 and          |                 |
 reconfigure  |                 |
              | &lt;/code&gt;pull&lt;code&gt;   &amp;nbsp;        |&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code&gt;&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; |&lt;/code&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;&lt;code&gt;---------------&lt;/code&gt;&lt;code&gt;-&lt;/code&gt;&lt;code&gt;| &lt;/code&gt;Pull buffer from the peer src pad&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code&gt;              |                 |
&lt;/code&gt;&lt;/pre&gt;PULL MODE下，由于是sink element的sink pad来drive pipeline，所以，caps negotiation要在pull thread启动之前就完成。首先，sink pad将自己的caps和peer src pad的caps做intersect（需调用peer src pad上的gst_pad_get_caps），之后调用gst_pad_set_caps将sink pad caps确定下来。调用gst_pad_set_caps，设置peer src pad，如果成功，那么表示src pad和自己一样，都具备了相同的caps，这样negotiation就成功了。最后，可以使用gst_pad_pull_range来获取数据，这个函数会为我们检查buffer中的caps和当前sink pad中的caps是否一致，如果不一致，就会return GST_FLOW_NOT_NEGOTIATED。 &lt;br /&gt;
&lt;br /&gt;
gst_pad_set_caps 被调用的时机。当在_chain函数中收到一个buffer之后，一般需要检查该buffer中的caps是否和当前pad中的caps相同，以防止数据在运行过程中改变caps。如果这两个caps不相同，那么，_chain函数应该返回GST_FLOW_NOT_NEGOTIATED，这样，gstreamer core就会用buffer中这个新的caps，去调用gst_pad_set_caps，这样做的目的是gstreamer要知道pad能否接受这个 caps，如果函数返回TRUE，表示接受该caps，而且pad已经更新了自己的caps为目前这个，如果函数返回FALSE，表示caps negotiation failed，pipeline就无法正常运行了。&lt;br /&gt;
&lt;br /&gt;
在 PUSH模式下，_chain函数返回GST_FLOW_NOT_NEGOTIATED，gstreamer core就会自动为我们调用gst_pad_set_caps；但是在PULL模式下，虽然gst_pad_pull_range也会返回 GST_FLOW_NOT_NEGOTIATED，但是gst_pad_set_caps并不会自动被调用，gstramer不支持在pull thread中做set caps的动作。所以，在PULL模式下，我们需要自己处理这种GST_FLOW_NOT_NEGOTIATED的情况。回想pull thread没有启动之前，为什么我们需要设置setcaps函数呢？这是因为我们需要在这个函数中，使用gst_pad_set_caps来给peer src pad设置caps来完成caps negotiation，而这个动作在PUSH模式下，只要peer element的_chain函数返回GST_FLOW_NOT_NEGOTIATED，gstreamer core就会自动为我们调用peer src pad上的gst_pad_set_caps，所以，PUSH模式下，我们不需要去设置setcaps函数指针。</content><link rel='replies' type='application/atom+xml' href='http://chennrui.blogspot.com/feeds/2524834359471145312/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://chennrui.blogspot.com/2011/01/gstreamer-caps-negotiation.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/2524834359471145312'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/2524834359471145312'/><link rel='alternate' type='text/html' href='http://chennrui.blogspot.com/2011/01/gstreamer-caps-negotiation.html' title='gstreamer caps negotiation'/><author><name>big bang</name><uri>http://www.blogger.com/profile/07380722230385048574</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQEwGR3hniNIaoAuRxuoFMsyO_esdj85N9t60Bj4qln24_y7qj8mnx8taxn-KrBbc2zQBfJviUXvScqSs7OD3zJBpP5wimbihfo-Y9yHnpYezKHlkxxt5YRkQ2wyrFDA/s220/linux-logo.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7128755548240021396.post-5249036579659437707</id><published>2011-01-05T12:20:00.000+08:00</published><updated>2011-01-05T12:20:40.478+08:00</updated><title type='text'>不能上网了！！！！</title><content type='html'>adsl modern坏了，上不了网，狂晕:(&lt;br /&gt;
周末逛电脑城。。。</content><link rel='replies' type='application/atom+xml' href='http://chennrui.blogspot.com/feeds/5249036579659437707/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://chennrui.blogspot.com/2011/01/blog-post.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/5249036579659437707'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/5249036579659437707'/><link rel='alternate' type='text/html' href='http://chennrui.blogspot.com/2011/01/blog-post.html' title='不能上网了！！！！'/><author><name>big bang</name><uri>http://www.blogger.com/profile/07380722230385048574</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQEwGR3hniNIaoAuRxuoFMsyO_esdj85N9t60Bj4qln24_y7qj8mnx8taxn-KrBbc2zQBfJviUXvScqSs7OD3zJBpP5wimbihfo-Y9yHnpYezKHlkxxt5YRkQ2wyrFDA/s220/linux-logo.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7128755548240021396.post-8233673066912434982</id><published>2010-12-30T10:45:00.001+08:00</published><updated>2010-12-30T10:48:33.771+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="bash"/><title type='text'>Command -- trap</title><content type='html'>man trap, trap --help都没有，网上搜到格式如下： &lt;br /&gt;
trap &quot;command&quot; signal&lt;br /&gt;
于是有&lt;br /&gt;
&lt;blockquote&gt;&lt;code&gt;&lt;span style=&quot;color: black; font-family: Courier New; font-size: x-small;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;
&lt;ol&gt;&lt;span style=&quot;color: black; font-family: Courier New; font-size: x-small;&quot;&gt;
&lt;li&gt;#!/bin/bash&lt;/li&gt;
&lt;li&gt;trap &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;echo \&quot;hello world\&quot;; echo $1&quot;&lt;/span&gt; SIGKILL&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: blue;&quot;&gt;while&lt;/span&gt; : ; &lt;span style=&quot;color: blue;&quot;&gt;do&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;sleep 1&lt;/li&gt;
&lt;li&gt;done&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;$ ./test abc&amp;amp;&lt;/li&gt;
&lt;li&gt;$ kill 11219&lt;/li&gt;
&lt;/span&gt;&lt;/ol&gt;&lt;/blockquote&gt;额。。。没反应！&lt;br /&gt;
原来kill 命令发出信号SIGTERM，如果想用SIGKILL需要执行kill -9。&lt;br /&gt;
再次运行后结果为：&lt;br /&gt;
&lt;blockquote&gt;&lt;code&gt;&lt;span style=&quot;color: black; font-family: Courier New; font-size: x-small;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;
&lt;ol&gt;&lt;span style=&quot;color: black; font-family: Courier New; font-size: x-small;&quot;&gt;
&lt;li&gt;$ ./test abc&amp;amp;&lt;/li&gt;
&lt;li&gt;$ kill -9 112424&lt;/li&gt;
&lt;li&gt;$ hello world&lt;/li&gt;
&lt;li&gt;abc&lt;/li&gt;
&lt;/span&gt;&lt;/ol&gt;&lt;/blockquote&gt;trap为信号捕捉器，当接收到指定信号后执行&quot;&quot;中的命令。</content><link rel='replies' type='application/atom+xml' href='http://chennrui.blogspot.com/feeds/8233673066912434982/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://chennrui.blogspot.com/2010/12/command-trap.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/8233673066912434982'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/8233673066912434982'/><link rel='alternate' type='text/html' href='http://chennrui.blogspot.com/2010/12/command-trap.html' title='Command -- trap'/><author><name>big bang</name><uri>http://www.blogger.com/profile/07380722230385048574</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQEwGR3hniNIaoAuRxuoFMsyO_esdj85N9t60Bj4qln24_y7qj8mnx8taxn-KrBbc2zQBfJviUXvScqSs7OD3zJBpP5wimbihfo-Y9yHnpYezKHlkxxt5YRkQ2wyrFDA/s220/linux-logo.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7128755548240021396.post-3322280053203402537</id><published>2010-12-28T21:21:00.001+08:00</published><updated>2010-12-28T21:21:24.112+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="bash"/><title type='text'>Command -- find</title><content type='html'>&lt;div style=&quot;color: #000102;&quot;&gt;1.  想查看当前文件夹及子文件夹里有没有文件名为“abc”的文件&lt;/div&gt;# find . -name abc&lt;br /&gt;
. ：表示当前目录&lt;br /&gt;
-name：表示要根据名称查找&lt;br /&gt;
&lt;div style=&quot;color: #000102;&quot;&gt;2. 想查看当前文件夹及子文件夹里有没有”xyz”目录&lt;/div&gt;# find . -type d -name xyz&lt;br /&gt;
-type：表示设定类型，d表示文件夹类型，可以替换为f(普通文件)、l(链接文件)&lt;br /&gt;
&lt;div style=&quot;color: #000102;&quot;&gt;3.  想找出当前文件夹及子文件夹里所有后缀是”.txt”的文件&lt;/div&gt;# find . -name “*.txt”&lt;br /&gt;
&lt;div style=&quot;color: #000102;&quot;&gt;4.  想查找当前目录及其子文件夹中“roc”用户自己的文件有哪些&lt;/div&gt;# find . -user roc&lt;br /&gt;
-user：用于设定所属用户的名称，此处可替换为-group，即所属用户组的名称&lt;br /&gt;
&lt;div style=&quot;color: #000102;&quot;&gt;5.  想查找当前文件夹及子文件夹里权限设定为755的所有文件&lt;/div&gt;&lt;span id=&quot;more-18&quot;&gt;&lt;/span&gt;&lt;br /&gt;
# find . -perm 755&lt;br /&gt;
-perm：用于设定权限&lt;br /&gt;
&lt;div style=&quot;color: #000102;&quot;&gt;6.  想查找当前文件夹及子文件夹里的同时含有b字符和3字符的文件：用到正则表达式技术&lt;/div&gt;# find . -regex ‘.*b.*3′&lt;br /&gt;
-regex：表示使用正则表达式进行匹配。请注意，&lt;span style=&quot;color: red;&quot;&gt;此命令会和“全 路径”进行匹配，也就是说前面要加.*，因为输出结果中会有“./”符号。&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;color: #000102;&quot;&gt;7.  如果想全部输出用find命令查找出的”*.abc”文件的内容&lt;/div&gt;# find . -type f -name “*.abc” -exec cat {} \;&lt;br /&gt;
输出/tmp/code中所有.h，.c文件长度的总和&lt;br /&gt;
# find /tmp/code -name &#39;*.[ch]&#39; -exec wc -l {} \; | awk &#39;{n+=$1} END{print n}&#39;&lt;br /&gt;
-exec 表示由find找到的匹配项会作为“-exec后面设定的命令”的参数&lt;br /&gt;
可以使用-ok代替-exec，这样对每个匹配项进行操作，都会要求用户确认（y/n）.&lt;br /&gt;
命令最后的{} \; 别忘了写，其中{}代表用find查找到的结果中的每一个查找项。&lt;br /&gt;
&lt;div style=&quot;color: #000102;&quot;&gt;8. 查找当前目录下在5分钟内被访问过的文件 &lt;/div&gt;# find . -amin -5&lt;br /&gt;
访问过用amin，修改过用mmin，文件状态改变过用cmin&lt;br /&gt;
精确到分钟的用amin,mmin,cmin，精确到天的用atime,mtime,ctime&lt;br /&gt;
在5分钟之内的用-5，在5分钟以上的用＋5&lt;br /&gt;
&lt;div style=&quot;color: #000102;&quot;&gt;9. 想查找当前目录及子目录下文件大小大于10M的所有文件&lt;/div&gt;# find . -size +10000000c&lt;br /&gt;
-size：表示文件大小，＋表示大于某个数，－表示小于某个数。c表示单位是字节，你可以将c换成k,M,G。&lt;br /&gt;
&lt;div style=&quot;color: #000102;&quot;&gt;10.  上述所有的find命令都是查找当前目录及其子目录。如果不想深入到子目录中，而是只查找当前一层目录，则可以：&lt;/div&gt;# find . &lt;strong&gt;-maxdepth 1&lt;/strong&gt; -name “*.c”</content><link rel='replies' type='application/atom+xml' href='http://chennrui.blogspot.com/feeds/3322280053203402537/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://chennrui.blogspot.com/2010/12/command-find.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/3322280053203402537'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/3322280053203402537'/><link rel='alternate' type='text/html' href='http://chennrui.blogspot.com/2010/12/command-find.html' title='Command -- find'/><author><name>big bang</name><uri>http://www.blogger.com/profile/07380722230385048574</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQEwGR3hniNIaoAuRxuoFMsyO_esdj85N9t60Bj4qln24_y7qj8mnx8taxn-KrBbc2zQBfJviUXvScqSs7OD3zJBpP5wimbihfo-Y9yHnpYezKHlkxxt5YRkQ2wyrFDA/s220/linux-logo.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7128755548240021396.post-3105585423307468256</id><published>2010-12-28T21:20:00.000+08:00</published><updated>2010-12-28T21:20:02.799+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="bash"/><title type='text'>Linux system admin command(basic)</title><content type='html'>&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;strong&gt;Linux Command&lt;br /&gt;
&lt;/strong&gt;&lt;/span&gt;&lt;span style=&quot;font-size: small; font-weight: bold;&quot;&gt;1. output files&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;cat -- concatenate files and print on the standard output&lt;br /&gt;
tac -- concatenate and print file in reverse &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;nl -- number lines of file&lt;br /&gt;
head -- output the first part of file&lt;br /&gt;
tail -- output the last part of file&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: small; font-weight: bold;&quot;&gt;2. summarizing files&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;wc -- print newline, word, and byte counts for each file&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;font-size: small;&quot;&gt;eg. $wc -l -c test&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 30(line) 557(byte) test&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: small; font-weight: bold;&quot;&gt;3. sort files&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;sort -- sort lines of text files&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;table bgcolor=&quot;#f1f1f1&quot; border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt; &lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;eg.&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;sort缺省默认空格和tab键为分隔符。其他方式分隔，使用&lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;t选项。缺省以第1列来排序，即&lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;k1&lt;br /&gt;
&lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;n 指定分类是域上的数字分类。&lt;br /&gt;
如编辑文件1111&lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt;txt&lt;br /&gt;
sdsad 311 315 asd3f&lt;br /&gt;
wdasd 551 133 adsff&lt;br /&gt;
sdsad 606 44 fgfdgdf&lt;br /&gt;
wdwew 77 599 gghgf&lt;br /&gt;
eeese 23 22 fgdf&lt;br /&gt;
eeese 23 22 fgdf&lt;br /&gt;
dfdff 78 55 fdgd&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;k 使用k做分类排序&lt;span style=&quot;color: #0000cc;&quot;&gt;,&lt;/span&gt;如按第2列来分类排序&lt;br /&gt;
&lt;span style=&quot;color: #0000cc;&quot;&gt;$ sort &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;k2 1111&lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt;txt &lt;br /&gt;
eeese 23 22 fgdf&lt;br /&gt;
eeese 23 22 fgdf&lt;br /&gt;
sdsad 311 315 asd3f&lt;br /&gt;
wdasd 551 133 adsff&lt;br /&gt;
sdsad 606 44 fgfdgdf&lt;br /&gt;
wdwew 77 599 gghgf&lt;br /&gt;
dfdff 78 55 fdgd&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;n 指定分类列上按数值来分类排序，如第按第2列数值大小来分类&lt;br /&gt;
&lt;span style=&quot;color: #0000cc;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;$ sort&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;k2n 1111&lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt;txt&lt;br /&gt;
eeese 23 22 fgdf&lt;br /&gt;
eeese 23 22 fgdf&lt;br /&gt;
wdwew 77 599 gghgf&lt;br /&gt;
dfdff 78 55 fdgd&lt;br /&gt;
sdsad 311 315 asd3f&lt;br /&gt;
wdasd 551 133 adsff&lt;br /&gt;
sdsad 606 44 fgfdgdf&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;u 去除重复的行，即完全一样的行，只保留一行&lt;br /&gt;
&lt;span style=&quot;color: #0000cc;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;$ sort&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;k2n &lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;u 1111&lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt;txt &lt;br /&gt;
eeese 23 22 fgdf 只有1行了&lt;br /&gt;
wdwew 77 599 gghgf&lt;br /&gt;
dfdff 78 55 fdgd&lt;br /&gt;
sdsad 311 315 asd3f&lt;br /&gt;
wdasd 551 133 adsff&lt;br /&gt;
sdsad 606 44 fgfdgdf&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;span style=&quot;font-size: small; font-weight: bold;&quot;&gt;&lt;br /&gt;
4. unique files&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;uniq --&amp;nbsp; report or omit repeated lines &lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;font-size: x-small;&quot;&gt;-d:&amp;nbsp; only print duplicate lines&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -u:&amp;nbsp; only print unique lines&lt;br /&gt;
&lt;/span&gt;&lt;span style=&quot;font-size: small; font-weight: bold;&quot;&gt;5. compare files&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;diff -- compare files line by line&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;font-size: x-small;&quot;&gt;-y: output in two colums&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -c: output lines of copied context (&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;上下文输出格式&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -u: output lines of unified context&lt;/span&gt;&lt;/span&gt; &lt;table bgcolor=&quot;#f1f1f1&quot; border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt; &lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;eg&lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;
a&lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt;txt&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;abc&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; hello&lt;span style=&quot;color: red;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
b&lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt;txt&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cba&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; hello&lt;span style=&quot;color: red;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;$ diff&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt; -y a.txt b.txt -W 50&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;abc&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; cba&lt;br /&gt;
hello &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; hello&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;$ diff&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt; -c a.txt b.txt&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;*** a.txt&amp;nbsp;&amp;nbsp; &amp;nbsp;2010-12-13 22:15:13.000000000 +0800&lt;br /&gt;
--- b.txt&amp;nbsp;&amp;nbsp; &amp;nbsp;2010-12-13 22:15:21.000000000 +0800&lt;br /&gt;
***************&lt;br /&gt;
*** 1,2 ****&lt;br /&gt;
! abc&lt;br /&gt;
&amp;nbsp; hello&lt;br /&gt;
--- 1,2 ----&lt;br /&gt;
! cba&lt;br /&gt;
&amp;nbsp; hello&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;$ diff&lt;/span&gt;&lt;/span&gt;&lt;/code&gt; -u a.txt b.txt&lt;br /&gt;
--- a.txt&amp;nbsp;&amp;nbsp;&amp;nbsp; 2010-12-13 22:15:13.000000000 +0800&lt;br /&gt;
+++ b.txt&amp;nbsp;&amp;nbsp;&amp;nbsp; 2010-12-13 22:15:21.000000000 +0800&lt;br /&gt;
@@ -1,2 +1,2 @@&lt;br /&gt;
-abc&lt;br /&gt;
+cba&lt;br /&gt;
&amp;nbsp;test&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small; font-weight: bold;&quot;&gt;6. operating on characters&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;tr -- translate or delete characters&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt;&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt;&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt;&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt;&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt; -c: 取SET1的反义，所有不在SET1中的字符&lt;br /&gt;
&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt;&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt;&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt;&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt;&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt; -d:&lt;/span&gt;&lt;/span&gt; &lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;delete characters in SET1&lt;br /&gt;
&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt;&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt;&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt;&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt;&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt; -s:&lt;/span&gt;&lt;/span&gt; 浓缩重复的字符。如果标准输入中连续重复出现SET1里所列的字符，则将其浓缩成一个。或者将其浓缩成SET1中的字符&lt;br /&gt;
ps:&lt;br /&gt;
&lt;table bgcolor=&quot;#f1f1f1&quot; border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt; &lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: NSimsun;&quot;&gt;$echo &lt;span style=&quot;color: magenta;&quot;&gt;&quot;chennnrui123&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;|&lt;/span&gt; tr &lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;d &lt;span style=&quot;color: magenta;&quot;&gt;&quot;cr123&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: NSimsun;&quot;&gt;hennnui&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: NSimsun;&quot;&gt;$echo&lt;/span&gt;&lt;/span&gt;&lt;/code&gt; &lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: magenta;&quot;&gt;&lt;span style=&quot;font-family: NSimsun;&quot;&gt;&quot;chennnrui123&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt; &lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: NSimsun;&quot;&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;|&lt;/span&gt; tr &lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;s &lt;span style=&quot;color: magenta;&quot;&gt;&quot;[a-z]&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: NSimsun;&quot;&gt;chenrui123&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: NSimsun;&quot;&gt;$echo&lt;/span&gt;&lt;/span&gt;&lt;/code&gt; &lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: magenta;&quot;&gt;&lt;span style=&quot;font-family: NSimsun;&quot;&gt;&quot;abc123def&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt; &lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: NSimsun;&quot;&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;|&lt;/span&gt; tr &lt;span style=&quot;color: #0000cc;&quot;&gt;-c&lt;/span&gt;s &lt;span style=&quot;color: magenta;&quot;&gt;&quot;[a-z]&quot; &quot; &quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: NSimsun;&quot;&gt;abc&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: NSimsun;&quot;&gt;def&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: NSimsun;&quot;&gt;$echo&lt;/span&gt;&lt;/span&gt;&lt;/code&gt; &lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: magenta;&quot;&gt;&lt;span style=&quot;font-family: NSimsun;&quot;&gt;&quot;abc123def&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt; &lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: NSimsun;&quot;&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;|&lt;/span&gt; tr &lt;span style=&quot;color: #0000cc;&quot;&gt;-c&lt;/span&gt;s &lt;span style=&quot;color: magenta;&quot;&gt;&quot;[a-z]&quot; &quot; &quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: NSimsun;&quot;&gt;abc&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;span style=&quot;font-family: NSimsun; font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;span style=&quot;font-family: NSimsun; font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: NSimsun;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;def&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;span style=&quot;font-size: small; font-weight: bold;&quot;&gt;&lt;br /&gt;
Others&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
alias -- redefine command&lt;br /&gt;
eg.&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt;&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt; alias ls=&#39;ls -lh&#39;&lt;/span&gt; &lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://chennrui.blogspot.com/feeds/3105585423307468256/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://chennrui.blogspot.com/2010/12/linux-system-admin-commandbasic.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/3105585423307468256'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/3105585423307468256'/><link rel='alternate' type='text/html' href='http://chennrui.blogspot.com/2010/12/linux-system-admin-commandbasic.html' title='Linux system admin command(basic)'/><author><name>big bang</name><uri>http://www.blogger.com/profile/07380722230385048574</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQEwGR3hniNIaoAuRxuoFMsyO_esdj85N9t60Bj4qln24_y7qj8mnx8taxn-KrBbc2zQBfJviUXvScqSs7OD3zJBpP5wimbihfo-Y9yHnpYezKHlkxxt5YRkQ2wyrFDA/s220/linux-logo.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7128755548240021396.post-7368421290761025955</id><published>2010-12-28T21:17:00.000+08:00</published><updated>2010-12-28T21:36:13.954+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="bash"/><title type='text'>bash学习笔记（五）—— awk</title><content type='html'>&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;awk简介&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;awk命令行的程序模型&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;    &lt;br /&gt;
&lt;pre class=&quot;programlisting&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;awk [-F field-separator] &#39;commands&#39; input-file(s)&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;-F 指定域分隔符，可选，默认为空格。&lt;/span&gt;&lt;/pre&gt;&lt;pre class=&quot;programlisting&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;commands的命令格式为：&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;/pattern/{actions}&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;&lt;pre class=&quot;programlisting&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;condition{actions}&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;code class=&quot;literal&quot;&gt;pattern&lt;/code&gt;是正则表达式，&lt;code class=&quot;literal&quot;&gt;actions&lt;/code&gt;是一系列操作。&lt;/span&gt;&lt;/pre&gt;&lt;pre class=&quot;programlisting&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;awk程序一行一行读出待处理文件，如果&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;某一行与pattern&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;code class=&quot;literal&quot;&gt;&lt;/code&gt;匹配，或者满足&lt;code class=&quot;literal&quot;&gt;condition&lt;/code&gt;条件，&lt;/span&gt;&lt;/pre&gt;&lt;pre class=&quot;programlisting&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;则执行相应的&lt;code class=&quot;literal&quot;&gt;actions&lt;/code&gt;，如果一条&lt;code class=&quot;literal&quot;&gt;awk&lt;/code&gt;命令只有&lt;code class=&quot;literal&quot;&gt;actions&lt;/code&gt;部分，则&lt;code class=&quot;literal&quot;&gt;actions&lt;/code&gt;作用于待处理文件的每一行。
例：
testfile文件内容为
ProductA  30  aaa
ProductB  76  bbb
ProductC  55  ccc&lt;/span&gt;&lt;/pre&gt;&lt;span style=&quot;font-size: small;&quot;&gt;打印每一行的第二列:&lt;/span&gt;&lt;br /&gt;
&lt;table bgcolor=&quot;#f1f1f1&quot; border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;$ awk &lt;span style=&quot;color: magenta;&quot;&gt;&#39;{print $2;}&#39;&lt;/span&gt; testfile &lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;30 &lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;76 &lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;55&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;span style=&quot;font-size: small;&quot;&gt;自动变量&lt;code class=&quot;literal&quot;&gt;$1&lt;/code&gt;、&lt;code class=&quot;literal&quot;&gt;$2&lt;/code&gt;分别表示第一列、第二列等，类似于Shell脚本的位置参数，而&lt;code class=&quot;literal&quot;&gt;$0&lt;/code&gt;表示整个当前行。&lt;/span&gt;&lt;br /&gt;
&lt;table bgcolor=&quot;#f1f1f1&quot; border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;$ awk &lt;span style=&quot;color: magenta;&quot;&gt;&#39;$2&amp;lt;75 {printf &quot;%s\t%s\n&quot;, $0, &quot;REORDER&quot;;} $2&amp;gt;=75 {print $0;}&#39;&lt;/span&gt; testfile&lt;br /&gt;
ProductA  30    aaa REORDER&lt;br /&gt;
ProductB  76 bbb&lt;br /&gt;
ProductC  55    ccc REORDER&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;literal&quot;&gt;awk&lt;/code&gt;命令的&lt;code class=&quot;literal&quot;&gt;condition&lt;/code&gt;部分还可以是两个特殊的&lt;code class=&quot;literal&quot;&gt;condition&lt;/code&gt;－&lt;code class=&quot;literal&quot;&gt;BEGIN&lt;/code&gt;和&lt;code class=&quot;literal&quot;&gt;END&lt;/code&gt;，对于每个待处理文件，&lt;code class=&quot;literal&quot;&gt;BEGIN&lt;/code&gt;后面的&lt;code class=&quot;literal&quot;&gt;actions&lt;/code&gt;在处理整个文件之前执行一次，&lt;code class=&quot;literal&quot;&gt;END&lt;/code&gt;后面的&lt;code class=&quot;literal&quot;&gt;actions&lt;/code&gt;在整个文件处理完之后执行一次。&lt;/span&gt;&lt;br /&gt;
&lt;table bgcolor=&quot;#f1f1f1&quot; border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;awk &lt;span style=&quot;color: magenta;&quot;&gt;&#39;BEGIN {print &quot;name belt -----&quot;}{print $1&quot; &quot;$3} END {print &quot;end&quot;}&#39;&lt;/span&gt; testfile&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;name belt -----&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;ProductA aaa&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;ProductB bbb&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;ProductC ccc&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;br /&gt;
&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;ps: 注print与printf的区别&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;初次awk时，可能会经常出现错误，在碰到错误时，可以按以下方式查找：&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br style=&quot;color: red;&quot; /&gt;&lt;span style=&quot;color: red;&quot;&gt;!确保整个awk命令用单引号括起来&lt;/span&gt;&lt;br style=&quot;color: red;&quot; /&gt;&lt;span style=&quot;color: red;&quot;&gt;!确保命令内所有引号成对出现&lt;/span&gt;&lt;br style=&quot;color: red;&quot; /&gt;&lt;span style=&quot;color: red;&quot;&gt;!确保用花括号括起动作语句，用圆括号括起条件语句&lt;/span&gt;&lt;br style=&quot;color: red;&quot; /&gt;&lt;span style=&quot;color: red;&quot;&gt;!确保文件路径正确&lt;br /&gt;
&lt;/span&gt;awk有许多内置变量设置环境信息。这些变量可以被改变。下面是一些常用的内置变量。&lt;/span&gt;&lt;br /&gt;
&lt;table bgcolor=&quot;#f1f1f1&quot; border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;ARGC&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;      命令行参数个数&lt;br /&gt;
ARGV&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;      命令行参数排列&lt;br /&gt;
EVVIRON&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;   支持队列中系统环境变量的使用&lt;br /&gt;
FILENAME&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  awk浏览的文件名&lt;br /&gt;
FNR&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;       浏览文件的记录数&lt;br /&gt;
FS &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;       设置输入域分隔符，等价于命令行&lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;F选项&lt;br /&gt;
NF &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;       浏览记录的域个数&lt;br /&gt;
NR&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        已读的记录数&lt;br /&gt;
OFS &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;       输出域分隔符&lt;br /&gt;
ORS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;       输出记录分隔符&lt;br /&gt;
RS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        控制记录分隔符&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;例：&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span class=&quot;linuxcmd&quot;&gt;$ awk &#39;END {print NR}&#39;&lt;span style=&quot;font-family: monospace;&quot;&gt; testfile&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span class=&quot;linuxcmd&quot;&gt;3&lt;span style=&quot;font-family: monospace;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span class=&quot;linuxcmd&quot;&gt;$ awk &#39;{print NF} END {print FILENAME}&#39; testfile&lt;br /&gt;
3&lt;br /&gt;
3&lt;br /&gt;
3&lt;br /&gt;
testfile&lt;/span&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://chennrui.blogspot.com/feeds/7368421290761025955/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://chennrui.blogspot.com/2010/12/bash-awk.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/7368421290761025955'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/7368421290761025955'/><link rel='alternate' type='text/html' href='http://chennrui.blogspot.com/2010/12/bash-awk.html' title='bash学习笔记（五）—— awk'/><author><name>big bang</name><uri>http://www.blogger.com/profile/07380722230385048574</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQEwGR3hniNIaoAuRxuoFMsyO_esdj85N9t60Bj4qln24_y7qj8mnx8taxn-KrBbc2zQBfJviUXvScqSs7OD3zJBpP5wimbihfo-Y9yHnpYezKHlkxxt5YRkQ2wyrFDA/s220/linux-logo.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7128755548240021396.post-4874474703669804039</id><published>2010-12-28T21:15:00.001+08:00</published><updated>2010-12-28T21:15:55.836+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="bash"/><title type='text'>bash学习笔记（四）—— cut</title><content type='html'>&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;cut简介&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;cut是以每一行为一个处理对象的，这种机制和sed是一样的。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;cut命令主要是接受三个定位方法：&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;第一，字节（bytes），用选项-b&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;第二，字符（characters），用选项-c&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;第三，域（fields），用选项-f&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;以“字节”定位标志，例&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-size: small;&quot;&gt;$who&lt;br /&gt;
rocrocket :0 2009-01-08 11:07&lt;br /&gt;
rocrocket pts/0 2009-01-08 11:23 (:0.0)&lt;br /&gt;
rocrocket pts/1 2009-01-08 14:15 (:0.0)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;如果我们想提取每一行的第3个字节，就这样：&lt;br /&gt;
$ who|cut -b 3&lt;br /&gt;
c&lt;br /&gt;
c&lt;br /&gt;
c&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;如果“字节”定位中，提取第3，第4、第5和第8个字节，则：&lt;br /&gt;
$ who|cut -b 3-5,8&lt;br /&gt;
croe&lt;br /&gt;
croe&lt;br /&gt;
croe&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt; 注意，cut命令如果使用了-b选项，那么执行此命令时，cut会先把-b后面所有的定位进行从小到大排序，然后再提取。&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;以“字符”为定位标志，例：&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-size: small;&quot;&gt;$ who|cut -c 3-5,8&lt;br /&gt;
croe&lt;br /&gt;
croe&lt;br /&gt;
croe&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;不过，看着怎么和-b没有什么区别啊？莫非-b和-c作用一样? 其实不然，看似相同，只是因为这个例子举的不好，who输出的都是单字节字符，所以用-b和-c没有区别，如果你提取中文，区别就看出来了，来，看看中文提取的情况：&lt;br /&gt;
$ cat cut_ch.txt&lt;br /&gt;
星期一&lt;br /&gt;
星期二&lt;br /&gt;
星期三&lt;br /&gt;
星期四&lt;br /&gt;
[rocrocket@rocrocket programming]$ cut -b 3 cut_ch.txt&lt;br /&gt;
�&lt;br /&gt;
�&lt;br /&gt;
�&lt;br /&gt;
�&lt;br /&gt;
[rocrocket@rocrocket programming]$ cut -c 3 cut_ch.txt&lt;br /&gt;
一&lt;br /&gt;
二&lt;br /&gt;
三&lt;br /&gt;
四&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;看到了吧，用-c则会以字符为单位，输出正常；而-b只会傻傻的以字节（8位二进制位）来计算，输出就是乱码。&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;font-weight: bold;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;以“域”为定位标志：&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-size: small;&quot;&gt;为什么会有“域”的提取呢，因为刚才提到的-b和-c只能在固定格式的文档中提取信息，而对于非固定格式的信息则束手无策。这时候“域”就派上用场了。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;以/etc/passwd的前五行内容为例：&lt;br /&gt;
$ cat /etc/passwd|head -n 5&lt;br /&gt;
root:x:0:0:root:/root:/bin/bash&lt;br /&gt;
bin:x:1:1:bin:/bin:/sbin/nologin&lt;br /&gt;
daemon:x:2:2:daemon:/sbin:/sbin/nologin&lt;br /&gt;
adm:x:3:4:adm:/var/adm:/sbin/nologin&lt;br /&gt;
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin&lt;br /&gt;
$ cat /etc/passwd|head -n 5|cut -d : -f 1&lt;br /&gt;
root&lt;br /&gt;
bin&lt;br /&gt;
daemon&lt;br /&gt;
adm&lt;br /&gt;
lp&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;用-d来设置间隔符为冒号，然后用-f来设置我要取的是第一个域。&lt;br /&gt;
当然，在设定-f时，也可以使用例如3-5或者4-类似的格式：&lt;br /&gt;
$ cat /etc/passwd|head -n 5|cut -d : -f 1,3-5,7&lt;br /&gt;
root:0:0:root:/bin/bash&lt;br /&gt;
bin:1:1:bin:/sbin/nologin&lt;br /&gt;
daemon:2:2:daemon:/sbin/nologin&lt;br /&gt;
adm:3:4:adm:/sbin/nologin&lt;br /&gt;
lp:4:7:lp:/sbin/nologin&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://chennrui.blogspot.com/feeds/4874474703669804039/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://chennrui.blogspot.com/2010/12/bash-cut.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/4874474703669804039'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/4874474703669804039'/><link rel='alternate' type='text/html' href='http://chennrui.blogspot.com/2010/12/bash-cut.html' title='bash学习笔记（四）—— cut'/><author><name>big bang</name><uri>http://www.blogger.com/profile/07380722230385048574</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQEwGR3hniNIaoAuRxuoFMsyO_esdj85N9t60Bj4qln24_y7qj8mnx8taxn-KrBbc2zQBfJviUXvScqSs7OD3zJBpP5wimbihfo-Y9yHnpYezKHlkxxt5YRkQ2wyrFDA/s220/linux-logo.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7128755548240021396.post-5835967828352428425</id><published>2010-12-28T21:12:00.000+08:00</published><updated>2010-12-28T21:13:08.432+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="bash"/><title type='text'>bash学习笔记（三）—— 基本语法</title><content type='html'>&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;变量，判断，重复动作&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;参数展开是shell&lt;span style=&quot;font-size: small;&quot;&gt;提供变量值在程序中使用的过程。如&lt;/span&gt;&lt;/span&gt;：&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;aa=&quot;hello word&quot;&lt;br /&gt;
sleep 10&lt;br /&gt;
echo $aa 或 &quot;$aa&quot;&lt;br /&gt;
变量展开需用&quot;&quot;,如果改为&#39;&#39;,则不会展开。echo &#39;$aa&#39;,输出为&#39;$aa&#39;&lt;br /&gt;
&lt;br /&gt;
替换运算符&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;table bgcolor=&quot;#f1f1f1&quot; border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;$&lt;span style=&quot;color: #0000cc;&quot;&gt;{&lt;/span&gt;varname&lt;span style=&quot;color: #0000cc;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;word&lt;span style=&quot;color: #0000cc;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
如果varname存在且非null&lt;span style=&quot;color: #0000cc;&quot;&gt;,&lt;/span&gt;则返回其值；否则，返回word。例，如果count未定义，则$&lt;span style=&quot;color: #0000cc;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;count&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;0&lt;span style=&quot;color: #0000cc;&quot;&gt;}&lt;/span&gt;返回0。&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;br /&gt;
&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;$&lt;span style=&quot;color: #0000cc;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;{varname:=word}&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
如果varname存在且非null&lt;span style=&quot;color: #0000cc;&quot;&gt;,&lt;/span&gt;则返回其值；否则，varname=word。&lt;span style=&quot;color: #0000cc;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;${varname:?message}&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;如果varname存在且不是null,则返回它的值；否则，显示varname:message后退出脚本。&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;$&lt;span style=&quot;color: #0000cc;&quot;&gt;{&lt;/span&gt;varname&lt;span style=&quot;color: #0000cc;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;+&lt;/span&gt;word&lt;span style=&quot;color: #0000cc;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;如果varname存在且非null&lt;span style=&quot;color: #0000cc;&quot;&gt;,&lt;/span&gt;则返回word;否则，返回null。例，如果count已定义，则${count:+1}返回1。&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;br /&gt;
&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;ps:上述运算符内的冒号都是可选的。如果去掉则将定义中的存在且非null改为存在，即运算符仅用于测试变量是否存在。&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;模式匹配运算符&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;table bgcolor=&quot;#f1f1f1&quot; border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;$&lt;span style=&quot;color: #0000cc;&quot;&gt;{&lt;/span&gt;var&lt;span style=&quot;color: #0000cc;&quot;&gt;#&lt;/span&gt;pattern&lt;span style=&quot;color: #0000cc;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
如果模式匹配于变量值的开头处，则删除匹配的最短部分，并返回剩下部分。&lt;br /&gt;
&lt;br /&gt;
$&lt;span style=&quot;color: #0000cc;&quot;&gt;{&lt;/span&gt;var&lt;span style=&quot;color: #0000cc;&quot;&gt;##&lt;/span&gt;pattern&lt;span style=&quot;color: #0000cc;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
如果模式匹配于变量值的开头处，则删除匹配的最长部分，并返回剩下部分。&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;br /&gt;
&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;$&lt;span style=&quot;color: #0000cc;&quot;&gt;{&lt;/span&gt;var&lt;span style=&quot;color: #0000cc;&quot;&gt;%&lt;/span&gt;pattern&lt;span style=&quot;color: #0000cc;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
如果模式匹配于变量值的结尾处，则删除匹配的最短部分，并返回剩下部分。&lt;br /&gt;
&lt;br /&gt;
$&lt;span style=&quot;color: #0000cc;&quot;&gt;{&lt;/span&gt;var&lt;span style=&quot;color: #0000cc;&quot;&gt;%%&lt;/span&gt;pattern&lt;span style=&quot;color: #0000cc;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
如果模式匹配于变量值的结尾处，则删除匹配的最长部分，并返回剩下部分。&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;br /&gt;
&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;例：&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;path=/home/tolstoy/mem/long.file.name&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;${path#/*/} 结果： &lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;tolstoy/mem/long.file.name&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;${path##/*/} 结果：&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;long.file.name&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;${path%.*} 结果：&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;/home/tolstoy/mem/long.file&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;${path%％.*} 结果：&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;/home/tolstoy/mem/long&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;字符串操作：&lt;br /&gt;
&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;${#path} : 返回变量的字符串长度, 为32&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;/code&gt;${string:position:length},例&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;{path:6:11} : 返回6－11字符串：tolstoy/mem&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;${string/substring/replacement}&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;Replace first &lt;i class=&quot;FIRSTTERM&quot;&gt;match&lt;/i&gt; of      &lt;tt class=&quot;REPLACEABLE&quot;&gt;&lt;i&gt;$substring&lt;/i&gt;&lt;/tt&gt; with      &lt;tt class=&quot;REPLACEABLE&quot;&gt;&lt;i&gt;$replacement&lt;/i&gt;&lt;/tt&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;${string//substring/replacement}&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;Replace all matches of      &lt;tt class=&quot;REPLACEABLE&quot;&gt;&lt;i&gt;$substring&lt;/i&gt;&lt;/tt&gt; with      &lt;tt class=&quot;REPLACEABLE&quot;&gt;&lt;i&gt;$replacement&lt;/i&gt;&lt;/tt&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;特殊变量： 例&lt;/span&gt;&lt;br /&gt;
&lt;table bgcolor=&quot;#f1f1f1&quot; border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;$ &lt;span style=&quot;color: red;&quot;&gt;set&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt; hello &lt;span style=&quot;color: magenta;&quot;&gt;&quot;hi there&quot;&lt;/span&gt; greetings&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        设置新的位置参数&lt;br /&gt;
$ echo there are $&lt;span style=&quot;color: #0000cc;&quot;&gt;#&lt;/span&gt; total arguments&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        显示计数值&lt;br /&gt;
there are 3 total arguments&lt;br /&gt;
$ &lt;span style=&quot;color: blue;&quot;&gt;for&lt;/span&gt; i in $&lt;span style=&quot;color: #0000cc;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;or&lt;/span&gt; $@&lt;span style=&quot;color: #0000cc;&quot;&gt;)&lt;/span&gt;&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;           $&lt;span style=&quot;color: #0000cc;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;@&lt;/span&gt;一次表示所有的命令行参数 &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;do&lt;/span&gt; echo i is $i&lt;br /&gt;
&amp;nbsp;&amp;nbsp;done&lt;br /&gt;
i is hello&lt;br /&gt;
i is hi&lt;br /&gt;
i is there&lt;br /&gt;
i is greetings&lt;br /&gt;
$ &lt;span style=&quot;color: blue;&quot;&gt;for&lt;/span&gt; i in &lt;span style=&quot;color: magenta;&quot;&gt;&quot;$@&quot;&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;    &lt;span style=&quot;color: magenta;&quot;&gt;&quot;$@&quot;&lt;/span&gt;将所有命令行参数视为单个字符串，即&lt;span style=&quot;color: magenta;&quot;&gt;&quot;$1 $2&quot;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;do&lt;/span&gt; echo i is $i&lt;br /&gt;
&amp;nbsp;&amp;nbsp;done&lt;br /&gt;
i is hello&lt;br /&gt;
i is hi there&lt;br /&gt;
i is greetings&lt;br /&gt;
$ shift &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;                                   去除第一个参数&lt;br /&gt;
$ echo there are $&lt;span style=&quot;color: #0000cc;&quot;&gt;#&lt;/span&gt; total arguments&lt;br /&gt;
there are 2 total arguments&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: small; font-weight: bold;&quot;&gt;if-elif-else-fi基本语法：例&lt;/span&gt;&lt;br /&gt;
&lt;table bgcolor=&quot;#f1f1f1&quot; border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;pre class=&quot;programlisting&quot;&gt;#! /bin/bash

echo &quot;Is it morning? Please answer yes or no.&quot;
read YES_OR_NO                   #输入value
if [ &quot;$YES_OR_NO&quot; = &quot;yes&quot; ]; then
  echo &quot;Good morning!&quot;
elif [ &quot;$YES_OR_NO&quot; = &quot;no&quot; ]; then
  echo &quot;Good afternoon!&quot;
else
  echo &quot;Sorry, $YES_OR_NO not recognized. Enter yes or no.&quot;
  exit 1
fi
exit 0

ps: &quot;［］&quot;为判断语句，返回1或0。if [pipeline] 等价于 if test pipeline。&lt;/pre&gt;&lt;pre class=&quot;programlisting&quot;&gt;因此可在［］中加入test的各种参数。
如：
&lt;span style=&quot;font-weight: bold;&quot;&gt;if [ -f &quot;$file&quot; ] &amp;amp;&amp;amp; [ ! -x &quot;$file&quot; ]&lt;/span&gt;; then
    echo $file is a file but cannot execute
elif [ -d &quot;$file&quot; ]; then
    echo $file is a directory
fi
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: small; font-weight: bold;&quot;&gt;case/esac基本语法：&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;code class=&quot;literal&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; case&lt;/code&gt;命令可类比C语言的&lt;code class=&quot;literal&quot;&gt;switch&lt;/code&gt;/&lt;code class=&quot;literal&quot;&gt;case&lt;/code&gt;语句，&lt;code class=&quot;literal&quot;&gt;esac&lt;/code&gt;表示&lt;code class=&quot;literal&quot;&gt;case&lt;/code&gt;语句块的结束。C语言的&lt;code class=&quot;literal&quot;&gt;case&lt;/code&gt;只能匹配整型或字符型常量表达式，而Shell脚本的&lt;code class=&quot;literal&quot;&gt;case&lt;/code&gt;可以匹配字符串和Wildcard，每个匹配分支可以有若干条命令，末尾必须以;;结束，执行时找到第一个匹配的分支并执行相应的命令，然后直接跳到&lt;code class=&quot;literal&quot;&gt;esac&lt;/code&gt;之后，不需要像C语言一样用&lt;code class=&quot;literal&quot;&gt;break&lt;/code&gt;跳出。&lt;/span&gt;&lt;br /&gt;
&lt;table bgcolor=&quot;#f1f1f1&quot; border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;!&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;/&lt;/span&gt;bin&lt;span style=&quot;color: #0000cc;&quot;&gt;/&lt;/span&gt;bash&lt;br /&gt;
&lt;br /&gt;
echo &lt;span style=&quot;color: magenta;&quot;&gt;&quot;Is it morning? Please answer yes or no.&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;read&lt;/span&gt; YES_OR_NO&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: magenta;&quot;&gt;&quot;$YES_OR_NO&quot;&lt;/span&gt; in&lt;br /&gt;
yes&lt;span style=&quot;color: #0000cc;&quot;&gt;|&lt;/span&gt;y&lt;span style=&quot;color: #0000cc;&quot;&gt;|&lt;/span&gt;Yes&lt;span style=&quot;color: #0000cc;&quot;&gt;|&lt;/span&gt;YES&lt;span style=&quot;color: #0000cc;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;echo &lt;span style=&quot;color: magenta;&quot;&gt;&quot;Good Morning!&quot;&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000cc;&quot;&gt;[&lt;/span&gt;nN&lt;span style=&quot;color: #0000cc;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;[oO]&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;echo &lt;span style=&quot;color: magenta;&quot;&gt;&quot;Good Afternoon!&quot;&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000cc;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;echo &lt;span style=&quot;color: magenta;&quot;&gt;&quot;Sorry, $YES_OR_NO not recognized. Enter yes or no.&quot;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;exit&lt;/span&gt; 1&lt;span style=&quot;color: #0000cc;&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;
esac&lt;span style=&quot;color: red;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: small; font-weight: bold;&quot;&gt;for/in/do/done基本语法：例&lt;/span&gt;&lt;br /&gt;
&lt;table bgcolor=&quot;#f1f1f1&quot; border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;!&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;/&lt;/span&gt;bin&lt;span style=&quot;color: #0000cc;&quot;&gt;/&lt;/span&gt;bash&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;for&lt;/span&gt; FRUIT (in apple banana pear)&lt;span style=&quot;color: #0000cc;&quot;&gt;;&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;do&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;echo &lt;span style=&quot;color: magenta;&quot;&gt;&quot;I like $FRUIT&quot;&lt;/span&gt;&lt;br /&gt;
done&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;ps: 如果未写()中内容，则默认执行 for FRUIT in &quot;$#&quot;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: small; font-weight: bold;&quot;&gt;while/do/done基本语法：例&lt;/span&gt;&lt;br /&gt;
&lt;table bgcolor=&quot;#f1f1f1&quot; border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;!&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;/&lt;/span&gt;bin&lt;span style=&quot;color: #0000cc;&quot;&gt;/&lt;/span&gt;sh&lt;br /&gt;
&lt;br /&gt;
echo &lt;span style=&quot;color: magenta;&quot;&gt;&quot;Enter password:&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;read&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;TRY&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;while&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;[&lt;/span&gt; &lt;span style=&quot;color: magenta;&quot;&gt;&quot;$TRY&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: magenta;&quot;&gt;&quot;secret&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;;&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;do&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;echo &lt;span style=&quot;color: magenta;&quot;&gt;&quot;Sorry, try again&quot;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;read&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;TRY&lt;/span&gt;&lt;br /&gt;
done&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://chennrui.blogspot.com/feeds/5835967828352428425/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://chennrui.blogspot.com/2010/12/bash_28.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/5835967828352428425'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/5835967828352428425'/><link rel='alternate' type='text/html' href='http://chennrui.blogspot.com/2010/12/bash_28.html' title='bash学习笔记（三）—— 基本语法'/><author><name>big bang</name><uri>http://www.blogger.com/profile/07380722230385048574</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQEwGR3hniNIaoAuRxuoFMsyO_esdj85N9t60Bj4qln24_y7qj8mnx8taxn-KrBbc2zQBfJviUXvScqSs7OD3zJBpP5wimbihfo-Y9yHnpYezKHlkxxt5YRkQ2wyrFDA/s220/linux-logo.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7128755548240021396.post-424410540254428603</id><published>2010-12-28T21:08:00.000+08:00</published><updated>2010-12-28T21:14:08.318+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="bash"/><title type='text'>bash学习笔记（二）—— grep, sed</title><content type='html'>&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;文本过滤工具grep&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;传统的 grep 程序&lt;span style=&quot;color: #0000cc;&quot;&gt;,&lt;/span&gt; 在没有参数的情况下&lt;span style=&quot;color: #0000cc;&quot;&gt;,&lt;/span&gt; 只输出符合 RE 字符串之句子&lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt; 常见参数如下&lt;span style=&quot;color: #0000cc;&quot;&gt;:&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;table bgcolor=&quot;#f1f1f1&quot; border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;line-height: 150%; margin: 5px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;v&lt;span style=&quot;color: #0000cc;&quot;&gt;:&lt;/span&gt; 逆反模示&lt;span style=&quot;color: #0000cc;&quot;&gt;,&lt;/span&gt; 只输出&lt;span style=&quot;color: magenta;&quot;&gt;&quot;不含&quot;&lt;/span&gt; RE 字符串之句子&lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;r&lt;span style=&quot;color: #0000cc;&quot;&gt;:&lt;/span&gt; 递归模式&lt;span style=&quot;color: #0000cc;&quot;&gt;,&lt;/span&gt; 可同时处理所有层级子目录里的文件&lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;q&lt;span style=&quot;color: #0000cc;&quot;&gt;:&lt;/span&gt; 静默模式&lt;span style=&quot;color: #0000cc;&quot;&gt;,&lt;/span&gt; 不输出任何结果&lt;span style=&quot;color: #0000cc;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;stderr&lt;/span&gt; 除外&lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt; 常用以获取 &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; value&lt;span style=&quot;color: #0000cc;&quot;&gt;,&lt;/span&gt; 符合为 &lt;span style=&quot;color: blue;&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;,&lt;/span&gt; 否则为 &lt;span style=&quot;color: blue;&quot;&gt;false&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;i&lt;span style=&quot;color: #0000cc;&quot;&gt;:&lt;/span&gt; 忽略大小写&lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;w&lt;span style=&quot;color: #0000cc;&quot;&gt;:&lt;/span&gt; 整词比对&lt;span style=&quot;color: #0000cc;&quot;&gt;,&lt;/span&gt; 类似 \&lt;span style=&quot;color: #0000cc;&quot;&gt;&amp;lt;&lt;/span&gt;word\&lt;span style=&quot;color: #0000cc;&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;n&lt;span style=&quot;color: #0000cc;&quot;&gt;:&lt;/span&gt; 同时输出行号&lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;c&lt;span style=&quot;color: #0000cc;&quot;&gt;:&lt;/span&gt; 只输出符合比对的行数&lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;l&lt;span style=&quot;color: #0000cc;&quot;&gt;:&lt;/span&gt; 只输出符合比对的文件名称&lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;o&lt;span style=&quot;color: #0000cc;&quot;&gt;:&lt;/span&gt; 只输出符合 RE 的字符串&lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;(&lt;/span&gt;gnu 新版独有&lt;span style=&quot;color: #0000cc;&quot;&gt;,&lt;/span&gt; 不见得所有版本都支持&lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt;E&lt;span style=&quot;color: #0000cc;&quot;&gt;:&lt;/span&gt; 切换为 egrep &lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #0000cc;&quot;&gt;*&lt;/span&gt; egrep&lt;span style=&quot;color: #0000cc;&quot;&gt;:&lt;/span&gt;&lt;br /&gt;
为 grep 的扩充版本&lt;span style=&quot;color: #0000cc;&quot;&gt;,&lt;/span&gt; 改良了许多传统 grep 不能或不便的操作&lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt; 比方说&lt;span style=&quot;color: #0000cc;&quot;&gt;:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt; grep 之下不支持 &lt;span style=&quot;color: #0000cc;&quot;&gt;?&lt;/span&gt; 与 &lt;span style=&quot;color: #0000cc;&quot;&gt;+&lt;/span&gt; 这两种 modifier&lt;span style=&quot;color: #0000cc;&quot;&gt;,&lt;/span&gt; 但 egrep 则可&lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt; grep 不支持 a&lt;span style=&quot;color: #0000cc;&quot;&gt;|&lt;/span&gt;b 或 &lt;span style=&quot;color: #0000cc;&quot;&gt;(&lt;/span&gt;abc&lt;span style=&quot;color: #0000cc;&quot;&gt;|&lt;/span&gt;xyz&lt;span style=&quot;color: #0000cc;&quot;&gt;)&lt;/span&gt; 这类&lt;span style=&quot;color: magenta;&quot;&gt;&quot;或一&quot;&lt;/span&gt;比对&lt;span style=&quot;color: #0000cc;&quot;&gt;,&lt;/span&gt; 但 egrep 则可&lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000cc;&quot;&gt;-&lt;/span&gt; grep 在处理 &lt;span style=&quot;color: #0000cc;&quot;&gt;{&lt;/span&gt;n&lt;span style=&quot;color: #0000cc;&quot;&gt;,&lt;/span&gt;m&lt;span style=&quot;color: #0000cc;&quot;&gt;}&lt;/span&gt; 时&lt;span style=&quot;color: #0000cc;&quot;&gt;,&lt;/span&gt; 需用 \&lt;span style=&quot;color: #0000cc;&quot;&gt;{&lt;/span&gt; 与 \&lt;span style=&quot;color: #0000cc;&quot;&gt;}&lt;/span&gt; 处理&lt;span style=&quot;color: #0000cc;&quot;&gt;,&lt;/span&gt; 但 egrep 则不需&lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;
诸如此类的&lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;.&lt;/span&gt; 我个人会建议能用 egrep 就不用 grep 啦&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;grep的一般格式为：&lt;br /&gt;
&amp;nbsp;&amp;nbsp; grep [选项]基本正则表达式[文件]。&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;在grep命令中输入字符串参数时，最好将其用双引号括起来。在调用模式匹配时，应使用单引号。&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;b&gt;&lt;/b&gt;例如：&quot;mystring&quot;。这样做有两个原因，一是以防被误解为shell命令，二是可以用来查找多个单词组成的字符串。在调用变量时，也应该使用双引号，诸如:grep &quot;$myvar&quot; file，如果不这样，将没有返回结果。&lt;br /&gt;
模式匹配:grep &#39;ab\{1,5\}&#39; file。这样可以防止grep中使用的专有模式与一些shell命令的特殊方式相混淆。&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;在文本文件里进行替换&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;1. Sed简介&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;sed是一种在线编辑器，它一次处理一行内容。处理时，把当前处理的行存储在临时缓冲区中，称为“模式空间”（pattern  space），接着用sed命令处理缓冲区中的内容，处理完成后，把缓冲区的内容送往屏幕。接着处理下一行，这样不断重复，直到文件末尾。文件内容并没有  改变，除非你使用重定向存储输出。Sed主要用来自动编辑一个或多个文件；简化对文件的反复操作；编写转换程序等。以下介绍的是Gnu版本的Sed  3.02。&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;2. 定址&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;可以通过定址来定位你所希望编辑的行，该地址用数字构成，用逗号分隔的两个行数表示以这两行为起止的行的范围（包括行数表示的那两行）。如1，3表示1，2，3行，美元符号($)表示最后一行。范围可以通过数据，正则表达式或者二者结合的方式确定 。&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;3. Sed命令&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;调用sed命令有两种形式：&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
sed [options] &#39;command&#39; file(s)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;sed [options] -f scriptfile file(s)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&amp;lt; &lt;br /&gt;
a\ &lt;br /&gt;
在当前行后面加入一行文本。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;b lable &lt;br /&gt;
分支到脚本中带有标记的地方，如果分支不存在则分支到脚本的末尾。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;c\ &lt;br /&gt;
用新的文本改变本行的文本。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;d &lt;br /&gt;
从模板块（Pattern space）位置删除行。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;D &lt;br /&gt;
删除模板块的第一行。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;i\ &lt;br /&gt;
在当前行上面插入文本。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;h &lt;br /&gt;
拷贝模板块的内容到内存中的缓冲区。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;H &lt;br /&gt;
追加模板块的内容到内存中的缓冲区&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;g &lt;br /&gt;
获得内存缓冲区的内容，并替代当前模板块中的文本。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;G &lt;br /&gt;
获得内存缓冲区的内容，并追加到当前模板块文本的后面。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;l &lt;br /&gt;
列表不能打印字符的清单。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;n &lt;br /&gt;
读取下一个输入行，用下一个命令处理新的行而不是用第一个命令。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;N &lt;br /&gt;
追加下一个输入行到模板块后面并在二者间嵌入一个新行，改变当前行号码。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;p &lt;br /&gt;
打印模板块的行。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;P（大写） &lt;br /&gt;
打印模板块的第一行。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;q &lt;br /&gt;
退出Sed。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;r file &lt;br /&gt;
从file中读行。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;t label &lt;br /&gt;
if分支，从最后一行开始，条件一旦满足或者T，t命令，将导致分支到带有标号的命令处，或者到脚本的末尾。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;T label &lt;br /&gt;
错误分支，从最后一行开始，一旦发生错误或者T，t命令，将导致分支到带有标号的命令处，或者到脚本的末尾。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;w file &lt;br /&gt;
写并追加模板块到file末尾。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;W file &lt;br /&gt;
写并追加模板块的第一行到file末尾。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;! &lt;br /&gt;
表示后面的命令对所有没有被选定的行发生作用。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;s/re/string &lt;br /&gt;
用string替换正则表达式re。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;= &lt;br /&gt;
打印当前行号码。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;# &lt;br /&gt;
把注释扩展到下一个换行符以前。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;以下的是替换标记&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;g表示行内全面替换。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;p表示打印行。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;w表示把行写入一个文件。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;x表示互换模板块中的文本和缓冲区中的文本。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;y表示把一个字符翻译为另外的字符（但是不用于正则表达式）&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;4. 选项&lt;br /&gt;
&amp;lt; &lt;br /&gt;
-e command, --expression=command &lt;br /&gt;
允许多台编辑。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;-h, --help &lt;br /&gt;
打印帮助，并显示bug列表的地址。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;-n, --quiet, --silent &lt;br /&gt;
取消默认输出。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;-f, --filer=script-file &lt;br /&gt;
引导sed脚本文件名。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;-V, --version &lt;br /&gt;
打印版本和版权信息。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
5. 元字符集&lt;br /&gt;
&amp;lt; &lt;br /&gt;
^ &lt;br /&gt;
锚定行的开始 如：/^sed/匹配所有以sed开头的行。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;$ &lt;br /&gt;
锚定行的结束 如：/sed$/匹配所有以sed结尾的行。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;. &lt;br /&gt;
匹配一个非换行符的字符 如：/s.d/匹配s后接一个任意字符，然后是d。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;* &lt;br /&gt;
匹配零或多个字符 如：/*sed/匹配所有模板是一个或多个空格后紧跟sed的行。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;[] &lt;br /&gt;
匹配一个指定范围内的字符，如/[Ss]ed/匹配sed和Sed。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;[^] &lt;br /&gt;
匹配一个不在指定范围内的字符，如：/[^A-RT-Z]ed/匹配不包含A-R和T-Z的一个字母开头，紧跟ed的行。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;\(..\) &lt;br /&gt;
保存匹配的字符，如s/\(love\)able/\1rs，loveable被替换成lovers。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&amp;amp; &lt;br /&gt;
保存搜索字符用来替换其他字符，如s/love/**&amp;amp;**/，love这成**love**。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;\&amp;lt; &lt;br /&gt;
锚定单词的开始，如:/\&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;\&amp;gt; &lt;br /&gt;
锚定单词的结束，如/love\&amp;gt;/匹配包含以love结尾的单词的行。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;x\{m\} &lt;br /&gt;
重复字符x，m次，如：/0\{5\}/匹配包含5个o的行。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;x\{m,\} &lt;br /&gt;
重复字符x,至少m次，如：/o\{5,\}/匹配至少有5个o的行。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;x\{m,n\} &lt;br /&gt;
重复字符x，至少m次，不多于n次，如：/o\{5,10\}/匹配5--10个o的行。&lt;/span&gt;&lt;br /&gt;
6. 实例&lt;br /&gt;
删除：d命令 &lt;br /&gt;
$ sed &#39;2d&#39; example-----删除example文件的第二行。&lt;br /&gt;
$ sed &#39;2,$d&#39; example-----删除example文件的第二行到末尾所有行。&lt;br /&gt;
$ sed &#39;$d&#39; example-----删除example文件的最后一行。&lt;br /&gt;
$ sed &#39;/test/&#39;d example-----删除example文件所有包含test的行。&lt;br /&gt;
替换：s命令 &lt;br /&gt;
$ sed &#39;s/test/mytest/g&#39; example-----在整行范围内把test替换为mytest。如果没有g标记，则只有每行第一个匹配的test被替换成mytest。&lt;br /&gt;
$ sed -n &#39;s/^test/mytest/p&#39; example-----(-n)选项和p标志一起使用表示只打印那些发生替换的行。也就是说，如果某一行开头的test被替换成mytest，就打印它。&lt;br /&gt;
$ sed &#39;s/^192.168.0.1/&amp;amp;localhost/&#39;  example-----&amp;amp;符号表示替换换字符串中被找到的部份。所有以192.168.0.1开头的行都会被替换成它自已加  localhost，变成192.168.0.1localhost。&lt;br /&gt;
$ sed &#39;s/hello/&amp;amp; chen/&#39; example-----hello rui替换为hello chen rui。＆被标记为查找内容hello。&lt;br /&gt;
$ sed -n &#39;s/\(love\)able/\1rs/p&#39; example-----love被标记为1，所有loveable会被替换成lovers，而且替换的行会被打印出来。&lt;br /&gt;
$ sed &#39;s#10#100#g&#39; example-----不论什么字符，紧跟着s命令的都被认为是新的分隔符，所以，“#”在这里是分隔符，代替了默认的“/”分隔符。表示把所有10替换成100。&lt;br /&gt;
选定行的范围：逗号 &lt;br /&gt;
$ sed -n &#39;/test/,/check/p&#39; example-----所有在模板test和check所确定的范围内的行都被打印。&lt;br /&gt;
$ sed -n &#39;5,/^test/p&#39; example-----打印从第五行开始到第一个包含以test开始的行之间的所有行。&lt;br /&gt;
$ sed &#39;/test/,/check/s/$/sed test/&#39; example-----对于模板test和west之间的行，每行的末尾用字符串sed test替换。&lt;br /&gt;
多点编辑：e命令 &lt;br /&gt;
$ sed -e &#39;1,5d&#39; -e &#39;s/test/check/&#39;  example-----(-e)选项允许在同一行里执行多条命令。如例子所示，第一条命令删除1至5行，第二条命令用check替换test。命令的执  行顺序对结果有影响。如果两个命令都是替换命令，那么第一个替换命令将影响第二个替换命令的结果。&lt;br /&gt;
$ sed --expression=&#39;s/test/check/&#39; --expression=&#39;/love/d&#39; example-----一个比-e更好的命令是--expression。它能给sed表达式赋值。&lt;br /&gt;
从文件读入：r命令 &lt;br /&gt;
$ sed &#39;/test/r file&#39; example-----file里的内容被读进来，显示在与test匹配的行后面，如果匹配多行，则file的内容将显示在所有匹配行的下面。&lt;br /&gt;
写入文件：w命令 &lt;br /&gt;
$ sed -n &#39;/test/w file&#39; example-----在example中所有包含test的行都被写入file里。&lt;br /&gt;
&lt;br /&gt;
追加命令：a命令 &lt;br /&gt;
$ sed &#39;/^test/a\\---&amp;gt;this is a example&#39; example&amp;lt;-----&#39;this is a example&#39;被追加到以test开头的行后面，sed要求命令a后面有一个反斜杠。&lt;br /&gt;
插入：i命令 &lt;br /&gt;
$ sed &#39;/test/i\\&lt;br /&gt;
new line&lt;br /&gt;
-------------------------&#39; example&lt;br /&gt;
如果test被匹配，则把反斜杠后面的文本插入到匹配行的前面。&lt;br /&gt;
下一个：n命令 &lt;br /&gt;
$ sed &#39;/test/{ n; s/aa/bb/; }&#39; example-----如果test被匹配，则移动到匹配行的下一行，替换这一行的aa，变为bb，并打印该行，然后继续。&lt;br /&gt;
变形：y命令 &lt;br /&gt;
$ sed &#39;1,10y/abcde/ABCDE/&#39; example-----把1--10行内所有abcde转变为大写，注意，正则表达式元字符不能使用这个命令。&lt;br /&gt;
退出：q命令 &lt;br /&gt;
$ sed &#39;10q&#39; example-----打印完第10行后，退出sed。&lt;br /&gt;
保持和获取：h命令和G命令 &lt;br /&gt;
$ sed -e &#39;/test/h&#39; -e &#39;$G  example-----在sed处理文件的时候，每一行都被保存在一个叫模式空间的临时缓冲区中，除非行被删除或者输出被取消，否则所有被处理的行都将   打印在屏幕上。接着模式空间被清空，并存入新的一行等待处理。在这个例子里，匹配test的行被找到后，将存入模式空间，h命令将其复制并存入一个称为保   持缓存区的特殊缓冲区内。第二条语句的意思是，当到达最后一行后，G命令取出保持缓冲区的行，然后把它放回模式空间中，且追加到现在已经存在于模式空间中  的行的末尾。在这个例子中就是追加到最后一行。简单来说，任何包含test的行都被复制并追加到该文件的末尾。&lt;br /&gt;
保持和互换：h命令和x命令 &lt;br /&gt;
$ sed -e &#39;/test/h&#39; -e &#39;/check/x&#39; example -----互换模式空间和保持缓冲区的内容。也就是把包含test与check的行互换。&lt;br /&gt;
7. 脚本&lt;br /&gt;
Sed脚本是一个sed的命令清单，启动Sed时以-f选项引导脚本文件名。Sed对于脚本中输入的命令非常挑剔，在命令的末尾不能有任何空白或文本，如果在一行中有多个命令，要用分号分隔。以#开头的行为注释行，且不能跨行。&lt;br /&gt;
&lt;br /&gt;
比如，如果要打印出含有字串”1024”的行，我就可能会用：&lt;br /&gt;
cat filename | sed –n ‘/1024/p’sed命令详解!!(要学习shell的 朋友要好好看看)&lt;br /&gt;
sed /^$/d filename&lt;br /&gt;
可以删除文件中的空行。&lt;br /&gt;
sed /^[[:space:]]*$/d filename&lt;br /&gt;
可以删除内容为多个空格/tab组成的行。</content><link rel='replies' type='application/atom+xml' href='http://chennrui.blogspot.com/feeds/424410540254428603/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://chennrui.blogspot.com/2010/12/bash-grep-sed.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/424410540254428603'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/424410540254428603'/><link rel='alternate' type='text/html' href='http://chennrui.blogspot.com/2010/12/bash-grep-sed.html' title='bash学习笔记（二）—— grep, sed'/><author><name>big bang</name><uri>http://www.blogger.com/profile/07380722230385048574</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQEwGR3hniNIaoAuRxuoFMsyO_esdj85N9t60Bj4qln24_y7qj8mnx8taxn-KrBbc2zQBfJviUXvScqSs7OD3zJBpP5wimbihfo-Y9yHnpYezKHlkxxt5YRkQ2wyrFDA/s220/linux-logo.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7128755548240021396.post-4284996662709676639</id><published>2010-12-28T21:06:00.000+08:00</published><updated>2010-12-28T21:06:16.850+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="bash"/><title type='text'>bash学习笔记（一）——正则表达式</title><content type='html'>脚本第一行的#!&lt;br /&gt;
由于系统拥有好几个shell，因此需要通过一种方式告知UNIX内核应该以哪个shell来执行指定的shell脚本。指定方法是，通过脚本文件中特殊的第一行来设置，如：#!/bin/bash。&lt;br /&gt;
&lt;br /&gt;
重定向&lt;br /&gt;
&amp;lt;： 改变标准输入     &amp;gt;： 改变标准输出，如果存在同名文件则覆盖，不存在则创建&lt;br /&gt;
&lt;br /&gt;
tr -d &#39;a&#39; &amp;lt; tmp1.txt &amp;gt; tmp2.txt，  此命令表示用ｔｍｐ１作为输入执行tr -d命令并将结果输出到ｔｍｐ２中。&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;:　作用同&amp;gt;,但其不会覆盖同名文件而是追加。&lt;br /&gt;
&lt;br /&gt;
｜：管道连接符，可将不同的命令连接起来。&lt;br /&gt;
&lt;br /&gt;
Ｓｈｅｌｌ脚本参数&lt;br /&gt;
shell脚本的命令行参数都是由整数命名，当它超过9，就应该用大括号把数字框起来。例:&lt;br /&gt;
&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
echo first arg is $1&lt;br /&gt;
echo tenth arg is ${10}&lt;br /&gt;
如需要调试脚本，可在#!/bin/bash后加上 -ｘ/+ｘ来打开/关闭跟踪功能。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
正则表达式&lt;br /&gt;
metacharacter:&lt;br /&gt;
\&lt;br /&gt;
将下一个字符标记为一个特殊字符、或一个原义字符、或一个 后向引用、或一个八进制转义符。例如，&#39;n&#39; 匹配字符 &quot;n&quot;。&#39;\n&#39; 匹配一个换行符。序列 &#39;\\&#39; 匹配 &quot;\&quot; 而 &quot;\(&quot; 则匹配 &quot;(&quot;。&lt;br /&gt;
&lt;br /&gt;
^&lt;br /&gt;
匹配输入字符串的开始位置。&lt;br /&gt;
&lt;br /&gt;
$&lt;br /&gt;
匹配输入字符串的结束位置。&lt;br /&gt;
&lt;br /&gt;
*&lt;br /&gt;
匹配前面的子表达式零次或多次。例如，zo* 能匹配 &quot;z&quot; 以及 &quot;zoo&quot;。 * 等价于{0,}。&lt;br /&gt;
&lt;br /&gt;
+&lt;br /&gt;
匹配前面的子表达式一次或多次。例如，&#39;zo+&#39; 能匹配 &quot;zo&quot; 以及 &quot;zoo&quot;，但不能匹配 &quot;z&quot;。+ 等价于 {1,}。&lt;br /&gt;
&lt;br /&gt;
?&lt;br /&gt;
匹配前面的子表达式零次或一次。例如，&quot;do(es)?&quot; 可以匹配 &quot;do&quot; 或 &quot;does&quot; 中的&quot;do&quot; 。? 等价于 {0,1}。&lt;br /&gt;
&lt;br /&gt;
[]&lt;br /&gt;
匹配括号中的一个字符。例，[abc]表示匹配a,b或c&lt;br /&gt;
&lt;br /&gt;
\(\)&lt;br /&gt;
将\(与\)间的模式存储在保留空间。最多可将9个独立的子模式存储在单个模式中。匹配于子模式的文本，可通过转义序列\1至\9被重复使用在相同模式里。例如，\(ab\)\(cd\)*\2\1,表示abcd*cdab。 \([&quot;&#39;]\).*\1,表示&quot;&quot;和&#39;&#39;。&lt;br /&gt;
&lt;br /&gt;
\{n,m\}&lt;br /&gt;
&lt;br /&gt;
区间表达式，匹配在它前面的单个字符重现的次数区间。\{ｎ\}指重现ｎ次；\{ｎ,\}指至少重现ｎ次；\{ｎ,ｍ\}指重现ｎ至ｍ次。ｎ,ｍ的值必须介于0－255。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
POSIX 字符类. [:class:]&lt;br /&gt;
&lt;br /&gt;
这是另外一个可选的用于指定匹配字符范围的方法。&lt;br /&gt;
&lt;br /&gt;
*&lt;br /&gt;
&lt;br /&gt;
[:alnum:] 匹配字母和数字.等同于A-Za-z0-9.&lt;br /&gt;
*&lt;br /&gt;
&lt;br /&gt;
[:alpha:] 匹配字母. 等同于A-Za-z.&lt;br /&gt;
*&lt;br /&gt;
&lt;br /&gt;
[:blank:] 匹配一个空格或是一个制表符(tab).&lt;br /&gt;
*&lt;br /&gt;
&lt;br /&gt;
[:cntrl:] 匹配控制字符.&lt;br /&gt;
*&lt;br /&gt;
&lt;br /&gt;
[:digit:] 匹配(十进制)数字. 等同于0-9.&lt;br /&gt;
*&lt;br /&gt;
&lt;br /&gt;
[:graph:] (可打印的图形字符). 匹配 ASCII 码值的33 - 126之间的字符. 这和下面提到的 [:print:]一样,但是不包括空格字符.&lt;br /&gt;
*&lt;br /&gt;
&lt;br /&gt;
[:lower:] 匹配小写字母. 等同于a-z.&lt;br /&gt;
*&lt;br /&gt;
&lt;br /&gt;
[:print:] (可打印字符). 匹配 ASCII码值 32 - 126之间的字符. 这和上面提到的一样[:graph:], 但是增多一个空格字符。&lt;br /&gt;
*&lt;br /&gt;
&lt;br /&gt;
[:space:] 匹配空白字符 (空格符和水平制表符).&lt;br /&gt;
*&lt;br /&gt;
&lt;br /&gt;
[:upper:] 匹配大写字母. 等同于A-Z.&lt;br /&gt;
*&lt;br /&gt;
&lt;br /&gt;
[:xdigit:] 匹配十六进制数字. 等同于0-9A-Fa-f.&lt;br /&gt;
&lt;br /&gt;
POSIX字符类一般都要求用[[ ]]引起来, 如： grep [[:digit:]] test.txt</content><link rel='replies' type='application/atom+xml' href='http://chennrui.blogspot.com/feeds/4284996662709676639/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://chennrui.blogspot.com/2010/12/bash.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/4284996662709676639'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/4284996662709676639'/><link rel='alternate' type='text/html' href='http://chennrui.blogspot.com/2010/12/bash.html' title='bash学习笔记（一）——正则表达式'/><author><name>big bang</name><uri>http://www.blogger.com/profile/07380722230385048574</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQEwGR3hniNIaoAuRxuoFMsyO_esdj85N9t60Bj4qln24_y7qj8mnx8taxn-KrBbc2zQBfJviUXvScqSs7OD3zJBpP5wimbihfo-Y9yHnpYezKHlkxxt5YRkQ2wyrFDA/s220/linux-logo.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7128755548240021396.post-651463165131714830</id><published>2010-12-28T12:47:00.001+08:00</published><updated>2010-12-28T20:43:09.937+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="翻墙"/><title type='text'>使用GAE翻墙</title><content type='html'>1. Sign in with your account in &lt;a href=&quot;http://appspot.com&quot;&gt;appspot.com&lt;/a&gt;&lt;br /&gt;
2. Install Google App Engine SDK for Python&lt;br /&gt;
   http://code.google.com/appengine/downloads.html#Google_App_Engine_SDK_for_Python&lt;br /&gt;
   http://googleappengine.googlecode.com/files/google_appengine_1.4.0.zip&lt;br /&gt;
   download and extract uncompress google_appengine_1.4.0.zip.&lt;br /&gt;
   modify PATH variable in ~/.bashrc for GAE.&lt;br /&gt;
3. checkout GAppProxy&lt;br /&gt;
   svn checkout http://gappproxy.googlecode.com/svn/trunk/ gappproxy&lt;br /&gt;
4. deploy GAppProxy &lt;br /&gt;
   modify fetchserver/app.yaml, application:&lt;br /&gt;
   appcfg.py update fetchserver&lt;br /&gt;
   login appspot.com, My Applications-&gt; -&gt; Versions, choose the lastest and make default.&lt;br /&gt;
5. edit localproxy/proxy.conf&lt;br /&gt;
6. testing&lt;br /&gt;
   localproxy/proxy.py</content><link rel='replies' type='application/atom+xml' href='http://chennrui.blogspot.com/feeds/651463165131714830/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://chennrui.blogspot.com/2010/12/blog-post.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/651463165131714830'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7128755548240021396/posts/default/651463165131714830'/><link rel='alternate' type='text/html' href='http://chennrui.blogspot.com/2010/12/blog-post.html' title='使用GAE翻墙'/><author><name>big bang</name><uri>http://www.blogger.com/profile/07380722230385048574</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQEwGR3hniNIaoAuRxuoFMsyO_esdj85N9t60Bj4qln24_y7qj8mnx8taxn-KrBbc2zQBfJviUXvScqSs7OD3zJBpP5wimbihfo-Y9yHnpYezKHlkxxt5YRkQ2wyrFDA/s220/linux-logo.png'/></author><thr:total>0</thr:total></entry></feed>