![linux实验报告(2)_第1页](http://file3.renrendoc.com/fileroot_temp3/2021-12/3/e04a2a80-4d9b-4096-a688-9ac9c38ffa26/e04a2a80-4d9b-4096-a688-9ac9c38ffa261.gif)
![linux实验报告(2)_第2页](http://file3.renrendoc.com/fileroot_temp3/2021-12/3/e04a2a80-4d9b-4096-a688-9ac9c38ffa26/e04a2a80-4d9b-4096-a688-9ac9c38ffa262.gif)
![linux实验报告(2)_第3页](http://file3.renrendoc.com/fileroot_temp3/2021-12/3/e04a2a80-4d9b-4096-a688-9ac9c38ffa26/e04a2a80-4d9b-4096-a688-9ac9c38ffa263.gif)
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、linux姓名班级学号指导老师试验报告黄芳恺 软件工程 114119074258阮越名目试验一 linux 基本命令的使用试验二简洁 shell 程序设计 试验三linux 下简洁 c 程序设计与文件操作试验四 linux 下进程操作与进程间通信 试验五 linux 线程的使用试验六 linux 进程间的 ipc 试验七 linux 下访问 mysql 数据库试验八 linux 下网络编程 练习题:grep bash生产者消费者试验一 linux 基本命令的使用1、试验目的学习和把握 linux 的基本命令。2、试验内容和步骤步骤 1:以user_login 用户身份并使用 tel net 登
2、录 lin ux 服务器,依据提示创建自己的账 户和口令。步骤 2 :使用新创建的用户账户和口令登录maxlocalhost documentsf pwd/home/max/documentsmaxlocalhost documentsflinux 系统,察看登录后的界面。步骤 3:使用 pwd 命令察看当前的工作名目,然后用 使用-a,-l,-f,-a,-if等不同选项并比较不同之处。is 命令查看当前名目下的内容,尝试-a do no t ig nore en tries start ing withmaxlocalhost documents$ is -a, .* virtualbox
3、dropped files-i, -ig nore=pattern do not list implied en tries matchi ng shell pattern -l use a long listi ng formatmaxlocalhost documentsf is -i total 4drwx -3 max max 4096 apr 27 16:45 virtualbox dropped files-f, -classifyappe nd in dicator (one of */=>|) to en triesmaxlocalhost desktop is - f台
4、包a.c cout* firefoxdgnoaedesktop*-a, -almost-all do not list implied . and .maxlacailhost docjmentsj is -avirtualbox dropped files-lf ignore filemaxglacblhost deskt 叩$ is -if total 24-rw- rw- r-.lmaxmax145may2222:32a. c-rw- rw- r- -1maxmax143may2222:32a. c-*-rwx rwx r 1maxmax6707may2222:32out*x1.rwx
5、rwx rwx.1maxmax39hay1819:07firefox.desktop-> /u5r/share/applications/firefox.desktop-rwxrwxrx.1 maxmax6333apr2722:40eriindl ( iesktop*步骤 4:在当前名目下建立一个名为test 的新名目,然后将工作名目切换到test 下,尝试将/etc 名目下的文件 passwd 拷贝到该名目下(cp 源文件 目的名目)。察看当前名目下的 passwd 文件的属主和文件权限。maxlocalhost desktopinkdir testmaxlocalhost deskt
6、op! maxglocalhostdesktop$ maxglocalhost test$ is total 4 -rw- r- - r- . 1 max maxcp /etc/passwd test cd test/i1847 jun5 21: 32 passwd步骤 5:尝试向当前名目下的 passwd 文件和/etc/passwd 文件分别写入一些新内容echo “字符串” >>文件的命令),看看操作能否成功,假如不能成功,请说明缘由。用(可使用cat命令扫瞄文件 password 的内容,用more 命令进行扫瞄翻页操作,再用 less 命令扫瞄文件的 内容。比较这几个命令
7、的不同之处maxilocalhost test$ echo “asdf“»passwd rnaxloca1.ho5t test! echo “asdfb»/etc/passwd bash: /etc/passwd: permission denied对当前名目中成功,由于该名目下的 passwd 文件对当前用户具有写的权限。文件的操作被拒绝由于对当前用户不具有写的权限对/etc/passwdcat 命令将文件的内容全部显示, 显示more 命令将文件内容分屏显示,less 命令进行刷新的全部步骤 6:用 ls 命令查看 test 下文件的权限,用mv 命令更改文件 pass
8、word 的文件名为test.txt, 尝试用chown 和 chgrp 更改文件的属主为 root、组为 root ,看看能否成功,不成功,请说明缘由。尝试用chomd 将文件权限为“ -rw-说明缘由。”。看看能否成功,不成功,请maxlocalliost maxfilocalhost test- txttest j. mv passwd test, txt test$ istest$ chown root test,txtmaxlocalhost匚 hown: changing ownership of ”test.txt”operation not permittedmaxglocal
9、host test$ chgrp:chgrp root test, txtchanging groupof test.txt1: operation not permitted chmod 6q9 test.txtmaxlocalhost test$maxlocalhost testj is -1 total 41856 jun 5 21:47 test-txt用 chown 和 chgrp 更改文件的属主为是 root 的权限root、组为 root,不成功。由于 chown 和 chgrp 一般步骤 7:用 rm 命令删除 test 名目下的全部文件,再用rmdir 命令删除 test 名
10、目。(想一想有没有一条命令将名目及名目下的全部文件删除,写出这条命令)maxlocalhost maxglocalhost total 0 rmaxlocalhost maxlocalhost imaxlocalhostrm -rf testtest$ cd desktop$ desktop$rmdir test/步骤 8 使用 ps 命令查看当前系统内的进程,并利用取当前终端进程执行状况的ps 命令。hidradt rantraotpid ppidc stime ttyl23g 9 20:36 ?g 0 20:36 ?2 0 20=36 7time cmj00:00:go /shin/ini
11、t g0:0g:go (kthreaddgfl: 00: go migration/elroot132 0 20:36 1qo: 0g:oe sync_supenrnaxlqcalhdst desktop$ ps -efman 命令猎取 ps 命令的参数,写出获raot420 2g:36 ?00:00:60 ksoftirqd/aroot52® 20:36 ?00:00:06 migration/qroot620 20:36 ?co:oolgo watchdog/eroot720 20:36 7eo:o0:g3 evertts/grootb2g 20:36 ?egrouproot92
12、b 20:36 ?khlperroot1020 20;36 ?jnetns)rootil2b 20:36 ?qo;0q;o0 async/mgrroot1220 20:36 ?pmrant142a 20:36 ?gfi:00:go bdi-defaultradt1520 20:36 ?g0:0g:oq kintegrityd/groot1620 2g;36 7g0: dg : 0 l (kbldtkd/qnot1720 20:36 ?co:0g:gq kacpidroot182q 20:36 700:00:06 kacpiratifyroot192d 20:36 ?co:do:oe ka<
13、;pi .hotplugroot2d20 »:36 7so:dg:co ata_auxroot2120 20:36 ?00:0&:11 jatasff/oroot2220 2g:36 ?前;eg:00步骤 9:使用 df 命令查看当前系统已安装的文件系统的空间使用状况,记录结果。filesystemlk-blocksused available use mounted onmaxlocalhost desktops df/dev/inapper/vg_tivedvd- ivroot6926264598332887258088%/tmpf s5101725525g96291%/
14、dev/shm/dev/sdal495s4435182435062/boot步骤 10:使用 du 命令查看用户的工作名目占用了多少空间,记录结果。maxlocalhost desktop$ du 32.步骤 11:使用 free 命令查看内存资源的使用状况,记录结果。maxlocalhostdesktopjt totalfreeusedfreesha redbufferscachedmem:102g348881336138512g&9552432512-/+ buffers/cache:329772690576swap:8355760335576步骤 12:使用 man 猎取 tar
15、 和 gzip 的挂念信息,尝试将 test 名目下的文件打包并压缩, 然后到另外一名目 tmp 下解包,写出这几条命令。maxlo 匚日 desktop tar -zcvf test. tar. gz test test/maxlo 匚 alhost desktop! tar -zxvf test,tar.gz -c /home/max/desktop/tmp/ test/_步骤 13:尝试执行“is - l > tmp ”,看看这条命令的执行会消灭什么结果,解释一下这条命令。创建一个名为 tmp 的文件并将 is -i 输出的内容写入 tmp 中步骤 14: 尝试执行 find /u
16、sr/src -name *.c -print | xargs grep“#include ”,看看这条命令的执行会消灭什么结果,解释一下这条命令。maxlocalhost desktop$ find /usr/src -name “c” -print | xargs grep “include /usr/src/kemels/2.6.32*431. el6, x86_64/scripts/conmakehash.c: #inelude <stdion h> /usr/src/keniel.s/2.6.32 431.x86_64/scripts/cornnakehash.c:#in
17、clude <stdlib.h> /usr/src/kernels/2. 6. 32-431. el6. xb6_64/sc ripts/coninakehash . c : #inelude <sysexits. h>zusr/src/kemels/?.6.32 431.叽 6*x8664/scripts/conmakehah.c:#include <stnng.h> /u5r/src/kerriel5/2u 6. 32-431. el6. x86_64/sc ripts/coninakehash . c : #inelude <ctype. h&g
18、t; /usr/sre/keitels/2 6.32-431. el6. x86_64/sc ripts/conmakehash. c: #inelude <linux/typ es.h>n/usr/src/lkernels/2.6.32-431.el6.x86_64/scripts/umfdef.cude <sys/cdef s. h>/usr/src/ikemels/2- 6,32-431. elfi. x86_64/sc ripts/unifdef , c /usr/src/kernel #include <ctype,h> #include s/2.
19、6.32-431. el6. x86_64/ sc ript s/unifdef , c /u s r/s rc/lkernels/2. 6. 32- <err.431.el6.xs6_64/scripts/umfdef.c/usr/src/lkemels/2-6,32-431.elfi.ude <stda rg.x86_64/scnpts/unifdef.c/usr/sre/kernels/2.6l32-431.616.x86_64/sc #include <stdboo”l.h> ripts/unifdef,c/usr/src/kemels/2.6.32-431.e
20、l6.x86_64/scripts/unifdef,c #include <stdio.h> #込匚 1/usr/src/ikemels/2-6,32-431.el6.x8664/scripts/unifdef,c/usr/s ude <stdlib. h> #includerc/kernels/2.6.32-431.el6.x86_64/sc ripts/unifdef,c<string.h> #include<unistd.h>/usr/src/kernel5/2,6. 32-431. el6, x86 64/scripts/dte/srep
21、os, c : #incldde “dtc . h匹配查找列表输出/usr/src 下以.c 结尾的文件中含有“ #include ”的内容 步骤 15:执行cal 和date命令,说说这两条指令的用途。maxlocalhost desktop$ caljune 2014sumotuwethfr1234568910111213l41516171819202l2223242526272829 30maxlocalhost desktop$ date 5at jun 7 19:31:58 cst 2gl4步骤 16:执行命令 clear 和 logout ,退出系统。(想一想有没有其他的方法,写出
22、这种方法)exit步骤 17:执行命令 shutdown,关闭系统。(想一想有没有更简洁的命令,写出这条命令)init 03、试验结论通过对 linux的常用命令的学习,让我对 linux 的系统有了初步的生疏-这是一个完全基于命令操作的操作系统,这些命令组成了强大的命令系统,供应了完善的功能。这些命令操作将为我以后的 linux 学习打下良好的基础。试验二简洁 shell 程序设计1、试验目的(1) 学习和把握 vi 编辑器的基本使用方法。(2) 学习和把握编写简洁的 shell 程序。2、试验内容和步骤2.1 vi 的使用步骤 1:以root 用户身份登录进入 linux 系统。步骤 2
23、:启动 vi,切换到输入模式,输入一段英文: this ia an exercise!we use vi to edit it.left,dow n, up,right步骤 3:尝试匹配其中的一串字符,写出这命令及执行结果。:/left步骤 4:尝试替换其中的一串字符,写出这命令及执行结果。:3s/left/123/g步骤 5:尝试复制/删除其中的一行或几行文本,写出命令及执行结果。命令模式下,光标移动到那一行按命令模式下,光标移动到那一行按” nyy ”为要复制的行数)再按p 粘贴。” ndd ”为要删除的行数)删除一行或几行。步骤 6:尝试复制/删除其中的一个单词或几个字符,写出命令及执行
24、结果。命令模式下,光标移动到那一行按命令模式下,光标移动到那一行按” nyw ”为要复制的单词数)再按p 粘贴。” ndw ”为要删除的单词数)删除一个或几个字符。步骤 7:尝试使用鼠标复制文本,写出命令及执行结果。直接使用鼠标选中复制,将光标移动到要粘贴的地方用鼠标粘贴即可完成复制文本。步骤 8 尝试存盘退出操作,写出命令。:wq2.2 简洁的shell 程序步骤 1:使用 vi 将程序清单 2-1 的程序输入。步骤 2 :尝试运行该程序,假如不能运行,缘由是什么,怎样修改。没有执行权限chmod +x test步骤 3:执行程序,写出程序的执行结果。fedora( ?lqcalhost a
25、bclltotml 12drwx2 drwxrwxr-x» 2-rwxrwxr-. 1fedorafedora 4096 may20 21:57 bcsakfedoraiedora 4096 may20 21:57 bsdfedor日fedora 1015 may2q 22:15 tesl-rw-rw-r, 1-rwxrwxr-x. 1fedorafedora fedora iedora0 may 20 21:42 testl0 may 20 22:11 n tfedoralocalhost abc$ tuser:fedorahost:localhostdate: list subd
26、irectciry in current airectory:list files in current directory which can run: see who is on thg system:help screen:exit menuyour choice l,2r3fhrq >1bcsak bsdhit the return key to continug.useredorahost:localhostdate:ll tllsteptsubdirectory in current directoryfiles in current ectory which cn run
27、who is on the system screentest xxxxxyour choicehesesxmenuell>2hit the return key ta continuel步骤 4:阅读程序,把握 shell 函数的编写方法,补全函数file_run 。file_run()is -l | awk “-(.x)+/ print $9”步骤 5:修改程序中的函数 uers(),使得显示在线用户时不分行。(提示:可以使用循环, 对每个在线用户分别处理。)uers()、echo “there arewho|wc -1echo “who are“users on li ne“for
28、 i in $(who | awk ”pri nt $1”);do printf “%s “ $idone echouser:fedormhost:lacalhostdate:1l_ist subdirectory in cur rent di rectory2list files in current directory which can run3see who is on the systemhhelp screenqexit menuyour choice 1,2,3,q >3 there are 7 users online who arefedora fedora fedor
29、a fedora fedora fedora fedorahit the return key to continuel3、试验结论linux 系统 shell 编程其本质就是 linux 命令的组合,通过很多简洁命令的组合可以完成很多 功能, 可以开发一些小型程序。试验三 linux 下简洁 c 程序设计与文件操作1、试验目的(3) 学习和把握 gcc 等 linux 的开发调试环境。(4) 学习并把握 linux 的文件操作。(5) 编写并实现试验步骤 6 要求的程序。2、试验内容和步骤步骤 1:使用 vi 将程序清单 3-1 和 3-2 的程序输入,并在当前名目下创建文件“ file.i
30、n ” 和文件“file.out ”,尽可能的使文件“ file.in”大一些。步骤 2 :利用 gcc 分别编译这两个程序,写出编译命令和执行结果,gdb 调试。假如不成功,尝试利用gcc - o iist3 1 iist3 1.c gcc o iist3 2 iist3 2.c 步骤 3:认真观看这两个程序,比较标准 c 的文件操作和 linux 的系统调用 open、read、write 等的使用区分。答:标准c 的文件操作一个是库函数的调用,linux 中系统调用文件操是底层的文件调用,其运行效率略有差距,同时参数也不同,返回的数据类型也不同。步骤 4:依据说明重新修改程序3-2,并使
31、用 time 命令察看程序执行的时间效率上有何区分。seaskerlocalhost 卓面e time ./listreal user sysomo.0q2sqmo.eeesrseaskerglacalhost 桌面$ time /list3_2realuser omo.qols sys步骤 5:输入、编译并运行程序使用方法上的异同3-3 和 3-4,写出执行结果,并比较他们fseek 和lseek 在两者都是对文件的读写指针进行设置但两者的返回类型不同, 返回的是 off_t 型fseek 返回的是 int 型lseek步骤 6:学习并分别使用标准 c 的文件操作函数和 linux 的系统调
32、用创建一个对同学基本信 息进行操作(插入、修改和删除)的 c 程序,同学基本信息以结构体的形式存储在文件 中,struct stunfostruct stunfo char stu_ nu m12;char n ame10;的定义如下:short int sex;/*0 为女生,1 为男生 */char mobile_ph on e12;3、试验结论通过对文件操作的编程,让我把握了文件的创建,打开,读写,以及特定位置的读写关闭 等操作。并且从系统底层调用和标准的异同。c 函数库两个角度对文件的操作比较中,生疏到两者试验四 linux 下进程操作与进程间通信1、试验目的(1) 学
33、习和把握 fork 等系统调用的基本使用方法。(2) 利用 linux 中的管道实现父子进程间的同步。2、试验内容与步骤步骤 1:使用 vi 将程序清单 4-1 的程序输入、编译并运行,学习和把握法。步骤 2 :使用 vi 将程序清单 4-2、4-3 和 4-4 的程序输入、利用fork 的基本调用方gcc 分别编译这三个程序,写出编译命令和编译结果,假如不成功,尝试利用gcc -o iist4_2 iist4_2.c gcc -o father father.c gcc -o child child.cgdb 调试。步骤 3:写出编译这三个程序的makefile,然后利用 make 进行编译
34、,谈谈这么做的好处。可以节省劳动时间,让三个程序同时编译,简化了操作。步骤 4:运行这三个程序,写出运行结果。sea5ker§lacalhq5t 咸面-/list4 2 seaskerlocalhost 桌面 parent is using pipe write,child, child.步骤 5:屏幕上显示出的执行结果是哪一个进程执行的结果? father 和 child步骤 6:父进程中的 printf 有向屏幕输出吗?为什么? 没有,由于父进程的标准输出已经被重定向。步骤 7:利用父子进程间的管道通信方式,改写试验3 步骤 6 要求的程序。3、 试验结论通过该节试验,我更进一步
35、理解了fock 函数 dup 函数 exercl 函数的工作原理,让我了解到了进程并发的概念。学习了如何创建子进程,进程映象替换,以及通过无名管道实现父子进程中的输入输出重定向试验五 linux 线程的使用1、试验目的学习和把握 linux 线程的创建以及同步方法。2、试验内容和步骤步骤 1:输入程序 5-1,编译并运行写出执行结果。thread_fu nction is runnin g.argume nt was 10 wait ing for thread to fini sh.thread join ed,it returned thank you for the cpu time s
36、hare_ in t is now -10步骤 2 :认真研读代码,描述 pthread_create函数的调用方法,描述两线程间参数传递的方式。函数中各个参数的意义,并给出线程的入口该函数有四个参数, 第一个参数为一个指向 pthread_t 类型数据的指针,其次个参数为创建线程的属性,一般用 null 表示用默认属性,第三个参数为指向要调用函数的函数指针,第四 个参数是传给该函数的参数。参数传递方式:首先线程的函数要定义成 void *(*start_rout in e)(void*)的形式,主线程创建子线程时可将要传 给子线程的信息放在 pthead_create 函数的第四个参数上,子
37、线程创建后就可以通过函数的参 数直接获得(为一个 void 类型的指针)。步骤 3:打开注释掉的全局变量aa 及操作aa 的相关代码,回答这跟进程有什么不同。由于线程是共享进程内资源的,所以子线程假如转变了 aa 的值,主线程内 aa 的值也会发生改变,而假如是创建了一个子进程,若子进程转变了的。步骤 4:输入程序 5-2,编译并运行,写出运行结果。in put some text,e nter ”e nd” to finish basjkyou in put 5 characters endwait ing for thread to fini sh. thread joinedaa 的值,
38、主进程内 aa 的值是没有发生转变步骤 5:认真研读代码,描述利用信号量实现线程间同步调用方法。定义一个全局的 sem_t 类型的变量,通过函数 semnit(&bin_sem,0,0)初始化信号量,sem_wait 函数相当于 p 操作,sem_post 函数相当于 v 操作,改程序的实质其实是一个生产者消费者问 题。注:int sem_ in it(sem_t *sem, int pshared, un sig ned int value);the value argument specifies the initial value for the semaphore.if psh
39、ared has the value 0, the n the semaphore is shared betwee n the threads of a process. if pshared is non zero, the n the semaphore is shared betwee n processes.步骤 6:学习并使用线程间的同步方法,重新改写试验3 步骤 6 要求的程序。要求启用两个线程,其中主线程接受用户对文件 的操作命令然后发给子线程, 子线程完成对文件的 实际操作(留意线程间的同步)。3、试验结论通过本节试验学习了如何创建线程,如何在线程之间传递参
40、数已经共享数据,以及如何利 用信号量同步线程。如何在线程之间传递参数已经共享数据,以及如何利用信号量同步线 程。试验六 linux 进程间的 ipc1、试验目的学习和把握 linux 进程间的 ipc 及同步方法。2、试验内容和步骤步骤 1:输入程序 6-1, 6-2 编译并运行写出执行结果。fedoralocalhost 冥验 6$ v6-2 & 1 2749semid = 196669fedoralocalhost 去 5i6$ ./6-2 x semid = 196609 ooooooxxooxxooxxooxxooxxooxxooxxoo2749 - finishedxxxxx
41、x2753 - finished1+ done./6-2fedoralocalhost 试验 6$ |步骤 2 :认真研读代码,写出程序中实现p、v 操作的相关函数和代码,描述程序的同步工作过程。上述代码实现多个进程读写临界区时,使用信号量进行同步的例子,读临界区时先出临界后 v 操作,上面结果中 0 与x 的消灭都是成队的。步骤 3:输入程序 6-3 和 6-4,编译执行并写出结果。p 操作,fedoralocalhost 试验 6$ ,/6-3init over!fedorataiocalhost 试验 6$ ./6-4labcdefahiiklmnodarstuvwxvz步骤 4:程序
42、6-3 和 6-4 中哪段代码实现了共享,描述实现内存共享的主要函数的参数意义 和这些函数的使用方法。int shmget(key_t key, size_t size, i nt shmflg);/ 向系统申请一块共享内存void *shmat(i nt shmid, const void *shmaddr, i nt shmflg); / 将共享内存挂载至 u shmaddr 指针上 int shmdt(co nst void *shmaddr);/ 卸载共享内存int shmctl(i nt shmid, i nt cmd, struct shmid_ds *buf);/ 删除共享内存以
43、及其他把握shmctl(shmid, ipc_rmid, 0);步骤 5:学习并使用 ipc 中信号量和共享内存的使用方法,重新改写试验3 步骤 6 要求的程序。要求启动多个进程,每一个进程都可以单独对文件进行操作,进程间通过信号量进行同步, 对文件的操作映射到共享内存中。3、试验结论通过对改节试验,让我了解了进程ipc 信号量访问临界区,以及进程之间访问共享内存的实现方法和同步机制,把握了上述一系列函数的使用方法。ipc 用于完成进程间通信,包括信号量,共享内存已及消息队列,在编写linux 程序时非有用试验七 linux 下访问 mysql 数据库1、试验目的学习和把握 mysql 数据库
44、及编程访问方法。2、试验内容和步骤步骤 1:在 mysql 中使用 sql 命令create database foo步骤 2 :在数据库 foo 中创建表 children 。create table childre n (命令创建数据库 foo。child no in t(11) not null auto_ in creme nt, fname varchar(30),age in t(11),primary key (child no) );步骤 3:向表 children中插入若干记录。in sert into childre n values (1, insert into chi
45、ldre n values (2, insert into childre n values (3, insert into childre n values (4, insert into childre n values (5, insert into childre n values (6, 步骤 4:输入、编译并运行程序fodo raglocal host 试验 7$ conne 匚 tion successret rieved 6 rows fetched data,.fetched data. fetched dmt 日fetched data. fetched data,., f
46、etched data.f e do ra(al oc al host 试验 7 $connectio 门 success inse rted 1 rows”jenny ” ,17);”an drew” ,13);”alex ” ,12);”tom” ,11);”jack ” ,7);”ella ” ,14);7-1、7-2 和 7-3,写出运行结果。./7-1j7-2 ji-3fedora(aiocalhost 衣验 7$ connection success updatod 1 rows步骤 5:学习并使用 c 语言访问 mysql 的基本方法,重新改写试验用数据库保存
47、结构。3、试验结论通过 mysql.h c 语言可以使用数据库。通过该节试验我把握了3 步骤 6 要求的程序。要求使linux 下怎么用 c 语言进行简单的数据库方面的编程。试验八 linux 下网络编程1、试验目的学习和把握 socket 函数的基本使用方法。2、试验内容和步骤步骤 1:输入、编译并运行程序 8-1 和 8-2,写出程序的执行结果。fedoradiacalhast 头竖町培./8-2 server waiting now,die nt reques t come in. .i?. i client_port client send:bcasjbkasj46171fedora0
48、t.ocal.host 共掘日$ vb-1 enter same message: bcasjbkasj from var = yes! fedoriocalhost 壬 1|server waiting步骤 2 :学习并使用 socket 函数的基本使用方法,完善并重新改写前几个试验实现的程序。 要求用户在客户端实现数据操作恳求的输入,然后上传到服务器端完成对数据库的实际操 作。同学在实现时应尽可能的使用前几个试验的成果, 以及 socket 等。3、试验结论即应当包括多线程或多进程、数据库通过改节试验我把握了 linux 下用 c 语言进行网络编程。socket 可以实现不同主机间进程的通
49、信,可以编写出网络应用程序课堂练习:l.grep:#i nclude <stdio.h> #in clude <stri ng.h> int main (i nt argc,char* argv) file *fp;char tmp100,c; char* tmp1;int l = 0,li ne = 1; if(argc<3) prin tf(“i nput wron g!n“); return 0;if(!(fp=fope n(argv2,“r“)prin tf(“ca n”t ope n file!n“); return 0;fsca nf(fp,“%c“,
50、&c);new_line:while(c!=”n”&&!feof(fp)tmpl=c;l+;fscan f(fp,“%c“,&c);tmpl=0; tmp1 = tmp; while(l!=0)if(!str ncmp(argv1,tmp1,sizeof(argv1)printf(“line %d: %sn“,line,tmp);l-;tmp1+=sizeof(char);fsca nf(fp,“%c“,&c); lin e+;if(!feof(fp)goto new_line; return 1;运行结果:fedoralo 匚 alhost 2014-
51、3-22$ /mygrep dup2 dupc line 17:dup2(fd,1);2. bash: #in elude <uni std.h> #i nclude <stdio.h>#in elude <stri ng.h> #i nclude <stdlib.h>#in elude <sys/types.h>void mai n()pid_t pid;char arg1oo; char *parg,*p; int len th,i,j;prin tf(“mysh#“);while(1)j=0;fgets(arg,sizeof(arg),stdin);/fgets 比 gets 多接收一个 lf(换行)即n/gets(arg); if(!strcmp(arg,“exit n“)return; pid = fork(); if(pid=0)len th=strle n( arg); len th-;argle nth=o;/pri ntf(“%sn“,a
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年综合接入服务系统项目可行性研究报告
- 2025年电脑雕刻圣诞灯饰项目可行性研究报告
- 2025至2031年中国牛角扣羊羔绒马甲行业投资前景及策略咨询研究报告
- 2025年果蔬宝农药项目可行性研究报告
- 2025至2031年中国异型结构件行业投资前景及策略咨询研究报告
- 2025年工艺温度计项目可行性研究报告
- 延安2024年陕西延安市市直事业单位选聘70人笔试历年参考题库附带答案详解
- 2025至2031年中国一体式顶置空调器行业投资前景及策略咨询研究报告
- 2025至2030年中国黑豆粉数据监测研究报告
- 2025至2030年高效板式密闭过滤机项目投资价值分析报告
- 水土保持方案中沉沙池的布设技术
- 安全生产技术规范 第25部分:城镇天然气经营企业DB50-T 867.25-2021
- 现代企业管理 (全套完整课件)
- 走进本土项目化设计-读《PBL项目化学习设计》有感
- 《网店运营与管理》整本书电子教案全套教学教案
- 教师信息技术能力提升培训课件希沃的课件
- 高端公寓住宅项目营销策划方案(项目定位 发展建议)
- 执业兽医师聘用协议(合同)书
- 第1本书出体旅程journeys out of the body精教版2003版
- [英语考试]同等学力英语新大纲全部词汇
- 2022年肝动脉化疗栓塞术(TACE)
评论
0/150
提交评论