2023年Linu实验报告新编.pdf
中南大学L in u x操作系统实验报告学生姓名_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _学院 信息科学与工程学院指导老师_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 胡小龙_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _专业班级_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _完毕时间目录1.实验一 L i nux的安装.错误!未定义书签。1.1 实验目的.错误!未定义书签。1.2 实验设备.错误!未定义书签。1.3 实验原理。错误!未定义书签。1.4 实验环节。错误!未定义书签。2.实验二Linux基本操作.错误!未定义书签。2.1 实验目的.错误!未定义书签。2 .2 实验设备。错误!未定义书签。2.3 实验原理。错误!未定义书签。2.4 实验环节。错误!未定义书签。3.实验三Li nux系统管理.错误!未定义书签。3.1 实验目的.错误!未定义书签。3.2 实验设备。错误!未定义书签。3.3 实验原理。错误!未定义书签。3.4 实验环节.错误!未定义书签。4.实验四Linux Shell程序设计。错误!未定义书签。4.1 实验目的。错误!未定义书签。4.2 实验设备。错误!未定义书签。4.3 实验原理.错误!未定义书签。4.4 实验环节.错误!未定义书签。5.实验五L i n u x 高级程序设计.错误!未定义书签。5.1 实验目的。错误!未定义书签。5.2 实验设备。错误!未定义书签。5.3 实验原理。错误!未定义书签。5.4 实验环节。错误!未定义书签。6.实验六 L in u x 内核25。6.1 实验目的。错误!未定义书签。6.2 实验设备.错误!未定义书签。6.3 实验原理.错误!未定义书签。6.4实验环节.错误!未定义书签。Linux操作系统1.实验一 L i mix的安装1.1 实验目的(1)了解硬盘分区的概念和方法;(2)掌握硬盘的分区规划;(3)掌握L in u x 操作系统的安装和配置过程。1.2 实验设备一台 pc 机、RedHat L inux 7.2 以上版本、VMware Workst a tion v5.5 o1.3 实验原理L i n u x 可以以多种方式安装在PC机上:(1)独立分区安装、(2)DOS分区安装和(3)虚 拟 机 VMW are下安装。鉴于V M w are下安装对本来系统影响较小且不影响本实验目的,因此采用VMWa r e 下安装方式。1.4 实验环节(1)在 W i ndo wsXP 下安装 VMware 5.5(2)配置虚拟机(3)启动虚拟机(4)启动Lin u x 安装过程(5)安装过程配置(6)安装后配置(7)第 1 次启动 VMWa r e 下 Linux操作系统V M w are W orkstation正在执行清求的操作消稽次,专等正在执行请求的媒惶.这可施笑要几方钟时间.状有:InstaOing packages on the system(上 一 步 下一步但)取3ubuntu0 14.04 LIS2.实验二 Lin u x 基本操作2.1 实验目的(1)复习L i n u x 基本命令;(2)掌握常用L in u x 命令。2.2实验设备一台 pc 机、R e dHa t Linux 7.2 以上版本、VM wa r e W o r k s t a t i o n v5.5。2.3 实验原理(i)练习命令行模式下的常用命令:m a n:命令帮助A LT-Fx:虚终端切换常用命令:cat、Ls ps chm o d k i 1 1 In、cp mv rm、cd、pwd mkdir、chown、who、w、WCN whoami d a te u nam e 等(2)编辑器v i的使用:使用v i建立并修改一个文本文献(3)档案管理r p m gzip、ta r 等命令(4)网络命令te 1 n e t f t p、t a 1 k2.4 实验环节(i)常用命令1.使 用m a n m a n命令查询m a n命令的M a n u a l:等 一(?)File Edit View Search Terminal HelpMAN(l)Manual pager utils MAN(l)NAMEman-an interface to the on-line reference manualsSYNOPSISman-C file-d-D-warnings=warntngsl -R encoding1 -Llocale-R systemf-M path -S list-e extension -t|-I-regex|-wildcard-names-only-a-u-no-subpages-Ppager -r prompt1 -7-E encoding -no-hyphenation-no-justification-p string -t-Tdevice -Hbrowser F-XFdpil1 -Zsection Dqe.nan-k apropos options eqexp.nan-K-w|-W-S list-t|-I-regex section term,nan-f whatis options!Daqe.man-1-C file-d-D f-warningsF=warnings11-R encoding -Llocale1 -P pager -r prompt -7-E encoding1 -p string -tr-Trdevicell r-HFbrowserll r-xrdptll-Z file.nan-w|-W-C file -d-D oaqenan-c-C file -d-D page,man-?VDESCRIPTIONManual page man(l)line 1(press h for help or q to quit)NAME章节指示了该命令的名字和简介;SY NO PSIS章节列出了该命令可用的使用方式及其符号;D E S C R IPT ION章节具体描述各使用方式及符号的作用;2 .c a t 查看/e t c /f s t a bf xaXA:/expxaXA:/exp$cat/etc/fstab#/etc/fstab:static file system information.#Use blkid to print the universally unique identifier for a#device;this may be used with UUID=as a more robust way to name devices#that works even if disks are added and removed.See fstab(5).n#n/was on/dev/sda7 during installationUUID=b6292ea3-4ddc-43f2-a654-a8faed2e5127/ext4 errors=remount-ro 0 1#/home was on/dev/sda5 during installation#UUID=769a5829-0fd7-47d8-95e8-a82d2bab2e7a/homea next4defaultsUUID=fld21be5-895e-4af6-a738-38d562e494f6/home0 2n swap was on/dev/sdb3 during installationext4defaultsUUID=0aea6926-a389-412-alOc-cfd7ad9be3ea none0 0 xaXA:/exp$1swapsw可以看出系统挂载了 3个文献系统,分别挂在/、/h o me、s w a p,它们都是通过U U I D指定其物理分区来定位的。3.1 5 歹 1 目录f xa)XA:*/expxaXA:-/e xp$ls/var/backups localcache lib lockxaXA:-/exp$|logn ailrunspool4.p s 列进程O G 曲View Search Terminal Help241500:00:00 gvfsd-burn2447700:00:00 telepathy-indie2453?00:00:00 m ission-control2465706:00:06 zeitgeist-datah2470700:00:00 zeitgeist-daemo2476700:00:00z e itg e is t-fts2491700:00:00 cat2524700:00:00 mount.ntfs2552?00:00:00 update-notifier2567700:00:00 oosplash2588?00:00:19 sofftce.b in2607700:00:07 update-manager2658?00:00:00 deja-dup-montto2800?00:00:00 kworker/ul7:22978?00:00:00 cupsd2981?00:00:00 dbus3362700:00:00 kworker/ul6:23373700:00:03 gnome-terminal3380?00:00:00 gnome-pty-helpe3381 Pts/100:00:00 bash3486700:00:00 kw orker/ul6:l3538?00:00:00 kworker/ul6:03579 pts/1xa0XA:$100:00:00PS5.v i 编辑器.-File Edit View Search Terminal Helpinclude main()p rtn tf();return;-INSERT-5,2 0-2 7 A U6.ta r 解压缩Q xa(XiAiir/exp.v Search Terminal HelpxaXA:/exp$cp/media/xa/Myl/Downloads/Android.tgz./xaXA:/exp$tar-xvf./Android.tgz|Q File Edit View Search Terminal HelpAndroid.docset/Contents/Resources/Documents/docs/images/brand/l.t_generxc_rgb_wo_45.pngAndroid.docset/Contents/Resources/Documents/docs/tmages/brand/lt_generic_rgb_wo_60.pngAndroid.docset/Contents/Resources/Documents/docs/tmages/brand/lv_genertc_rgb_wo_45.pngAndrotd.docset/Contents/Resources/Documents/docs/tmages/brand/lv_generic_rgb_wo_66.pngAndroid.docset/Contents/Resources/Documents/docs/images/brand/mediaplayer.pngAndroid.docset/Contents/Resources/Documents/docs/tmages/brand/ms_genertc_rgb_wo_45.pngAndrotd.docset/Contents/Resources/Documents/docs/tmages/brand/ms_genertc_rgb_wo_66.pngAndroid.docset/Contents/Resources/Documents/docs/images/brand/nl_app_rgb_wo_45.pngAndroid.docset/Contents/Resources/Documents/docs/images/brand/nl_app_rgb_wo_60.pngAndroid.docset/Contents/Resources/Documents/docs/images/brand/nl_generic_rgb_wo_45.pngAndroid.docset/Contents/Resources/Documents/docs/images/brand/nl_genertc_rgb_wo_66.pngAndroid.docset/Contents/Resources/Documents/docs/tmages/brand/no_genertc_rgb_wo_45.png7.t e l n e t 远程登录路由器爨 xaXA:/exp.ermina!xaXA:-/exp$telnet 192.168.2.10Trying 192.168.2.10.Connected to 192.168.2.10.Escape character is A.DD-W RT v24-sp2 std(c)2012 NewMedia-NET G m bHRelease:02/11/13(SVN revision:20675)Texot login:rootPassword:|s s h远程登录i P a dO O xaXA:/expaXA:-/exp$ssh root192.168.2.103_oot192.168.2.163s password:erox:-root#uname)arwinerox:-root#Is-ibrary/Media/passwd 等观测:/etc/pa s s w d文献(2)文献系统管理d f、du命令使用moun t、u m o unt命令使用:安装usb盘或者光盘,查看分析/etc/fstab文献(3)存储器free:了解存储器使用情况(4)关机halt shutdown-h、init 0reboot、shu t do wn-r now并比较它们之间的差别(5)网络配置netcon f i g 的使用(6)启动配置/el c/ini t tab:查看、修改并观测其响应3.4实验环节(1)用户管理1.adduser:O 翁附pw Search Terminal HelpxaXA:/exp$sudo adduser testaddsudo password for xa:Adding user testadd*,Adding new group testadd1(1002)Adding new user testadd1(1001)with group testadd*.Creating home directory/home/testadd1.Copying files from/etc/skelEnter new UNIX password:Retype new UNIX password:passwd:password updated successfullyChanging the user information for testaddEnter the new value,or press ENTER for the defaultFull Name:Test User For ExpRoom Number:Work Phone:Home Phone:Other:Is the information correct?Y/n YxagXA:-/exp$|痼X配i&/域pw Search Terminal Helpgnats:x:41:41:Gnats Bug-Reporting System(admin):/var/lib/gnats:/usr/sbin/nologinnobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologinlibuuid:x:100:101:/var/lib/libuuid:/bin/shsyslog:x:101:103:/home/syslog:/bin/falsemessagebus:x:102:105:/var/run/dbus:/btn/falseusbmux:x:103:46:usbmux daemon,:/home/usbmux:/bin/falsednsmasq:x:104:65534:dnsmasq,:/var/lib/misc:/bin/falseavahi-autoipd:x:105:lll:Avahi autoip daemon,:/var/lib/avahi-autoipd:/bin/falsekernoops:x:106:65534:Kernel Oops Tracking D a e m o n/b i n/f a l s ertkit:x:107:113:RealtimeKit,:/proc:/bin/falsewhoopsie:x:108:114:/nonexistent:/bin/falsespeech-dispatcher:x:109:29:Speech Dispatcher,:/var/run/speech-dispatcher:/bin/shavahi:x:110:116:Avahi mDNS daemon,:/var/run/avahi-daemon:/bin/falselightdm:x:ill:117:Light Display Manager:/var/ltb/lightdR:/btn/falsepulse:x:112:119:PulseAudio daemon,:/var/run/pulse:/btn/falsehpltp:x:113:7:HPLIP system user,:/var/run/hplip:/btn/falsecolord:x:114:122:colord colour management daemon,:/var/lib/colord:/bin/falsesaned:x:115:123:/home/saned:/btn/falsexa:x:1000:1000:XA,:/home/xa:/bin/bashvboxadd:x:999:1:/var/run/vboxadd:/bin/falsetestadd:x:1001:1002:Test User For Exp,:/home/testadd:/bin/bash|xaXA:/exp$_2.passwd 命令修 e 合 xaXA:/expxaXA:-/exp$sudo passwd testaddEnter new UNIX password:Retype new UNIX password:passwd:password updated successfullyxaXA:-/exp$|(2)文献系统管理1.d f d u:。xa(Q)XA:/exp Search Terminal HelpxagXA:-/exp$dfFilesystemIK-blocksUsed A vailableUse%Mounted on/dev/sda5153492647351844719466451%/none4040%/sys/fs/cg ro u pudev19387961219387841%/devtmpfs38977613003884761%/runnone5120051200%/ru n/lo c knone194886815619487121%/run/shmnone102400401023601%/run/user/dev/sdbl149749768578676561249261%/home/dev/sda797911060 749337602297730077%/m edia/xa/M ylxaXA:-/exp$du h e llo w o rld.c4 h e llo w o rldcxaXA:/exp$|2 .m o u n t、u m o u n t:0 0 xXA,i&/expw Search Terminal HelpxaXA:-/exp$sudo mount-o rw-t ntfs/dev/sdal/medta/xa/WtnxaXA:/exp$cd/nedta/xa/Wtn/xa0XA:/nedia/xa/Wtn$Is _xaXA:/nedta/xa/Wtn$cd-/home/xa/expxaXA:-/exp$sudo amount/medta/xa/Wtnxa0XA:/exp$|3 .查看 f s t a b:e e File Edit View Search Terminal HelpxaXA:/exp$cat/etc/fstab#/etc/fstab:static file system information.*#Use blktd1 to print the universally unique identifier for a#device;this may be used with UUID=as a more robust way to name devicesn that works even if disks are added and removed.See fstab(5).#mount point#/was on/dev/sda7 during installationUUID=b6292ea3-4ddc-43f2-a654-a8faed2e5127/-o 0 1ext4errors=remount#/home was on/dev/sda5 during Installation#UUID=769a5829-0fd7-47d8-95e8-a82d2bab2e7a/homeext4defaultsU LUUID=fld21be5-895e-4af0-a738-38d562e494f6/homeA Oext4defaultsU L.#swap was on/dev/sdb3 during installationUUID=6aea6926-a389-4126-al0c-cfd7ad9be3ea none0 0 xaXA:/exp$|swapsw(3)存储系统f r e e 命令查看存储器状态.xa)XA:/expxagXA:-/exp$freetotalMen:3897740-/+buffers/cache:Swap:0 xaXA:-/exp$|used28635767721600free103416431255800shared289480buffers522676cached1568740(4 )网络配置i f c o nfi g。痈诫pw Search Terminal HelpxagXA:/exp$tfconftgeth6 Link encap:Ethernet HWaddr 00:O9:lc:0e:16:lfinet addr:192.168.2.100 Beast:192.168.2.255 Mask:255.255.255.0inet6 addr:fe80:269:leff:fe0e:161f/64 Scope:LinkUP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:3319 errors:3 dropped:overruns:frame:3TX packets:2830 errors:dropped:overruns:carrier:collisions:txqueuelen:1000RX bytes:3399535(3.3 MB)TX bytes:322938(322.9 KB)lo Link encap:Local Loopbackinet addr:127.0.0.1 Mask:255.0.0.0inet6 addr:1/128 Scope:HostUP LOOPBACK RUNNING MTU:65536 Metric:1RX packets:216 errors:dropped:overruns:frame:TX packets:216 errors:dropped:overruns:carrier:collisions:txqueuelen:0RX bytes:93668(93.6 KB)TX bytes:93668(93.6 KB)wlan0 Link encap:Ethernet HWaddr 64:27:37:d6:da:23UP BROADCAST MULTICAST MTU:1560 Metric:1RX packets:errors:dropped:0 overruns:frame:TX packets:errors:dropped:overruns:carrier:collisions:txqueuelen:1000RX bytes:6(0.0 B)TX bytes:0(0.0 B)xaXA:-/exp$|4.实验四Li n ux She 1 1程序设计4.1 实验目的(1)掌握L inux she 1 1程序运营方法;(2)掌握Linux She 1 1程序基本语法;(3)了解L i n u x 环境变量;(4)编写简朴Li n ux s h ell程序。4.2 实验设备一台 pc 机、R e dHat Lin u x 7.2 以上版本、VM ware W o rk s tati o n v5.5o4.3 实验原理(1)查看/etc/,p r o f i le 文献:相称于 D OS 下 a u toex e.b a t(2)通配符“*”、“?一 口”的使用$1 s a-c 大 和$ls*命令(3)重定向和管道的使用6 1 s|moreca t te s t.txt(4)变量$1 o o kup=/u s r/mydir$e c h o$look u p$expor t loo k u p:让进程使用(5)编辑并运营以下程序(s h ell程序控制结构)1 f o rtest#!/bi n/b a s hfor a in x y zd oecho now a=$ao n e2 f ort e s t 1#!/b in/b a s hfo r adoe c ho now a=$ado n e3 f unctest#!/bin/b as hsetup()6。echo set u p s d odate()(s d a te)h g d i r()(8cd$1)do_da t e s etu pchg d ir4 p aram t est#!/bin/b a sh ec h o f i 1 e nam e:$0echo ar g uments:$*e cho n umber arg:$#e c h o a r g 2:$2o s h i f te ch o n um b er a r g:$#c h o ar g 2:$2se t h ell o,evero n ee cho arg s:$*e c h o arg 2:$25 untilte s t#!/bin/b ashnum b er=0n til(t e s t$number-gt 5)doecho$num b e r 0 n umber=ex p r$n umber+V3do n e4.4实验环节(i)查看文献rootlocalhost Desktop#vi/etc/.p ro filerootlocalhost Desktop#vi/etc/.p ro filerootlocalhost Desktop#cat test.txtwo shishuia rootlocalhost Desktop#|屏幕上的内容定向到text中。file dit yiew S e a rch lenninal H elpjo shishuia(2)输入输出重定向在 L in ux命令行模式中,假如命令所需的输入不是来自键盘,而是来自指定的文献,这就是输入重定向。同理,命令的输出也可以不显示在屏幕上,而是写入到指定文献中,这就是输出重定向。c o m m a n d f i l e:将命令的输出结果重定向到一个文献。com m a n d&f il e:将命令的标准错误输出一起重定向到一个文献。com m a n d f i 1 e:将标准输出的结果追加到文献中。com m a n d&f i 1 e:将标准输出和标准错误输出的结构都追加到文献中。如#I s -1 l is t,t xt(3)管道 p i pe将某一个程序的输出送到另一个程序的输入com m a n d 1|com m an d 2 I c om m an d 3.也可以连同标准错误输出一起送入管道:comma n d 1|&c o mmand2|&comm a n d 3.(5)$1 oo k up=/usr/my d ir该命令建立一个名为loo k u p 的变量并给其赋值/u s r/m y di r,以后用户可以在命令行中使用looku p 来代替/u s r/m y dir,$e cho$lookup结果显示:/u s r /mydir为了使变量能被子进程使用,可用exprot命令,例如:$1o okup=/u s r/mydi r(6)运 营 s h e ll程序S h e ll 程序 1:七_营c盘;力0-备|12二She 1 1 程序 2:大;也 国 23:45 0ISITl-;号日Fe_B*TS h el l 程序 3:echo setupdo_date()date:hgdlr()|cd$1do_dateLlbreOfflce WriterFun3.$hfun3.sh-gedlt 打 开保存&Mt消Qrunl-:un3-;面$chnod*x fun3.sh:面S fun3g-SVT13128CCS:-/桌面setupchgdtrchengcheng-SVTISIZSCCfun3.$h xBl/btn/bashsetup()jngchcng-SVT13128CCS:-/jR j,3128CCS:-/J|(i4raWWE,g w c r g a s ty to a w iE (simpWird)-sh :8*行 io.列 9 版入,中南大学第一届大学生信息安全应用创新大赛全国大学生信口16 名表.docx第顼项-云计舞比赛:hengcheng-SVT13128CCS:-/Mh:./f u n 3:没有那个文/或目录:hengcheng-SVTni28CCS:-/jKiE$./funJ.sh5h:./funa.sh:b tn/b ash:坏的解释翦:没有那个文件或目录:hengcheng-SVT13128CCS:-/j|lDB$./fun3.sh!”4年 11 月 190 星期三 1。:31:8 CSTS h e 1 1 程序 4:龙。*10:37 chengcheng-SVT13128CCS:-/JRflG$chnod+x fun4.shchengcheng-SV113128CCS:-/川面$./fu n 4.shfilenam e:,/fun4.sharguments:number arg:O6 cheng(9cheng-SVT13128CCS:*/*:hengecheng-SVT13128CCS:-/jftK$|number arg:Oargz:argsjheUo,everyone:hengcheng-SVT13128CCS:-/桌面$vln fun4.sh:henflcheng-SVTniZ8CCS:-/Mffi$vtm fun4.shUbrcomc*Wri(*rShel I 程序5echoaig2:S2rilMnbashnumbcnOunid(tnt Snumber-gj 5)echo-Snumbernumber etrSnumbef 1donechengcheng-SVT13128CCS:/*3 i&审巧-邕Ai n t t l i te s tsNewftofnanSWWJIS?10:41 0,盈/A至国图|入实物要求(1)每个shell程序事例运行多退,并给不同着数5.实验五L in u x 高级程序设计5.1 实验目的(1)了解Li n ux操作系统下应用程序开发流程(2)掌握g u n 工具链的使用(3)了解Lin ux高级编程技巧(例如IPC机制、系统调用等)5.2 实验设备一台 pc 机、RedHat L i nux 7.2 以上版本、V Mwar e W o r kstatio n v5.5。5.3 实验原理(1)编写一个简朴的C 语言程序,编写Makefile文献。了解编译过程,并用gdb进行调试。(2)以下任选其一:1.编写一个多进程通信程序,采 用 M e ssag e Que u e 或 s hare d M e m o ry 或者M叩ed F ile机制进行通信2.编写一个多线程程序(pthrea d),实现2程同步互斥5.4实验环节(1)写出源程序,并编译运营c编程:11:14 0chan9(chen9-SVT13128CCS:-/worktpc/C|hellow ord/workspace/Cprogram$vim h e llo w o rd.c:-/w orkspace/C progranS,:-/w orkspace/C progran$en9cheng-5VT13128CCS:-/,:无法获取“h e U o w o rd.Lcheng9chrng-SVT13128CCS:-/worksphellow ord:f i l e n o t re co n tie d:c o lle c t?:e rro r:Id returned 1 e x it sta tu sCprogramS mv h e llo w o rd.c hellow ord(s t a t):没有那个文件或目录gcc h e llo w o rd.c./h e llo-o h e llo/h e lloo h e lloh e llo w o rd.c hellow ord三?四白备一,=2014Linux2G 主文件夹 workspace Cprogram位 ch e n g-SVT 1 3 1 2 8C C S:/w o r k s p a ce/C p r o gr a mn t i t e r a t e(i n t v a l u e)i f(=v a l u e)r e t u r n ;r e t u r n t t e r a t e(v a l u e -)+v a l u e;t n t m a t n()p r i n t f(d ,t t e r a t e();r e t u r n ;)r i n t t e s t.cH 1 3 L,1 81 C全部6.实验六L in u x内核6.1 实验目的(1 )了解L in ux操作系内核(2)掌握内核编译和内核升级方法(3)了解有关内核编程6.2 实验设备一台 p c 机、R edH at L in u x 7.2 以上版本、V M w a r e W or k s ta t ion v5.5 o6.3 实验原理(i)内核配置和编译(课后完毕)(2)察看/pr oc内存文献系统下的文献,写出每个目录内容 编写一个简朴的字符虚拟设备程序(以模块方式编译、加载、使用)6.4 实验环节s tr u ct f i 1 e _ o pera t ion s statu s _ fo p s