{"id":43,"date":"2024-03-09T14:47:18","date_gmt":"2024-03-09T06:47:18","guid":{"rendered":"http:\/\/104.46.213.183\/?p=43"},"modified":"2024-03-09T14:47:18","modified_gmt":"2024-03-09T06:47:18","slug":"lab-xv6-and-unix-utilities","status":"publish","type":"post","link":"https:\/\/www.yewpo.top\/index.php\/43\/","title":{"rendered":"Lab Xv6 and Unix utilities"},"content":{"rendered":"<h1>Lab Xv6 and Unix utilities<\/h1>\n<h2>1 Boot xv6<\/h2>\n<p>\u5bfc\u5165\u5b9e\u9a8c\u548c\u542f\u52a8\u7cfb\u7edf<\/p>\n<pre><code class=\"language-git\">git clone git:\/\/g.csail.mit.edu\/xv6-labs-2022\ncd xv6-labs-2022\ngit cheakout util\ngit commit -am &#039;my solution for util lab exercise 1&#039;\nmake qemu<\/code><\/pre>\n<p>\u6d4b\u8bd5\u81ea\u5df1\u7684\u4ee3\u7801\u7684\u6b63\u786e\u6027<\/p>\n<pre><code class=\"language-shell\">make grade #for all test\nmake GRADEFLAGS=&#039;test&#039; grade # test just for test<\/code><\/pre>\n<p>\u6216\u8005<\/p>\n<pre><code class=\"language-shell\">.\\grade-lab-util &lt;test name&gt;<\/code><\/pre>\n<h2>2 sleep(easy)<\/h2>\n<blockquote>\n<p>\u5b9e\u73b0\u4e00\u4e2asleep\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u6682\u505c\u7528\u6237\u8981\u6c42\u7684\u65f6\u95f4\u3002<\/p>\n<\/blockquote>\n<h3>2.1 \u7cfb\u7edf\u8c03\u7528sleep<\/h3>\n<p>\u672c\u5b9e\u9a8c\u53ea\u7528\u5b9e\u73b0\u7cfb\u7edf\u8c03\u7528\u3002<\/p>\n<h3>2.2 \u7a0b\u5e8f\u4ee3\u7801<\/h3>\n<pre><code class=\"language-c\">#include &quot;kernel\/types.h&quot;\n#include &quot;kernel\/stat.h&quot;\n#include &quot;user\/user.h&quot;\n\nint main(int argc, char *argv[]) {\n    if (argc &lt; 2 || argc &gt; 2) {\n        fprintf(2, &quot;Usage: sleep time\\n&quot;);\n        exit(1);\n    }\n\n    for (int i = 0; i &lt; strlen(argv[1]); ++i) {\n        if (argv[1][i] &lt; &#039;0&#039; || argv[1][i] &gt; &#039;9&#039;) {\n            fprintf(2, &quot;Usage: sleep time\\n&quot;);\n            exit(1);\n        }\n    }\n\n    sleep(atoi(argv[1]));\n\n    exit(0);\n}<\/code><\/pre>\n<h2>3 pingpong(easy)<\/h2>\n<blockquote>\n<p>\u5b9e\u73b0\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u5b8c\u6210\u4e24\u4e2a\u8fdb\u7a0b\u4e4b\u95f4\u4e00\u4e2a\u5b57\u8282\u7684\u4fe1\u606f\u4ea4\u6d41\u3002<\/p>\n<p>\u5b9e\u73b0\u65b9\u6cd5\uff1a\u901a\u8fc7\u7ba1\u9053<\/p>\n<p>\u7236\u8fdb\u7a0b\u5411\u5b50\u8fdb\u7a0b\u901a\u8fc7\u7ba1\u9053\u53d1\u9001\u4e00\u4e2a\u5b57\u8282\u7684\u4fe1\u606f\u540e\uff0c\u5b50\u8fdb\u7a0b\u63a5\u53d7\u5230\u6d88\u606f\u540e\u6253\u5370\u63a5\u53d7\u6d88\u606f\u4fe1\u606f\uff0c\u5e76\u5411\u7236\u8fdb\u7a0b\u53d1\u9001\u4e00\u4e2a\u5b57\u8282\u7684\u4fe1\u606f\uff0c\u7236\u8fdb\u7a0b\u6536\u5230\u6d88\u606f\u4e4b\u540e\uff0c\u6253\u5370\u63a5\u53d7\u5230\u6d88\u606f\u7684\u4fe1\u606f\u3002<\/p>\n<\/blockquote>\n<h3>3.1 \u7cfb\u7edf\u8c03\u7528pipe\uff0cread\uff0cwrite\uff0cgetpid\uff0cfork<\/h3>\n<p><strong>\u5bf9\u4e8e\u5b50\u8fdb\u7a0b\u548c\u7236\u8fdb\u7a0b\uff0c\u4ed6\u4eec\u5171\u4eab\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u4f46\u662f\u76f8\u4e92\u72ec\u7acb\u3002<\/strong><\/p>\n<h4>3.1.1 pipe<\/h4>\n<p>\u7ba1\u9053\u662f\u4e00\u4e2a\u5c0f\u578b\u7684\u7cfb\u7edf\u7f13\u5b58\uff0c\u5e76\u5411\u8fdb\u7a0b\u63d0\u4f9b\u4e24\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u4e00\u4e2a\u7ba1\u9053\u8bfb\u53d6\u63cf\u8ff0\u7b26\u4e00\u4e2a\u7ba1\u9053\u5199\u5165\u63cf\u8ff0\u7b26\u3002\u7528\u6237\u53ea\u80fd\u5728\u7ba1\u9053\u7684\u4e00\u7aef\u5199\u5165\uff0c\u5e76\u5728\u53e6\u4e00\u7aef\u8bfb\u53d6\u3002\u7ba1\u9053\u4ee5\u8fd9\u79cd\u65b9\u5f0f\u5411\u8fdb\u7a0b\u63d0\u4f9b\u4e86\u4fe1\u606f\u4ea4\u6d41\u7684\u65b9\u5f0f\u3002<\/p>\n<p>\u7ba1\u9053\u5177\u6709\u4ee5\u4e0b\u7279\u70b9\uff1a<\/p>\n<ul>\n<li>\u534a\u53cc\u5de5<\/li>\n<li>\u4e0d\u53ef\u91cd\u590d\u8bfb\u53d6<\/li>\n<\/ul>\n<p>\u57fa\u4e8e\u4ee5\u4e0a\u7279\u6027\uff0c<strong>\u6570\u636e\u5728\u7ba1\u9053\u4e2d\u53ea\u80fd\u5355\u5411\u4f20\u8f93\uff0c\u800c\u4e14\u4e0d\u80fd\u957f\u671f\u5b58\u5728\uff08\u8bfb\u53d6\u540e\u5c31\u4e0d\u5b58\u5728\u4e86\uff09\u3002<\/strong><\/p>\n<h4>3.1.2 \u83b7\u53d6\u4e00\u4e2apipe<\/h4>\n<p>\u901a\u8fc7\u7cfb\u7edf\u8c03\u7528<code>pipe<\/code>\u51fd\u6570\uff0c\u53ef\u4ee5\u7533\u8bf7\u5f97\u5230\u4e00\u4e2apipe\u3002<\/p>\n<pre><code class=\"language-c\">int p[2];\npipe(p);<\/code><\/pre>\n<p>\u5982\u679c\u7533\u8bf7\u6210\u529f\uff0cpipe[0]\u50a8\u5b58\u7684\u8bfb\u53d6\u63cf\u8ff0\u7b26\uff0c\u800cp[1]\u50a8\u5b58\u7684\u662f\u5199\u5165\u63cf\u8ff0\u7b26\u3002<\/p>\n<h4>3.1.3 fork<\/h4>\n<p><code>fork<\/code>\u7684\u4f5c\u7528\u662f\u521b\u5efa\u4e00\u4e2a\u5b50\u8fdb\u7a0b\uff0c\u5728\u7236\u8fdb\u7a0b\u4e2d\u8fd4\u56de\u5b50\u8fdb\u7a0b\u7684<code>pid<\/code>\uff0c\u800c\u5728\u5b50\u8fdb\u7a0b\u4e2d\u8fd4\u56de0\uff1b<\/p>\n<p>\u6709\u5173fork\u7684\u8be6\u7ec6\u7ec6\u8282\uff0c\u53ef\u4ee5\u53c2\u8003<code>CSAPP3E<\/code>\u76848.4\u8282\u3002<\/p>\n<p><strong>\u7531\u4e8e\u7236\u5b50\u8fdb\u7a0b\u5171\u4eab\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u6240\u4ee5\u5b50\u8fdb\u7a0b\u548c\u7236\u8fdb\u7a0b\u90fd\u9700\u8981\u624b\u52a8\u5173\u95ed\u76f8\u5173\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26<\/strong><\/p>\n<h4>3.1.4 read &amp; write<\/h4>\n<p>\u8be6\u7ec6\u5185\u5bb9\u53ef\u4ee5\u53c2\u8003<code>CSAPP3E<\/code>\u7b2c10\u7ae0\u3002<\/p>\n<h4>3.1.5 getpid<\/h4>\n<p>\u83b7\u5f97\u5f53\u524d\u8fdb\u7a0b\u7684pid\u3002<\/p>\n<h4>3.2 \u4ee3\u7801\u5b9e\u73b0<\/h4>\n<p>\u5728\u7236\u8fdb\u7a0b\u521b\u5efa\u7ba1\u9053\uff0c\u4e4b\u540e\u4f1a\u4e0e\u5b50\u8fdb\u7a0b\u5171\u4eab\u3002<\/p>\n<p>\u7531\u4e8e\u5b50\u8fdb\u7a0b\u548c\u7236\u8fdb\u7a0b\u51e0\u4e4e\u5e76\u884c\uff0c\u6240\u4ee5\u6211\u4eec\u8981\u5148\u7b49\u5f85\u5b50\u8fdb\u7a0b\u7ed3\u675f\u540e\u518d\u7ee7\u7eed\u6267\u884c\u7236\u8fdb\u7a0b\u3002\uff08\u5426\u5219\u5b50\u8fdb\u7a0b\u7684\u7ba1\u9053\u5c31\u6ca1\u6709\u8bfb\u7684\u4e86\uff0c\u8981\u53d1\u751f\u963b\u585e\u76f4\u5230\u5bf9\u5e94\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u5173\u95ed\uff0c\u800c\u4e14\u6ca1\u6709\u76f8\u5e94\u7684\u6536\u5230\u4fe1\u606f\u7684\u8f93\u51fa\uff09<\/p>\n<pre><code class=\"language-c\">#include &quot;kernel\/types.h&quot;\n#include &quot;kernel\/stat.h&quot;\n#include &quot;user\/user.h&quot;\n\nint main(int argc, char *argv[]) {\n    if (argc &gt; 1) {\n        fprintf(2, &quot;Usage: pingpong\\n&quot;);\n        exit(0);\n    }\n    int p[2];\n\n    pipe(p);\n\n    char buf[2];\n    buf[0] = &#039; &#039;;\n    buf[1] = &#039;\\0&#039;;\n\n    write(p[1], buf, 1);\n\n    if (fork() == 0) {\n\n        read(p[0], buf, 1);\n\n        fprintf(1, &quot;%d: received ping\\n&quot;, getpid());\n\n        write(p[1], buf, 1);\n\n        close(p[0]);\n        close(p[1]);\n\n        exit(0);\n    }\n\n    wait(0);\n\n    read(p[0], buf, 1);\n\n    fprintf(1, &quot;%d: received pong\\n&quot;, getpid());\n\n    close(p[0]);\n    close(p[1]);\n\n    exit(0);\n}<\/code><\/pre>\n<h2>4 primes(hard)<\/h2>\n<blockquote>\n<p>\u9605\u8bfb <code>Bell Lab and CSP Thread<\/code>\u6750\u6599\uff0c\u7528\u8fdb\u7a0b\u95f4\u7684\u901a\u4fe1\u5b8c\u6210\u6750\u6599\u4e2d\u8d28\u6570\u7b5b\u9009\u7684\u5b9e\u9a8c<\/p>\n<p>\u8be5\u7a0b\u5e8f\u7684\u601d\u8def\u7684\u6d41\u7a0b\u56fe;<\/p>\n<p>![image-20221018214030001](D:\\assignment\\glimmer\\notes\\6.S081 OS Labs\\image-20221018214030001.png)<\/p>\n<p>\u5411\u6bcf\u4e2a\u8d28\u6570\u5206\u914d\u4e00\u4e2a\u5b50\u8fdb\u7a0b\uff0c\u7528pipe\u7ba1\u9053\u5411\u4e0b\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u4f20\u8f93\u4e0d\u662f\u81ea\u5df1\u7684\u500d\u6570\u7684\u6570\u3002<\/p>\n<\/blockquote>\n<h3>4.1 \u5199\u5165\u7ba1\u9053\u963b\u585e<\/h3>\n<h4>4.1.1 \u4ea7\u751f\u539f\u56e0<\/h4>\n<p>\u56e0\u4e3a\u7ba1\u9053\u63d0\u4f9b\u7684\u7f13\u5b58\u5927\u5c0f\u6709\u9650\uff08\u5f88\u5c0f\uff09\uff0c\u5f53\u8f93\u5165\u5230\u7ba1\u9053\u4e2d\u7684\u6570\u636e\u7684\u5927\u5c0f\u8fbe\u5230\u7ba1\u9053\u7684\u6700\u5927\u7684\u5bb9\u91cf\u7684\u65f6\u5019\uff0c\u5199\u5165\u5c31\u4f1a\u963b\u585e\u3002<\/p>\n<h4>4.1.2 \u89e3\u51b3\u65b9\u6848<\/h4>\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u9700\u8981\u5148\u521b\u5efa\u5b50\u8fdb\u7a0b\u5f00\u59cb\u4ece\u7ba1\u9053\u4e2d\u8bfb\u53d6\uff0c\u7236\u8fdb\u7a0b\u5728\u6b64\u4e4b\u540e\u63d0\u4f9b\u8f93\u5165\u3002<\/p>\n<h4>4.1.3 \u65b0\u7684\u95ee\u9898<\/h4>\n<p>\u7531\u4e8e\u6bcf\u4e2a\u8fdb\u7a0b\u90fd\u8981\u5148\u521b\u5efa\u5b50\u8fdb\u7a0b\uff0c\u6240\u4ee5\u8fdb\u7a0b\u4f1a\u4e00\u76f4\u521b\u5efa\u4e0b\u53bb\uff0c\u7136\u540e\u5c31\u5d29\u6e83\u4e86\uff0c0.0<\/p>\n<h3>4.2 \u65e0\u9650\u5b50\u8fdb\u7a0b<\/h3>\n<h4>4.2.1 \u4ea7\u751f\u539f\u56e0<\/h4>\n<p>\u89c14.1.3<\/p>\n<h4>4.2.2 \u89e3\u51b3\u65b9\u6cd5<\/h4>\n<ul>\n<li>\u80fd\u5426\u63d0\u4f9b\u4e00\u4e2a\u6807\u8bb0\u503c\uff1f<\/li>\n<\/ul>\n<p>\u8be5\u65b9\u6cd5\u7684\u95ee\u9898\uff1a\u7236\u8fdb\u7a0b\u521b\u5efa\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u7684\u65f6\u5019\uff0c\u5b50\u8fdb\u7a0b\u4f1a\u590d\u5236\u7236\u8fdb\u7a0b\u7684\u53d8\u91cf\u7684\u526f\u672c\uff08\u5b50\u8fdb\u7a0b\u662f\u7236\u8fdb\u7a0b\u7684\u590d\u5236\u54c1\uff09\uff0c\u7136\u800c\u7236\u8fdb\u7a0b\u4e00\u5f00\u59cb\u5c31\u4f1a\u521b\u5efa\u5b50\u8fdb\u7a0b\uff0c\u5373\u4f7f\u540e\u9762\u7236\u8fdb\u7a0b\u7684\u68c0\u67e5\u53d1\u73b0\u4e86\u95ee\u9898\u6253\u4e0a\u4e86\u8fd9\u4e2a\u6807\u8bb0\uff0c\u5b50\u8fdb\u7a0b\u4e5f\u4e0d\u77e5\u9053\uff0c\u56e0\u4e3a\u53d8\u91cf\u4e4b\u95f4\u76f8\u4e92\u72ec\u7acb\u3002<\/p>\n<ul>\n<li>\u65e0\u5948\u672c\u9898\u7279\u6b8a\u89e3\uff08\u6211\u592a\u83dc\u4e86\uff09<\/li>\n<\/ul>\n<p>\u7531\u4e8e\u662f\u7b5b\u8d28\u6570\uff0c\u6240\u4ee5\u8fdb\u7a0b\u6570\u6709\u9650\uff0c\u5f53\u8fdb\u7a0b\u6570\u8d85\u8fc7\u8981\u5224\u65ad\u7684\u6570\u7684\u603b\u6570\u4e4b\u540e\uff0c\u5c31\u53ef\u4ee5\u4e0d\u7528\u5728\u4ea7\u751f\u65b0\u7684\u8fdb\u7a0b\u4e86\u3002\uff08\u7279\u6b8a\u89e3\u7f62\u4e86\uff0c\u4e00\u65e6\u8981\u5224\u65ad\u6570\u7684\u603b\u6570\u589e\u52a0\uff0c\u8fd9\u4e2a\u7a0b\u5e8f\u4ea7\u751f\u7684\u65e0\u7528\u7684\u8fdb\u7a0b\u5c31\u66f4\u591a\u4e86\uff0c\u3002\u3002\uff09<\/p>\n<h3>4.3 \u521b\u5efa\u8fdb\u7a0b<\/h3>\n<p>\u7531\u4e8e\u5b50\u8fdb\u7a0b\u5f88\u591a\uff0c\u4e0d\u592a\u53ef\u80fd\u5199\u6761\u4ef6\u5d4c\u5957\u5427\uff1f<\/p>\n<p><strong>\u7528\u9012\u5f52\u51fd\u6570\u6765\u521b\u5efa\u5b50\u5b50\u8fdb\u7a0b<\/strong><\/p>\n<p>\u5f62\u5982\uff1a<\/p>\n<pre><code class=\"language-c\">void forkandfork() {\n    if (fork() == 0) {\n        forkandfork();\n    }\n\n    exit(0);\n}<\/code><\/pre>\n<h3>4.4 \u8fdb\u7a0b\u95f4\u7684\u6c9f\u901a<\/h3>\n<p>\u8fdb\u7a0b\u95f4\u7684\u6c9f\u901a\u53c2\u8003<code>3 pingpong<\/code><\/p>\n<p><strong>\u5b9e\u73b0<\/strong><\/p>\n<pre><code class=\"language-c\">while (read(fd0, &amp;value, 32)) {\n    if (!prime) {\n        prime = value;\n        fprintf(1, &quot;prime %d\\n&quot;, prime);\n    }\n\n    if (value % prime != 0) {\n        write(p[1], &amp;value, 32);\n    }\n}<\/code><\/pre>\n<h3>4.5 \u4ee3\u7801\u5b9e\u73b0<\/h3>\n<pre><code class=\"language-C\">#include &quot;kernel\/types.h&quot;\n#include &quot;kernel\/stat.h&quot;\n#include &quot;user\/user.h&quot;\n\nint p[2];\nint flag = 1;\nint count = 0;\nint num = 35;\n\nvoid forkPrime() {\n    count++;\n\n    if (count &gt; num) {\n        close(p[0]);\n        close(1);\n        exit(0);\n    }\n\n    int fd0 = p[0];\n\n    pipe(p);\n\n    if (fork() == 0) {\n        close(fd0);\n        close(p[1]);\n\n        forkPrime();\n    }\n\n    close(p[0]);\n\n    int prime = 0;\n    int value = 0;\n\n    while (read(fd0, &amp;value, 32)) {\n        if (!prime) {\n            prime = value;\n            fprintf(1, &quot;prime %d\\n&quot;, prime);\n        }\n\n        if (value % prime != 0) {\n            write(p[1], &amp;value, 32);\n        }\n    }\n\n    close(fd0);\n    close(p[1]);\n    close(1);\n\n    wait(0);\n\n    exit(0);\n}\n\nint main(int argc, char *argv[]) {\n    close(0);\n    close(2);\n\n    pipe(p);\n\n    if (fork() == 0) {\n        close(p[1]);\n        forkPrime();\n    }\n\n    close(p[0]);\n\n    for (int i = 2; i &lt;= num; ++i) {\n        write(p[1], &amp;i, 32);\n    }\n\n    close(p[1]);\n    close(1);\n\n    wait(0);\n\n    exit(0);\n}<\/code><\/pre>\n<h2>5 find(moderate)<\/h2>\n<blockquote>\n<p>\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u5b9e\u73b0\u5728\u6307\u5b9a\u6587\u4ef6\u5939\u4ee5\u53ca\u5b50\u6587\u4ef6\u5939\u4e2d\u641c\u7d22\u8981\u67e5\u627e\u5230\u7684\u6587\u4ef6\u3002<\/p>\n<\/blockquote>\n<h3>5.1 \u9605\u8bfbls.c<\/h3>\n<p>ls.c \u6e90\u7801<\/p>\n<pre><code class=\"language-C\">#include &quot;kernel\/types.h&quot;\n#include &quot;kernel\/stat.h&quot;\n#include &quot;user\/user.h&quot;\n#include &quot;kernel\/fs.h&quot;\n\nchar*\nfmtname(char *path)\n{\n  static char buf[DIRSIZ+1];\n  char *p;\n\n  \/\/ Find first character after last slash.\n  for(p=path+strlen(path); p &gt;= path &amp;&amp; *p != &#039;\/&#039;; p--)\n    ;\n  p++;\n\n  \/\/ Return blank-padded name.\n  if(strlen(p) &gt;= DIRSIZ)\n    return p;\n  memmove(buf, p, strlen(p));\n  memset(buf+strlen(p), &#039; &#039;, DIRSIZ-strlen(p));\n  return buf;\n}\n\nvoid\nls(char *path)\n{\n  char buf[512], *p;\n  int fd;\n  struct dirent de;\n  struct stat st;\n\n  if((fd = open(path, 0)) &lt; 0){\n    fprintf(2, &quot;ls: cannot open %s\\n&quot;, path);\n    return;\n  }\n\n  if(fstat(fd, &amp;st) &lt; 0){\n    fprintf(2, &quot;ls: cannot stat %s\\n&quot;, path);\n    close(fd);\n    return;\n  }\n\n  switch(st.type){\n  case T_FILE:\n    printf(&quot;%s %d %d %l\\n&quot;, fmtname(path), st.type, st.ino, st.size);\n    break;\n\n  case T_DIR:\n    if(strlen(path) + 1 + DIRSIZ + 1 &gt; sizeof buf){\n      printf(&quot;ls: path too long\\n&quot;);\n      break;\n    }\n    strcpy(buf, path);\n    p = buf+strlen(buf);\n    *p++ = &#039;\/&#039;;\n    while(read(fd, &amp;de, sizeof(de)) == sizeof(de)){\n      if(de.inum == 0)\n        continue;\n      memmove(p, de.name, DIRSIZ);\n      p[DIRSIZ] = 0;\n      if(stat(buf, &amp;st) &lt; 0){\n        printf(&quot;ls: cannot stat %s\\n&quot;, buf);\n        continue;\n      }\n      printf(&quot;%s %d %d %d\\n&quot;, fmtname(buf), st.type, st.ino, st.size);\n    }\n    break;\n  }\n  close(fd);\n}\n\nint\nmain(int argc, char *argv[])\n{\n  int i;\n\n  if(argc &lt; 2){\n    ls(&quot;.&quot;);\n    exit(0);\n  }\n  for(i=1; i&lt;argc; i++)\n    ls(argv[i]);\n  exit(0);\n}\n<\/code><\/pre>\n<h4>5.1.1 fmtname\u51fd\u6570<\/h4>\n<p>\u8be5\u51fd\u6570\u7684\u4f5c\u7528\u662f\uff1a\u63d0\u53d6\u8def\u5f84\u4e2d\u7684\u6587\u4ef6\u540d\u3002<\/p>\n<p>\u5bf9\u4e8e<code>memset(buf + strlen(p), &#039; &#039;, DIRSIZ - strlen(p))<\/code>\u7684\u7406\u89e3\uff0c\u6b64\u5904\u7528<code>\u2018 \u2019<\/code>\u5bf9\u672b\u5c3e\u6570\u7ec4\u7684\u521d\u59cb\u5316\u5e76\u4e0d\u662f\u9519\u8bef\u7684\uff0c\u8fd9\u6837\u521d\u59cb\u5316\u7684\u76ee\u7684\u662f\u4e3a\u4e86ls\u5728\u6253\u5370\u7684\u65f6\u5019\u5217\u5bf9\u9f50\u3002\uff08\u4e0d\u77e5\u9053\u8fd9\u4e2a\u76ee\u7684\u7684\u610f\u4e49\u6709\u591a\u5927\u3002\u3002\u3002<\/p>\n<h4>5.1.2 ls \u51fd\u6570<\/h4>\n<p>\u5f88\u660e\u663e\uff0c\u8be5\u51fd\u6570\u7684\u76ee\u7684\u5c31\u662f\u6253\u5370\u5f53\u524d\u76ee\u5f55\u4e0b\u7684\u5185\u5bb9<\/p>\n<h5>5.1.2.1 \u76ee\u5f55\u7c7b\u578b<\/h5>\n<p>\u6309\u7167xv6\u7684\u53c2\u8003\u6587\u6863\uff0c\u76ee\u5f55\u53ef\u4ee5\u5206\u6210\u4e09\u79cd\u7c7b\u578b\uff1a<\/p>\n<ul>\n<li>\u6587\u4ef6<\/li>\n<li>\u8bbe\u5907\u6587\u4ef6<\/li>\n<li>\u76ee\u5f55<\/li>\n<\/ul>\n<p>\u4e09\u79cd\u5f62\u5f0f\u90fd\u53ef\u4ee5\u6253\u5f00\uff0c\u5e76\u4e14\u6211\u4eec\u53ef\u4ee5\u7528<code>fstat<\/code>\u51fd\u6570\u83b7\u5f97\u8be5\u76ee\u5f55\u7684\u4fe1\u606f\u3002\u4fe1\u606f\u50a8\u5b58\u5728<code>struct stat<\/code>\u4e2d\u3002\u8be5\u7ed3\u6784\u4f53\u7684<code>type<\/code>\u5c5e\u6027\u8868\u793a\u4e86\u8be5\u76ee\u5f55\u7684\u7c7b\u578b\uff1a<\/p>\n<ul>\n<li>T_FILE \u6587\u4ef6\u7c7b\u578b<\/li>\n<li>T_DEVICE \u8bbe\u5907\u6587\u4ef6\u7c7b\u578b<\/li>\n<li>T_DIR \u76ee\u5f55\u7c7b\u578b<\/li>\n<\/ul>\n<h5>5.1.2.2 \u5b9e\u73b0\u7684\u601d\u8def<\/h5>\n<p>\u6253\u5f00\u8be5\u76ee\u5f55\uff0c\u4fdd\u5b58\u5bf9\u5e94\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u3002\u5e76\u7528<code>fstat<\/code>\u83b7\u5f97\u8be5\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e2d\u7684\u4fe1\u606f\u3002\u5982\u679c\u8be5\u76ee\u5f55\u7684\u7c7b\u578b\u662f\u6587\u4ef6\uff0c\u6216\u8005\u662f\u8bbe\u5907\u6587\u4ef6\uff0c\u5c31\u76f4\u63a5\u6253\u5370\u6587\u4ef6\u540d\u3002\u5982\u679c\u8be5\u76ee\u5f55\u7c7b\u578b\u662f\u76ee\u5f55\uff0c\u5219\u8be5\u6587\u4ef6\u91cc\u63cf\u8ff0\u4e86\u8be5\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6\u4fe1\u606f\u3002\u6bcf\u4e2a\u6587\u4ef6\u4fe1\u606f\u53ef\u4ee5\u7528<code>struct dirent<\/code>\u6765\u8868\u793a\u3002<\/p>\n<p><strong>struct dirent<\/strong><\/p>\n<pre><code class=\"language-C\">struct dirent {\n    int inum;\n    char *name;\n};<\/code><\/pre>\n<p>inum\u8868\u793ainode number\uff1b\u76ee\u5f55\u8fdb\u5165\u8282\u70b9\u7f16\u53f7\uff0c<strong>\u5982\u679cinode\u7684\u8282\u70b9\u7f16\u53f7\u4e3a0\uff0c\u5219\u8868\u793a\u8be5\u6587\u4ef6\u4e0d\u5b58\u5728\u53ef\u4ee5\u8df3\u8fc7<\/strong>\u3002name\u5c31\u662f\u8868\u793a\u6587\u4ef6\u540d\u4e86\u3002\u8bfb\u53d6\u5230\u8be5\u4fe1\u606f\u4e4b\u540e\uff0c\u5c31\u628a\u6587\u4ef6\u540d\u62fc\u63a5\u5230\u8def\u5f84\u540d\u4e0a\u3002\u518d\u7528<code>stat<\/code>\u51fd\u6570\u83b7\u5f97\u8be5\u6587\u4ef6\u7684\u4fe1\u606f\uff0c\u5e76\u6253\u5370\u51fa\u6587\u4ef6\u540d\uff0c\u6587\u4ef6\u7c7b\u578b\uff0c\u6587\u4ef6\u7684\u8282\u70b9\u7f16\u53f7\uff0c\u6587\u4ef6\u7684\u5927\u5c0f\u3002<\/p>\n<h3>5.2 \u4eff\u5199ls.c<\/h3>\n<p>\u5982\u679c\u8bf4\u6587\u4ef6\u7cfb\u7edf\u662f\u4e00\u68f5\u6811\uff0c\u90a3\u4e48\u6211\u8ba4\u4e3a\u6bcf\u4e2a\u6587\u4ef6\u548c\u8bbe\u5907\u6587\u4ef6\u90fd\u662f\u53f6\u5b50\u8282\u70b9\uff0c\u6bcf\u4e2a\u6587\u4ef6\u5939\u76ee\u5f55\u5c31\u662f\u4e00\u4e2a\u5185\u8282\u70b9\u3002<\/p>\n<h4>5.2.1 \u4eff\u5199fmtname\u51fd\u6570<\/h4>\n<p>\u552f\u4e00\u8981\u6ce8\u610f\u7684\u4e00\u70b9\u662f\uff0c\u6700\u540e\u7684memset\u7684\u521d\u59cb\u5316\u7684\u503c\u662f0\uff0c\u56e0\u4e3a\u6211\u4eec\u6b64\u65f6\u7684\u76ee\u7684\u4e0d\u5728\u662f\u5217\u8868\u5bf9\u9f50\u4e86\uff0c\u800c\u662f\u7eaf\u7eaf\u7684\u4e00\u4e2a\u6587\u4ef6\u540d\uff01\uff01<\/p>\n<h4>5.2.2 \u4eff\u5199ls\u51fd\u6570<\/h4>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u4e5f\u5fc5\u987b\u77e5\u9053\u5f53\u524d\u7684\u76ee\u5f55\u8def\u5f84\u662f\u4ec0\u4e48\u7c7b\u578b\uff0c\u6240\u4ee5\u4e5f\u9700\u8981\u5bf9\u76ee\u5f55\u8fdb\u884c\u6253\u5f00\u5e76\u4e14\u83b7\u5f97\u4ed6\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e2d\u7684\u76f8\u5173\u4fe1\u606f\u3002\u5982\u679c\u8be5\u76ee\u5f55\u8def\u5f84\u662f\u4e00\u4e2a\u6587\u4ef6\u6216\u8005\u662f\u4e00\u4e2a\u8bbe\u5907\u6587\u4ef6\uff0c\u6211\u4eec\u5c31\u83b7\u5f97\u4ed6\u7684\u6587\u4ef6\u540d\u548c\u8981\u67e5\u627e\u7684\u6587\u4ef6\u540d\u8fdb\u884c\u6bd4\u8f83\uff0c\u5982\u679c\u5339\u914d\uff0c\u5c31\u8f93\u51fa\u5f53\u524d\u7684\u8def\u5f84\u3002\u4e0d\u5339\u914d\uff0c\u5219\u7ee7\u7eed\u3002<\/p>\n<p>\u5982\u679c\u8be5\u76ee\u5f55\u8def\u5f84\u7c7b\u578b\u662f\u4e00\u4e2a\u6587\u4ef6\u5939\uff0c\u5219\u6211\u4eec\u8981\u67e5\u627e\u8be5\u6587\u4ef6\u5939\u4e2d\u7684\u6240\u6709\u6587\u4ef6\uff0c\u4ece\u8be5\u76ee\u5f55\u6587\u4ef6\u91cc\u6bcf\u6b21\u8bfb\u53d6\u4e00\u4e2a<code>struct dirent<\/code>\uff0c\u5982\u679c\u8bfb\u53d6\u5185\u5bb9\u6709\u6548\uff0c\u62fc\u63a5\u6587\u4ef6\u540d\u5230\u5f53\u524d\u76ee\u5f55\u8def\u5f84\u4e0a\uff0c\u7136\u540e\u7ee7\u7eed\u641c\u7d20\u3002<\/p>\n<h4>5.2.3 \u9632\u6b62\u6b7b\u5faa\u73af<\/h4>\n<p>\u7531\u4e8e\u6bcf\u4e2a\u6587\u4ef6\u4e2d\u90fd\u6709<code>.<\/code>\u6587\u4ef6\u5939\u548c<code>..<\/code>\u6587\u4ef6\u5939\uff0c\u5206\u522b\u8868\u793a\u5f53\u524d\u6587\u4ef6\u5939\u548c\u7236\u6587\u4ef6\u5939\u3002\u641c\u7d20\u5e76\u4e0d\u9700\u8981\u8bbf\u95ee\u7236\u6587\u4ef6\u5939\uff0c\u6240\u4ee5<code>..<\/code>\u6587\u4ef6\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u8df3\u8fc7\uff0c\u7136\u540e\u5bf9\u4e8e<code>.<\/code>\u6587\u4ef6\u5939\uff0c\u6211\u4eec\u5c31\u4e0d\u5ae9\u76f4\u63a5\u8df3\u8fc7\u4e86\uff08\u56e0\u4e3a\u7a0b\u5e8f\u5f00\u59cb\u5c31\u662f<code>.<\/code>\u6587\u4ef6\u5939\uff0c\u8df3\u8fc7\u5c31\u4e0d\u7528\u641c\u7d22\u8fa3:\uff09\u3002<\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u4fdd\u5b58\u5f53\u524d\u76ee\u5f55\u8def\u5f84\u7684iNode\u7f16\u53f7\uff0c\u4ee5\u53ca\u5373\u5c06\u8981\u67e5\u627e\u7684\u6587\u4ef6\u8def\u5f84\u7684iNode\u7f16\u53f7\uff0c\u5982\u679c\u76f8\u540c\uff0c\u5219\u6211\u4eec\u5c31\u4e0d\u7528\u518d\u7ee7\u7eed\u641c\u7d22\u8fd9\u4e2a\u6587\u4ef6\u5939\u3002<\/p>\n<h4>5.2.4 \u4eff\u5199\u51fa\u6765\u7684find\u51fd\u6570<\/h4>\n<pre><code class=\"language-c\">void search(char *path, const char *file) {\n\n    if (strcmp(fmtname(path), &quot;..&quot;) == 0) {\n        return;\n    }\n\n    char buf[512], *p;\n    int fd;\n    struct dirent de;\n    struct stat st;\n\n    if ((fd  = open(path, 0)) &lt; 0) {\n        fprintf(2, &quot;find: cannot open %s\\n&quot;, path);\n        exit(1);\n    }\n\n    if (fstat(fd, &amp;st) &lt; 0) {\n        fprintf(2, &quot;find: cannot stat %s\\n&quot;, path);\n        close(fd);\n        exit(1);\n    }\n\n    switch (st.type) {\n        case T_FILE:\n            if (strcmp(file, fmtname(path)) == 0) {\n                fprintf(1, &quot;%s\\n&quot;, path);\n            }\n            break;\n        case T_DEVICE:\n            if (strcmp(file, fmtname(path)) == 0) {\n                fprintf(1, &quot;%s\\n&quot;, path);\n            }\n            break;\n        case T_DIR:\n            if (strlen(path) + 1 + DIRSIZ + 1 &gt; sizeof(buf)) {\n                fprintf(2, &quot;find: path too long\\n&quot;);\n                close(fd);\n                exit(1);\n            }\n\n            strcpy(buf, path);\n\n            p = buf + strlen(buf);\n\n            *p++ = &#039;\/&#039;;\n\n            while (read(fd, &amp;de, sizeof(de)) == sizeof(de)) {\n                if (de.inum == 0) {\n                    continue;\n                }\n\n                memmove(p, de.name, DIRSIZ);\n                p[DIRSIZ] = 0;\n\n                struct stat prest;\n\n                if (stat(buf, &amp;prest) &lt; 0) {\n                    fprintf(2, &quot;find: cannot stat %s\\n&quot;, p);\n                    continue;\n                }\n\n                if (st.ino == prest.ino) {\n                    continue;\n                }\n\n                search(buf, file);\n            }\n\n            break;\n        default:\n            break;\n    }\n\n    close(fd);\n}<\/code><\/pre>\n<p>\u81f3\u6b64\u6574\u4f53\u4ee3\u7801\u5c31\u57fa\u672c\u5b9e\u73b0\u4e86\u3002<\/p>\n<h3>5.3 \u4ee3\u7801\u5b9e\u73b0<\/h3>\n<pre><code class=\"language-C\">#include &quot;kernel\/types.h&quot;\n#include &quot;kernel\/stat.h&quot;\n#include &quot;user\/user.h&quot;\n#include &quot;kernel\/fs.h&quot;\n\nchar *fmtname(char *path) {\n    static char buf[DIRSIZ + 1];\n    char *p;\n\n    for (p = path + strlen(path); p &gt;= path &amp;&amp; *p != &#039;\/&#039;; p--);\n    p++;\n\n    if (strlen(p) &gt;= DIRSIZ) {\n        return p;\n    }\n\n    memmove(buf, p, strlen(p));\n    memset(buf + strlen(p), 0, DIRSIZ - strlen(p));\n\n    return buf;\n}\n\nvoid search(char *path, const char *file) {\n\n    if (strcmp(fmtname(path), &quot;..&quot;) == 0) {\n        return;\n    }\n\n    char buf[512], *p;\n    int fd;\n    struct dirent de;\n    struct stat st;\n\n    if ((fd  = open(path, 0)) &lt; 0) {\n        fprintf(2, &quot;find: cannot open %s\\n&quot;, path);\n        exit(1);\n    }\n\n    if (fstat(fd, &amp;st) &lt; 0) {\n        fprintf(2, &quot;find: cannot stat %s\\n&quot;, path);\n        close(fd);\n        exit(1);\n    }\n\n    switch (st.type) {\n        case T_FILE:\n            if (strcmp(file, fmtname(path)) == 0) {\n                fprintf(1, &quot;%s\\n&quot;, path);\n            }\n            break;\n        case T_DEVICE:\n            if (strcmp(file, fmtname(path)) == 0) {\n                fprintf(1, &quot;%s\\n&quot;, path);\n            }\n            break;\n        case T_DIR:\n            if (strlen(path) + 1 + DIRSIZ + 1 &gt; sizeof(buf)) {\n                fprintf(2, &quot;find: path too long\\n&quot;);\n                close(fd);\n                exit(1);\n            }\n\n            strcpy(buf, path);\n\n            p = buf + strlen(buf);\n\n            *p++ = &#039;\/&#039;;\n\n            while (read(fd, &amp;de, sizeof(de)) == sizeof(de)) {\n                if (de.inum == 0) {\n                    continue;\n                }\n\n                memmove(p, de.name, DIRSIZ);\n                p[DIRSIZ] = 0;\n\n                struct stat prest;\n\n                if (stat(buf, &amp;prest) &lt; 0) {\n                    fprintf(2, &quot;find: cannot stat %s\\n&quot;, p);\n                    continue;\n                }\n\n                if (st.ino == prest.ino) {\n                    continue;\n                }\n\n                search(buf, file);\n            }\n\n            break;\n        default:\n            break;\n    }\n\n    close(fd);\n}\n\nint main(int argc, char *argv[]) {\n\n    if (argc &lt; 2 || argc &gt; 3) {\n        fprintf(2, &quot;Usage: find &lt;filename&gt;\\n&quot;);\n        exit(1);\n    }\n\n    search(argv[1], argv[2]);\n\n    exit(0);\n}<\/code><\/pre>\n<h2>6 xargs(moderate)<\/h2>\n<blockquote>\n<p>\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u5b9e\u73b0linux xargs\u57fa\u7840\u529f\u80fd\u3002<\/p>\n<p>xargs\u901a\u5e38\u548c\u7ba1\u9053\u4f7f\u7528\uff0c\u4f8b\u5982<\/p>\n<pre><code class=\"language-shell\">echo bye too | xargs echo hello<\/code><\/pre>\n<p>\u9996\u5148\u7ba1\u9053\u7684\u5de6\u8fb9\u6267\u884c<code>echo bye too<\/code>\u6b64\u65f6\u4f1a\u4ece\u6807\u51c6\u8f93\u51fa\u6d41\u4e2d\u8f93\u51fa<code>bye too<\/code>\u3002\u800c\u7ba1\u9053\u53f3\u4fa7\u6267\u884c<code>xargs<\/code>\u7a0b\u5e8f\uff0c\u8be5\u7a0b\u5e8f\u4ece\u7ba1\u9053\u7684\u5de6\u4fa7\u7684\u8f93\u51fa\u8bfb\u53d6\u4fe1\u606f\uff08\u4ece\u8be5\u7a0b\u5e8f\u7684\u6807\u51c6\u8f93\u5165\u6d41\u4e2d\u8bfb\u53d6\uff09\uff0c\u4f5c\u4e3a\u5373\u5c06\u8981\u8fd0\u884c\u7684<code>echo<\/code>\u7a0b\u5e8f\u7684\u6269\u5c55\u53c2\u6570\u3002<\/p>\n<p>\u5373\u6574\u4e2a\u547d\u4ee4\u884c\u76f8\u5f53\u4e8e\u6267\u884c\u4e86<code>echo hello bye too<\/code>\uff0c\u6240\u4ee5\u6253\u5370\u51fa\u4e86<code>hello bye too<\/code>\u3002<\/p>\n<\/blockquote>\n<h3>6.1 \u5b9e\u73b0\u65b9\u5f0f<\/h3>\n<h4>6.1.1 \u8bfb\u53d6\u5de6\u4fa7\u7684\u53c2\u6570<\/h4>\n<p>\u5b9a\u4e49\u4e00\u4e2a\u5168\u5c40\u53d8\u91cfbuf\u6765\u4fdd\u5b58\u8bfb\u53d6\u5230\u7684\u4fe1\u606f\u6d41\u3002\u6309\u7167\u9898\u76ee\u63cf\u8ff0\u7684\u8981\u6c42\uff0c\u6bcf\u4e00\u884c\u5c31\u662f\u4e00\u4e2a\u53c2\u6570\uff0c\u6240\u4ee5\u53ea\u8981\u8bfb\u5230\u6362\u884c\u7b26\uff0c\u6211\u4eec\u5c31\u5c06\u8be5\u6362\u884c\u7b26\u4fdd\u5b58\u4e3a<code>\u2018\\0\u2019<\/code>\uff0c\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\u4e32\uff08\u5373\u53c2\u6570\uff09\u7684\u7ed3\u675f\uff0c\u5e76\u7d2f\u8ba1\u53c2\u6570\u8ba1\u6570\u5668\u3002<\/p>\n<h4>6.1.2 \u6574\u5408\u7a0b\u5e8f\u53c2\u6570<\/h4>\n<p>\u65b0\u58f0\u660e\u4e00\u4e2aargs\u5b57\u7b26\u6307\u9488\u6570\u7ec4\uff0c\u4fdd\u5b58\u6bcf\u4e2a\u53c2\u6570\u7684\u8d77\u59cb\u5730\u5740\u3002\u9996\u5148\u5c06\u547d\u4ee4\u884c\u4e2d\u672c\u6709\u7684\u53c2\u6570\u4fdd\u5b58\u5728args\u4e2d\uff0c\u5728\u4ecebuf\u4e2d\u8bfb\u53d6\u7d2f\u8ba1\u7684\u53c2\u6570\u4e2a\u6570\u7684\u53c2\u6570\u7684\u8d77\u59cb\u5730\u5740\u3002<\/p>\n<pre><code class=\"language-C\">int argptr;\nchar *args[MAXARG];\nchar buf[512 * MAXARG];\n\nvoid getargs() {\n    char *p = buf;\n    char ch;\n    int count = 0;\n\n    while (p &amp;&amp; read(0, &amp;ch, 1)) {\n        if (ch == &#039;\\n&#039;) {\n            count++;\n            *p++ = &#039;\\0&#039;;\n        } else {\n            *p++ = ch;\n        }\n    }\n\n    *p = &#039;\\0&#039;;\n\n    if (read(0, &amp;ch, 1)) {\n        fprintf(2, &quot;xargs: args too long\\n&quot;);\n        exit(1);\n    }\n\n    if (count &gt; MAXARG) {\n        fprintf(2, &quot;xargs: args too long\\n&quot;);\n        exit(1);\n    }\n\n    p = buf;\n\n    while (count--) {\n        args[argptr++] = p;\n        p += strlen(p);\n        p++;\n    }\n}<\/code><\/pre>\n<p>\u6574\u4e2a\u7a0b\u5e8f\u7684\u96be\u70b9\u5c31\u5728\u8fd9\u91cc\u4e86\u3002<\/p>\n<h4>6.1.3 \u65b0\u5efa\u5b50\u8fdb\u7a0b<\/h4>\n<p>\u7528fork\u548cexec\u8fd0\u884c\u7a0b\u5e8f\u5373\u53ef\u3002<\/p>\n<h3>6.2 \u4ee3\u7801\u5b9e\u73b0<\/h3>\n<pre><code class=\"language-C\">#include &quot;kernel\/types.h&quot;\n#include &quot;kernel\/stat.h&quot;\n#include &quot;user\/user.h&quot;\n#include &quot;kernel\/param.h&quot;\n\nint argptr;\nchar *args[MAXARG];\nchar buf[512 * MAXARG];\n\nvoid getargs() {\n    char *p = buf;\n    char ch;\n    int count = 0;\n\n    while (p &amp;&amp; read(0, &amp;ch, 1)) {\n        if (ch == &#039;\\n&#039;) {\n            count++;\n            *p++ = &#039;\\0&#039;;\n        } else {\n            *p++ = ch;\n        }\n    }\n\n    *p = &#039;\\0&#039;;\n\n    if (read(0, &amp;ch, 1)) {\n        fprintf(2, &quot;xargs: args too long\\n&quot;);\n        exit(1);\n    }\n\n    if (count &gt; MAXARG) {\n        fprintf(2, &quot;xargs: args too long\\n&quot;);\n        exit(1);\n    }\n\n    p = buf;\n\n    while (count--) {\n        args[argptr++] = p;\n        p += strlen(p);\n        p++;\n    }\n}\n\nint main(int argc, char *argv[]) {\n\n    for (int i = 1; i &lt; argc; ++i) {\n        args[argptr++] = argv[i];\n    }\n\n    getargs();\n\n    if (fork() == 0) {\n        if (exec(argv[1], args) &lt; 0) {\n            fprintf(2, &quot;xargs: exec %s fail\\n&quot;, argv[1]);\n            exit(1);\n        }\n    }\n\n    wait(0);\n\n    exit(0);\n}<\/code><\/pre>\n<h2>7 END<\/h2>\n<p>\u6574\u4e2alab\u5c31\u5199\u5b8c\u4e86\uff0c\u6d4b\u8bd5\u7ed3\u679c\u5982\u4e0b\u3002<\/p>\n<pre><code>== Test sleep, no arguments == \n$ make qemu-gdb\nsleep, no arguments: OK (4.9s) \n== Test sleep, returns == \n$ make qemu-gdb\nsleep, returns: OK (0.9s) \n== Test sleep, makes syscall == \n$ make qemu-gdb\nsleep, makes syscall: OK (0.9s) \n== Test pingpong == \n$ make qemu-gdb\npingpong: OK (0.9s) \n== Test primes == \n$ make qemu-gdb\nprimes: OK (1.0s) \n== Test find, in current directory == \n$ make qemu-gdb\nfind, in current directory: OK (1.2s) \n== Test find, recursive == \n$ make qemu-gdb\nfind, recursive: OK (1.1s) \n== Test xargs == \n$ make qemu-gdb\nxargs: OK (1.3s) \n== Test time == \ntime: OK \nScore: 100\/100<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>xv6\u64cd\u4f5c\u7cfb\u7edf\u5b9e\u9a8c1\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[14],"class_list":["post-43","post","type-post","status-publish","format-standard","hentry","category-os","tag-xv6"],"_links":{"self":[{"href":"https:\/\/www.yewpo.top\/index.php\/wp-json\/wp\/v2\/posts\/43","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yewpo.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yewpo.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yewpo.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yewpo.top\/index.php\/wp-json\/wp\/v2\/comments?post=43"}],"version-history":[{"count":0,"href":"https:\/\/www.yewpo.top\/index.php\/wp-json\/wp\/v2\/posts\/43\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yewpo.top\/index.php\/wp-json\/wp\/v2\/media?parent=43"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yewpo.top\/index.php\/wp-json\/wp\/v2\/categories?post=43"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yewpo.top\/index.php\/wp-json\/wp\/v2\/tags?post=43"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}