{"id":56,"date":"2019-07-23T16:50:33","date_gmt":"2019-07-23T08:50:33","guid":{"rendered":"https:\/\/www.book11111.com\/?p=56"},"modified":"2019-07-27T22:05:45","modified_gmt":"2019-07-27T14:05:45","slug":"%e5%86%85%e6%a0%b8list_head%e9%93%be%e8%a1%a8%e8%8a%82%e7%82%b9%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"http:\/\/116.62.123.213\/index.php\/2019\/07\/23\/%e5%86%85%e6%a0%b8list_head%e9%93%be%e8%a1%a8%e8%8a%82%e7%82%b9%e4%bd%bf%e7%94%a8\/","title":{"rendered":"\u5185\u6838list_head\u94fe\u8868\u8282\u70b9\u4f7f\u7528"},"content":{"rendered":"<p>\u786c\u4ef6\u8bbe\u5907\uff1aJZ2440\u5f00\u53d1\u677f<\/p>\n<p>\u8f6f\u4ef6\u73af\u5883\uff1aUbuntu15.04<\/p>\n<p>\u81ea\u5236\u7f16\u8bd1\u5668<\/p>\n<p>\u00a0<\/p>\n<p>\u672c\u6848\u4f8b\u6d4b\u8bd5\u5185\u6838\u6a21\u5757\uff0c\u5b9e\u73b0\u94fe\u8868\u7684\u521b\u5efa\u3001\u589e\u52a0\u8282\u70b9\u3001\u904d\u5386\u548c\u5220\u9664\u64cd\u4f5c\u3002<\/p>\n<p>\u5b9e\u73b0\u6b65\u9aa4\uff1a\u901a\u8fc7vim\u7f16\u5199c\u6e90\u7a0b\u5e8f<\/p>\n<ol>\n<li>\u7f16\u5199\u76f8\u5e94\u7684Makefile\u6587\u4ef6<\/li>\n<li>\u5728listdemo,c\u6587\u4ef6\u76ee\u5f55\u4e0b\u6267\u884cmake\u6307\u4ee4\uff0c\u751f\u6210ko\u6587\u4ef6<\/li>\n<li>\u5c06\u751f\u6210\u7684ko\u62f7\u8d1d\u5230\u5f00\u53d1\u677f\u5185<\/li>\n<li>\u6253\u5f00\u5f00\u53d1\u677f\uff0c\u5728ko\u6587\u4ef6\u76ee\u5f55\u4e0b\u6267\u884cinsmod\u00a0listdemo.ko<\/li>\n<\/ol>\n<p>listdemo.c\u6587\u4ef6<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">#include &lt;linux\/init.h&gt;\n#include &lt;linux\/module.h&gt;\n#include &lt;linux\/slab.h&gt;\n\u00a0\n#include &lt;linux\/list.h&gt;\n\u00a0\nMODULE_LICENSE(\"Dual BSD\/GPL\");\n\u00a0\n#define\tEMPLOYEE_NUMBEROF 5\n\u00a0\nstatic struct list_head employee_list;\n\u00a0\nstruct employee{\n  char name[20];\n  int number;\n  int salary;\n  struct list_head list;\n};\n\u00a0\nstatic struct employee *employeep = NULL;\nstatic struct employee *employeep_tmp = NULL;\nstatic struct list_head *pos = NULL;\nstatic struct list_head *pos1 = NULL;\n\u00a0\nstatic int __init listdemo_init(void)\n{\n  int i;\n  printk(\n\u00a0\nKERN_ALERT \"Entry listdemo_init!\\n\");\n  INIT_LIST_HEAD(&amp;employee_list);\n  employeep = kmalloc(sizeof(struct employee) * EMPLOYEE_NUMBEROF,GFP_KERNEL);\n  if(NULL==employeep){\n    printk(KERN_ALERT \"can't allocate memory for employee array from kernel!\\n\");\n    return -ENOMEM;\n  }\n  printk(KERN_ALERT \"Success to allocate memory for employee array from kernel!\\n\");\n  memset(employeep,0,sizeof(struct employee) * EMPLOYEE_NUMBEROF);\n\u00a0\n  for(i=0;i&lt;EMPLOYEE_NUMBEROF;i++){\n    sprintf(employeep[i].name,\"Employee%d\",i+1);\n    employeep[i].number = 1001 + i;\n    employeep[i].salary = 50000 + 5000 * i;\n    list_add(&amp;(employeep[i].list),&amp;employee_list);\n  }\n  list_for_each(pos,&amp;employee_list){\n    employeep_tmp = list_entry(pos,struct employee,list);\n    printk(KERN_ALERT \"Employee Name: %s\\tNumber:%d\\tSalary:%d!\\n\",employeep_tmp-&gt;name,employeep_tmp-&gt;number,employeep_tmp-&gt;salary);\n  }\n  return 0;\n\u00a0\n}\n\u00a0\nstatic void __exit listdemo_exit(void)\n{\n  printk(KERN_ALERT \"Entry listdem_exit!\\n\");\n  #if 0\n    for(i=0;i&lt;EMPLOYEE_NUMBEROF;i++){\n      list_del(&amp;(employeep[i].list));\n    }\n  #endif\n    list_for_each_safe(pos,pos1,&amp;employee_list){\n      employeep_tmp = list_entry(pos,struct employee,list);\n      list_del(&amp;employeep_tmp-&gt;list);\n    }\n\u00a0\n  printk(KERN_ALERT \"Exit listdemo_exit!\\n\");\n\u00a0\n  kfree(employeep);\n}\n\u00a0\nmodule_init(listdemo_init);\nmodule_exit(listdemo_exit);\n\u00a0\nMODULE_AUTHOR(\"shenchao\");\nMODULE_DESCRIPTION(\"Demo kernel list_head\");\nMODULE_VERSION(\"0.0.1\");\nMODULE_ALIAS(\"ListSemo\");<\/pre>\n<p>Makefile\u6587\u4ef6<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">KERN_DIR = \/work\/system\/linux-3.14.11                                \n\u00a0\nall:\n    make -C $(KERN_DIR) M=`pwd` modules \n\u00a0\nclean:\n    make -C $(KERN_DIR) M=`pwd` modules clean\n    rm -rf modules.order\n\u00a0\nobj-m   += listdemo.o<\/pre>\n<p>\u6700\u7ec8\u5b9e\u73b0insmod\u00a0listdemo.ko\u6307\u4ee4\u540e\u8f93\u51fa\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">\/work # insmod listdemo.ko \nEntry listdemo_init!\nSuccess to allocate memory for employee array from kernel!\nEmployee Name: Employee5        Number:1005     Salary:70000!\nEmployee Name: Employee4        Number:1004     Salary:65000!\nEmployee Name: Employee3        Number:1003     Salary:60000!\nEmployee Name: Employee2        Number:1002     Salary:55000!\nEmployee Name: Employee1        Number:1001     Salary:50000!<\/pre>\n<p>\u6267\u884crmmod\u00a0listdemo\u6307\u4ee4\u540e\u8f93\u51fa\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">\/work # rmmod listdemo\nEntry listdem_exit!\nExit listdemo_exit!<\/pre>\n<p>\u00a0<\/p>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u786c\u4ef6\u8bbe\u5907\uff1aJZ2440\u5f00\u53d1\u677f \u8f6f\u4ef6\u73af\u5883\uff1aUbuntu15.04 \u81ea\u5236\u7f16\u8bd1\u5668 \u00a0 \u672c\u6848\u4f8b\u6d4b\u8bd5\u5185\u6838\u6a21\u5757\uff0c\u5b9e\u73b0\u94fe\u8868\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-56","post","type-post","status-publish","format-standard","hentry","category-electr"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.1.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5185\u6838list_head\u94fe\u8868\u8282\u70b9\u4f7f\u7528 - \u6c88\u8d85\u7684\u535a\u5ba2<\/title>\n<meta name=\"description\" content=\"arm,dsp,pcb,fpga,zynq,\u5e38\u7528\u8f6f\u4ef6altium designed,\u7b97\u6cd5\" \/>\n<link rel=\"canonical\" href=\"http:\/\/116.62.123.213\/index.php\/2019\/07\/23\/\u5185\u6838list_head\u94fe\u8868\u8282\u70b9\u4f7f\u7528\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5185\u6838list_head\u94fe\u8868\u8282\u70b9\u4f7f\u7528 - \u6c88\u8d85\u7684\u535a\u5ba2\" \/>\n<meta property=\"og:description\" content=\"arm,dsp,pcb,fpga,zynq,\u5e38\u7528\u8f6f\u4ef6altium designed,\u7b97\u6cd5\" \/>\n<meta property=\"og:url\" content=\"http:\/\/116.62.123.213\/index.php\/2019\/07\/23\/\u5185\u6838list_head\u94fe\u8868\u8282\u70b9\u4f7f\u7528\/\" \/>\n<meta property=\"og:site_name\" content=\"\u6c88\u8d85\u7684\u535a\u5ba2\" \/>\n<meta property=\"article:published_time\" content=\"2019-07-23T08:50:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-07-27T14:05:45+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\">\n\t<meta name=\"twitter:data1\" content=\"2 \u5206\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"http:\/\/116.62.123.213\/#website\",\"url\":\"http:\/\/116.62.123.213\/\",\"name\":\"\\u6c88\\u8d85\\u7684\\u535a\\u5ba2\",\"description\":\"arm,dsp,pcb,fpga,zynq,\\u5e38\\u7528\\u8f6f\\u4ef6altium designed,\\u7b97\\u6cd5\",\"publisher\":{\"@id\":\"http:\/\/116.62.123.213\/#\/schema\/person\/686c7e95d9da5350921994bb9575417c\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"http:\/\/116.62.123.213\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/116.62.123.213\/index.php\/2019\/07\/23\/%e5%86%85%e6%a0%b8list_head%e9%93%be%e8%a1%a8%e8%8a%82%e7%82%b9%e4%bd%bf%e7%94%a8\/#webpage\",\"url\":\"http:\/\/116.62.123.213\/index.php\/2019\/07\/23\/%e5%86%85%e6%a0%b8list_head%e9%93%be%e8%a1%a8%e8%8a%82%e7%82%b9%e4%bd%bf%e7%94%a8\/\",\"name\":\"\\u5185\\u6838list_head\\u94fe\\u8868\\u8282\\u70b9\\u4f7f\\u7528 - \\u6c88\\u8d85\\u7684\\u535a\\u5ba2\",\"isPartOf\":{\"@id\":\"http:\/\/116.62.123.213\/#website\"},\"datePublished\":\"2019-07-23T08:50:33+00:00\",\"dateModified\":\"2019-07-27T14:05:45+00:00\",\"description\":\"arm,dsp,pcb,fpga,zynq,\\u5e38\\u7528\\u8f6f\\u4ef6altium designed,\\u7b97\\u6cd5\",\"breadcrumb\":{\"@id\":\"http:\/\/116.62.123.213\/index.php\/2019\/07\/23\/%e5%86%85%e6%a0%b8list_head%e9%93%be%e8%a1%a8%e8%8a%82%e7%82%b9%e4%bd%bf%e7%94%a8\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/116.62.123.213\/index.php\/2019\/07\/23\/%e5%86%85%e6%a0%b8list_head%e9%93%be%e8%a1%a8%e8%8a%82%e7%82%b9%e4%bd%bf%e7%94%a8\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/116.62.123.213\/index.php\/2019\/07\/23\/%e5%86%85%e6%a0%b8list_head%e9%93%be%e8%a1%a8%e8%8a%82%e7%82%b9%e4%bd%bf%e7%94%a8\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"item\":{\"@type\":\"WebPage\",\"@id\":\"http:\/\/116.62.123.213\/\",\"url\":\"http:\/\/116.62.123.213\/\",\"name\":\"\\u9996\\u9875\"}},{\"@type\":\"ListItem\",\"position\":2,\"item\":{\"@type\":\"WebPage\",\"@id\":\"http:\/\/116.62.123.213\/index.php\/2019\/07\/23\/%e5%86%85%e6%a0%b8list_head%e9%93%be%e8%a1%a8%e8%8a%82%e7%82%b9%e4%bd%bf%e7%94%a8\/\",\"url\":\"http:\/\/116.62.123.213\/index.php\/2019\/07\/23\/%e5%86%85%e6%a0%b8list_head%e9%93%be%e8%a1%a8%e8%8a%82%e7%82%b9%e4%bd%bf%e7%94%a8\/\",\"name\":\"\\u5185\\u6838list_head\\u94fe\\u8868\\u8282\\u70b9\\u4f7f\\u7528\"}}]},{\"@type\":\"Article\",\"@id\":\"http:\/\/116.62.123.213\/index.php\/2019\/07\/23\/%e5%86%85%e6%a0%b8list_head%e9%93%be%e8%a1%a8%e8%8a%82%e7%82%b9%e4%bd%bf%e7%94%a8\/#article\",\"isPartOf\":{\"@id\":\"http:\/\/116.62.123.213\/index.php\/2019\/07\/23\/%e5%86%85%e6%a0%b8list_head%e9%93%be%e8%a1%a8%e8%8a%82%e7%82%b9%e4%bd%bf%e7%94%a8\/#webpage\"},\"author\":{\"@id\":\"http:\/\/116.62.123.213\/#\/schema\/person\/686c7e95d9da5350921994bb9575417c\"},\"headline\":\"\\u5185\\u6838list_head\\u94fe\\u8868\\u8282\\u70b9\\u4f7f\\u7528\",\"datePublished\":\"2019-07-23T08:50:33+00:00\",\"dateModified\":\"2019-07-27T14:05:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/116.62.123.213\/index.php\/2019\/07\/23\/%e5%86%85%e6%a0%b8list_head%e9%93%be%e8%a1%a8%e8%8a%82%e7%82%b9%e4%bd%bf%e7%94%a8\/#webpage\"},\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/116.62.123.213\/#\/schema\/person\/686c7e95d9da5350921994bb9575417c\"},\"articleSection\":\"\\u7535\\u5b50\",\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\/\/116.62.123.213\/index.php\/2019\/07\/23\/%e5%86%85%e6%a0%b8list_head%e9%93%be%e8%a1%a8%e8%8a%82%e7%82%b9%e4%bd%bf%e7%94%a8\/#respond\"]}]},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\/\/116.62.123.213\/#\/schema\/person\/686c7e95d9da5350921994bb9575417c\",\"name\":\"\\u6c88\\u8d85\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"http:\/\/116.62.123.213\/#personlogo\",\"inLanguage\":\"zh-Hans\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/40261dfac05f2d465bb2abf96c1c4e8ceaf45876aec9d52e6b86ef40372d06f0?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/40261dfac05f2d465bb2abf96c1c4e8ceaf45876aec9d52e6b86ef40372d06f0?s=96&d=identicon&r=g\",\"caption\":\"\\u6c88\\u8d85\"},\"logo\":{\"@id\":\"http:\/\/116.62.123.213\/#personlogo\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"http:\/\/116.62.123.213\/index.php\/wp-json\/wp\/v2\/posts\/56","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/116.62.123.213\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/116.62.123.213\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/116.62.123.213\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/116.62.123.213\/index.php\/wp-json\/wp\/v2\/comments?post=56"}],"version-history":[{"count":1,"href":"http:\/\/116.62.123.213\/index.php\/wp-json\/wp\/v2\/posts\/56\/revisions"}],"predecessor-version":[{"id":57,"href":"http:\/\/116.62.123.213\/index.php\/wp-json\/wp\/v2\/posts\/56\/revisions\/57"}],"wp:attachment":[{"href":"http:\/\/116.62.123.213\/index.php\/wp-json\/wp\/v2\/media?parent=56"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/116.62.123.213\/index.php\/wp-json\/wp\/v2\/categories?post=56"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/116.62.123.213\/index.php\/wp-json\/wp\/v2\/tags?post=56"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}