{"id":371,"date":"2017-01-12T19:37:20","date_gmt":"2017-01-12T11:37:20","guid":{"rendered":"http:\/\/blog.messi.moe\/?p=371"},"modified":"2017-01-12T19:37:20","modified_gmt":"2017-01-12T11:37:20","slug":"linux-os-final","status":"publish","type":"post","link":"https:\/\/blog.messi.moe\/?p=371","title":{"rendered":"Linux OS Final"},"content":{"rendered":"<h2>1. Linux Basic Commands (5 marks)<\/h2>\n<h3>Make rational utilization of instruction, completing the following tasks\uff1a<\/h3>\n<h4>(1) Print current time information of system<\/h4>\n<pre><code class=\"bash\">lsz@Test:~$ date\nThu Jan 12 01:35:05 EST 2017\n<\/code><\/pre>\n<h4>(2) Display processor architecture and the kernel version<\/h4>\n<pre><code class=\"bash\">lsz@Test:~$ uname -a\nLinux Test 2.6.32-042stab112.15 #1 SMP Tue Oct 20 17:22:56 MSK 2015 x86_64 x86_64 x86_64 GNU\/Linux\n<\/code><\/pre>\n<h4>(3) Reboot the system after twenty minutes and inform all users logged on so that they can save their work<\/h4>\n<pre><code class=\"bash\">root@Test:~# shutdown -r +20 \"The system will reboot after 20 minutes!\"\n<\/code><\/pre>\n<h2>2. Crontab (10 marks)<\/h2>\n<h3>A system administrator may have to do some repetitive work every day, while crontab is a very useful tool, you should answer following questions.<\/h3>\n<h3>Complete the following tasks with the tool of crontab:<\/h3>\n<h4>(1) Remove all the subdirectories and files in &#8220;\/cdf&#8221; directory at 2:10 a.m every day<\/h4>\n<h4>(2) If Sunday, copy all the directories and files in \/user\/backup to \/tmp at 0:0 a.m<\/h4>\n<pre><code class=\"bash\">root@Test:~# vim task.sh\n10 2 * * * rm -rf \/cdf\/*\n0 0 * * 6 copy -r \/user\/backup \/tmp\nroot@Test:~# crontab task.sh\n<\/code><\/pre>\n<h2>3. Shell Programming (10 marks)<\/h2>\n<pre><code class=\"bash\">a1=0\na2=0\na3=0\nsum=0\nwhile read def num rel\ndo \na3=$(($a3+1))\nif [ \"$rel\" == \"1\" ];\nthen a2=$(($bb+1))\n     a1=$a2\n     tt=$(echo \"scale=5;$a1\/$k\"|bc -l)         \n     sum=$(echo \"scale=5;$sum+$tt\"|bc -l)\nfi\ndone &lt; result.txt                                             \nAP=$(echo \"scale=5;$sum\/$a2\"|bc -l)   \necho \"a2=$a2 sum=$sum AP=$AP\"\n<\/code><\/pre>\n<h2>4. SSH Login (15 marks)<\/h2>\n<h3>Write one method of non-interactive ssh connection between two linux servers.<\/h3>\n<h3>Server A IP : 10.193.251.191<\/h3>\n<h3>Server B IP : 10.193.251.192<\/h3>\n<h3>The two linux servers both have root users and you can take root users as example.<\/h3>\n<p>Generate a pair of keys in Server A (in root)<\/p>\n<pre><code class=\"bash\">root@Test:~# ssh-keygen -t rsa\n<\/code><\/pre>\n<p>Login to Server B, make directory <code>.ssh<\/code><\/p>\n<pre><code class=\"bash\">lsz@Test:~# mkdir .ssh\nlsz@Test:~# chmod 700 .ssh\n<\/code><\/pre>\n<p>Copy public key to B from A<\/p>\n<pre><code>root@Test:~# scp .ssh\/id_rsa.pub root@10.193.251.192:~\/.ssh\/authorized_keys\n<\/code><\/pre>\n<h2>5. Shell Programming to Compute (15 marks)<\/h2>\n<pre><code>0 0 1\n0 100 1\n0 101 0\n0 102 0\n0 103 1\n0 104 0\n0 105 1\n0 106 1\n0 107 1\n0 108 0\n0 109 0\n0 10 0\n0 110 1\n\u2026\n<\/code><\/pre>\n<h3>Above is the top 1000 result from an image retrieval system. The first column is default value, and the second and third column indicate the rank and the relevance of the image. For example, (0 100 1) means that the 100th image is relevant. Please write shell program to compute the AP(average precision).<\/h3>\n<h3>Rq is the number of relevant images regarding the instance topic q. rel (k) is an indicator function of relevance and irrelevance, and if the k th ranked video is relevant to q, rel (k) is 1. On the other hand, if the k th ranked video is irrelevant to q, rel (k) is 0. c(k) is the accumulated number of correct videos retrieved upper k th rank.<\/h3>\n<pre><code>a1=0\na2=0\na3=0\nsum=0\nwhile read def num rel\ndo \na3=$(($a3+1))\nif [ \"$rel\" == \"1\" ];\nthen a2=$(($bb+1))\n     a1=$a2\n     tt=$(echo \"scale=5;$a1\/$k\"|bc -l)         \n     sum=$(echo \"scale=5;$sum+$tt\"|bc -l)\nfi\ndone &lt; result.txt                                             \nAP=$(echo \"scale=5;$sum\/$a2\"|bc -l)   \necho \"a2=$a2 sum=$sum AP=$AP\"\n<\/code><\/pre>\n<h2>7. gcc<\/h2>\n<h3>Write an ANSI C \/C++ code. Use a Makefile to build it (including compile and link) into binary file. The function of this binary file should be: Given two binary strings, return their sum (also a binary string). or example, a = &#8220;11&#8221; b = &#8220;1&#8221; Return c = &#8220;100&#8221;.<\/h3>\n<h3>You should give:<\/h3>\n<h4>1. Makefile (hint: four files, main.cpp\uff0cfunction.cpp\uff0cfunction.h, makefile).<\/h4>\n<h4>2. All C\/C++ source code. main.cpp only passes parameter of input output and use the command line to pass the parameters to the main() .<\/h4>\n<h4>3. The whole procedure of how you compile and link C code.<\/h4>\n<p>8<\/p>\n<pre><code class=\"cpp\">\/\/ main.cpp\n#include &lt;iostream&gt;\n#include &lt;string&gt;\n#include &lt;math.h&gt;\nusing namespace std;\n\nint b2d(string b)\n{\n    int d=0;\n    int len=b.size();\n    for(int i=len-1;i&gt;=0;i--)\n    {\n        int f=0;\n        if(b[i]=='1') f=1;\n        d=d+f*(pow(2,len-i-1));\n    }\n    return d;\n}\n\nint d2b(int d)\n{\n    int s[30];\n    int b=0;\n    for (int i=0;i&lt;30;i++) s[i]=pow(2,i-1);\n    int digit=30;\n    while (d&gt;0)\n    {\n        for (int i=digit-1;i&gt;=0;i--) \n        {\n            if(d&gt;=s[i]) \n            {\n                digit=i+1;\n                b=b+pow(10,i-1);\n                d=d-s[i];\n            }\n        }\n    }\n    return b;\n}\n\nint main()\n{\n    string m,n;\n    cout&lt;&lt;\"Please input m:\";cin&gt;&gt;m;\n    cout&lt;&lt;\"Please input n:\";cin&gt;&gt;n;\n    cout&lt;&lt;d2b(b2d(m)+b2d(n));\n    return 0;\n}\n<\/code><\/pre>\n<pre><code class=\"makefile\">CC=gcc\nOBJS=main.o reverse.o\nSRCS=main.cpp reverse.c\n\nmain:main.o reverse.o\n    $(CC) -o main $(SRCS)\nclean:\n    rm -rf main $(OBJS)\n<\/code><\/pre>\n<h2>8. NFS Mount<\/h2>\n<p>\u4e00\u3001\u670d\u52a1\u5668\u7aef<br \/>\n\u7f16\u8f91\/etc\/exports<br \/>\n\/home\/data1 10.193.251.192.<em>(ro,all_squash)<br \/>\n\/home\/data2 10.193.251.192.<\/em>(rw,sync,root_squash)<br \/>\n\/home\/data3 10.193.251.192.*(rw,async,no_root_squash)<br \/>\n\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8NFS\u534f\u8bae\uff1a<br \/>\n\/etc\/rc.d\/init.d\/portmap start<br \/>\n\/etc\/rc.d\/init.d\/nfs start<br \/>\n\u4e8c\u3001\u5ba2\u6237\u7aef\u7684\u64cd\u4f5c<br \/>\n\u672c\u5730\u6302\u8f7d\u70b9\u4e3a\/mnt\/nfs<br \/>\nmount -t nfs 10.193.251.191:\/home\/data1 \/mnt\/nfs<br \/>\nmount -t nfs 10.193.251.191:\/home\/data2 \/mnt\/nfs<br \/>\nmount -t nfs 10.193.251.191:\/home\/data3 \/mnt\/nfs<\/p>\n","protected":false},"excerpt":{"rendered":"<h2>1. Linux Basic Commands (5 marks)<\/h2>\n<h3>Make rational utilization of instruction, completing the following tasks\uff1a<\/h3>\n<h4>(1) Print current time information of system<\/h4>\n<pre><code class=\"bash\">lsz@Test:~$ date\nThu Jan 12 01:35:05 EST 2017\n<\/code><\/pre>\n<h4>(2) Display processor architecture and the kernel version<\/h4>\n<pre><code class=\"bash\">lsz@Test:~$ uname -a\nLinux Test 2.6.32-042stab112.15 #1 SMP Tue Oct 20 17:22:56 MSK 2015 x86_64 x86_64 x86_64 GNU\/Linux\n<\/code><\/pre>\n<h4>(3) Reboot the system after twenty minutes and inform all users logged on so that they can save their work<\/h4>\n<pre><code class=\"bash\">root@Test:~# shutdown -r +20 \"The system will reboot after 20 minutes!\"\n<\/code><\/pre>\n<h2>2. Crontab (10 marks)<\/h2>\n<h3>A system administrator may have to do some repetitive work every day, while crontab is a very useful tool, you should answer following questions.<\/h3>\n<h3>Complete the following tasks with the tool of crontab:<\/h3>\n<h4>(1) Remove all the subdirectories and files in &#8220;\/cdf&#8221; directory at 2:10 a.m every day<\/h4>\n<h4>(2) If Sunday, copy all the directories and files in \/user\/backup to \/tmp at 0:0 a.m<\/h4>\n<pre><code class=\"bash\">root@Test:~# vim task.sh\n10 2 * * * rm -rf \/cdf\/*\n0 0 * * 6 copy -r \/user\/backup \/tmp\nroot@Test:~# crontab task.sh\n<\/code><\/pre>\n<h2>3. Shell Programming (10 marks)<\/h2>\n<pre><code class=\"bash\">a1=0\na2=0\na3=0\nsum=0\nwhile read def num rel\ndo \na3=$(($a3+1))\nif [ \"$rel\" == \"1\" ];\nthen a2=$(($bb+1))\n     a1=$a2\n     tt=$(echo \"scale=5;$a1\/$k\"|bc -l)         \n     sum=$(echo \"scale=5;$sum+$tt\"|bc -l)\nfi\ndone &lt; result.txt                                             \nAP=$(echo \"scale=5;$sum\/$a2\"|bc -l)   \necho \"a2=$a2 sum=$sum AP=$AP\"\n<\/code><\/pre>\n<h2>4. SSH Login (15 marks)<\/h2>\n<h3>Write one method of non-interactive ssh connection between two linux servers.<\/h3>\n<h3>Server A IP : 10.193.251.191<\/h3>\n<h3>Server B IP : 10.193.251.192<\/h3>\n<h3>The two linux servers both have root users and you can take root users as example.<\/h3>\n<p>Generate a pair of keys in Server A (in root)<\/p>\n<pre><code class=\"bash\">root@Test:~# ssh-keygen -t rsa\n<\/code><\/pre>\n<p>Login to Server B, make directory <code>.ssh<\/code><\/p>\n<pre><code class=\"bash\">lsz@Test:~# mkdir .ssh\nlsz@Test:~# chmod 700 .ssh\n<\/code><\/pre>\n<p>Copy public key to B from A<\/p>\n<pre><code>root@Test:~# scp .ssh\/id_rsa.pub root@10.193.251.192:~\/.ssh\/authorized_keys\n<\/code><\/pre>\n<h2>5. Shell Programming to Compute (15 marks)<\/h2>\n<pre><code>0 0 1\n0 100 1\n0 101 0\n0 102 0\n0 103 1\n0 104 0\n0 105 1\n0 106 1\n0 107 1\n0 108 0\n0 109 0\n0 10 0\n0 110 1\n\u2026\n<\/code><\/pre>\n<h3>Above is the top 1000 result from an image retrieval system. The first column is default value, and the second and third column indicate the rank and the relevance of the image. For example, (0 100 1) means that the 100th image is relevant. Please write shell program to compute the AP(average precision).<\/h3>\n<h3>Rq is the number of relevant images regarding the instance topic q. rel (k) is an indicator function of relevance and irrelevance, and if the k th ranked video is relevant to q, rel (k) is 1. On the other hand, if the k th ranked video is irrelevant to q, rel (k) is 0. c(k) is the accumulated number of correct videos retrieved upper k th rank.<\/h3>\n<pre><code>a1=0\na2=0\na3=0\nsum=0\nwhile read def num rel\ndo \na3=$(($a3+1))\nif [ \"$rel\" == \"1\" ];\nthen a2=$(($bb+1))\n     a1=$a2\n     tt=$(echo \"scale=5;$a1\/$k\"|bc -l)         \n     sum=$(echo \"scale=5;$sum+$tt\"|bc -l)\nfi\ndone &lt; result.txt                                             \nAP=$(echo \"scale=5;$sum\/$a2\"|bc -l)   \necho \"a2=$a2 sum=$sum AP=$AP\"\n<\/code><\/pre>\n<h2>7. gcc<\/h2>\n<h3>Write an ANSI C \/C++ code. Use a Makefile to build it (including compile and link) into binary file. The function of this binary file should be: Given two binary strings, return their sum (also a binary string). or example, a = &#8220;11&#8221; b = &#8220;1&#8221; Return c = &#8220;100&#8221;.<\/h3>\n<h3>You should give:<\/h3>\n<h4>1. Makefile (hint: four files, main.cpp\uff0cfunction.cpp\uff0cfunction.h, makefile).<\/h4>\n<h4>2. All C\/C++ source code. main.cpp only passes parameter of input output and use the command line to pass the parameters to the main() .<\/h4>\n<h4>3. The whole procedure of how you compile and link C code.<\/h4>\n<p>8<\/p>\n<pre><code class=\"cpp\">\/\/ main.cpp\n#include &lt;iostream&gt;\n#include &lt;string&gt;\n#include &lt;math.h&gt;\nusing namespace std;\n\nint b2d(string b)\n{\n    int d=0;\n    int len=b.size();\n    for(int i=len-1;i&gt;=0;i--)\n    {\n        int f=0;\n        if(b[i]=='1') f=1;\n        d=d+f*(pow(2,len-i-1));\n    }\n    return d;\n}\n\nint d2b(int d)\n{\n    int s[30];\n    int b=0;\n    for (int i=0;i&lt;30;i++) s[i]=pow(2,i-1);\n    int digit=30;\n    while (d&gt;0)\n    {\n        for (int i=digit-1;i&gt;=0;i--) \n        {\n            if(d&gt;=s[i]) \n            {\n                digit=i+1;\n                b=b+pow(10,i-1);\n                d=d-s[i];\n            }\n        }\n    }\n    return b;\n}\n\nint main()\n{\n    string m,n;\n    cout&lt;&lt;\"Please input m:\";cin&gt;&gt;m;\n    cout&lt;&lt;\"Please input n:\";cin&gt;&gt;n;\n    cout&lt;&lt;d2b(b2d(m)+b2d(n));\n    return 0;\n}\n<\/code><\/pre>\n<pre><code class=\"makefile\">CC=gcc\nOBJS=main.o reverse.o\nSRCS=main.cpp reverse.c\n\nmain:main.o reverse.o\n    $(CC) -o main $(SRCS)\nclean:\n    rm -rf main $(OBJS)\n<\/code><\/pre>\n<h2>8. NFS Mount<\/h2>\n<p>\u4e00\u3001\u670d\u52a1\u5668\u7aef<br \/>\n\u7f16\u8f91\/etc\/exports<br \/>\n\/home\/data1 10.193.251.192.<em>(ro,all_squash)<br \/>\n\/home\/data2 10.193.251.192.<\/em>(rw,sync,root_squash)<br \/>\n\/home\/data3 10.193.251.192.*(rw,async,no_root_squash)<br \/>\n\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8NFS\u534f\u8bae\uff1a<br \/>\n\/etc\/rc.d\/init.d\/portmap start<br \/>\n\/etc\/rc.d\/init.d\/nfs start<br \/>\n\u4e8c\u3001\u5ba2\u6237\u7aef\u7684\u64cd\u4f5c<br \/>\n\u672c\u5730\u6302\u8f7d\u70b9\u4e3a\/mnt\/nfs<br \/>\nmount -t nfs 10.193.251.191:\/home\/data1 \/mnt\/nfs<br \/>\nmount -t nfs 10.193.251.191:\/home\/data2 \/mnt\/nfs<br \/>\nmount -t nfs 10.193.251.191:\/home\/data3 \/mnt\/nfs<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.messi.moe\/index.php?rest_route=\/wp\/v2\/posts\/371"}],"collection":[{"href":"https:\/\/blog.messi.moe\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.messi.moe\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.messi.moe\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.messi.moe\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=371"}],"version-history":[{"count":8,"href":"https:\/\/blog.messi.moe\/index.php?rest_route=\/wp\/v2\/posts\/371\/revisions"}],"predecessor-version":[{"id":379,"href":"https:\/\/blog.messi.moe\/index.php?rest_route=\/wp\/v2\/posts\/371\/revisions\/379"}],"wp:attachment":[{"href":"https:\/\/blog.messi.moe\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.messi.moe\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.messi.moe\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}