ImageVerifierCode 换一换
格式:DOCX , 页数:11 ,大小:182.40KB ,
资源ID:28079308      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/28079308.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Linux多进程程序设计.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Linux多进程程序设计.docx

1、Linux多进程程序设计实验报告实验名称:Linux 多进程程序设计一、 实验目的熟悉Linux下多进程编程的方法,掌握Linux下fork、exec、wait、waitpid等进程相关的系统调用使用方法。二、 实验内容在父进程中创建两个子进程,其中一个子进程运行“ls -l”指令,另一个子进程在暂停5s之后退出。父进程先用阻塞方式等待第一个子进程的结束,然后用非阻塞方式等待第二个子进程的退出,待收集到第二个子进程结束的信息,父进程就返回。三、 实验内容1、 程序说明、流程图等父进程首先创建一个子进程A,采用组赛模式等待进程A结束,然后创建进程B,采用非阻塞模式等待B 进程结束,然后父进程结束

2、 A进程运行 ps -ef B进程等待5S 自动结束 父进程会铺货进程A,B的结束,然后给予相应的提示。2、 程序代码#include #include #include #include #include int main(void ) pid_t pa,pb,pr; pa=fork(); if(pa0) perror(fork a error!); else if(pa=0) sleep(1); printf(process A is running.n); if(execlp(ps,ps,-ef,NULL)0) perror(execlp a error!); exit(0); else

3、 printf(this is parent process!n); printf(parent process is wating for children !n); printf(wating .wating.n); pr=wait(NULL); if(pr=pa) printf(parent catched the child A!n); printf(creat process B!n); pb=fork(); if(pb0) printf(error fork Bn); else if(pb=0) printf(B process is running( 5 S )!n); slee

4、p(5); printf(B process end!n); exit(0); else do pr=waitpid(pb,NULL,WNOHANG); if(pr=0)/*B not end*/ printf(father is wating for child B!n); sleep(1); while(pr=0);/*wait for process B*/ if(pr=pb) printf(child B very well!n); else printf(my child B lost!); 3、 运行测试输出的结果this is parent process!parent proc

5、ess is wating for children !wating .wating.process A is running.UID PID PPID C STIME TTY TIME CMDroot 1 0 0 02:57 ? 00:00:01 /sbin/initroot 2 0 0 02:57 ? 00:00:00 kthreaddroot 3 2 0 02:57 ? 00:00:00 ksoftirqd/0root 5 2 0 02:57 ? 00:00:00 kworker/u:0root 6 2 0 02:57 ? 00:00:00 migration/0root 7 2 0 0

6、2:57 ? 00:00:00 cpusetroot 8 2 0 02:57 ? 00:00:00 khelperroot 9 2 0 02:57 ? 00:00:00 netnsroot 10 2 0 02:57 ? 00:00:00 sync_supersroot 11 2 0 02:57 ? 00:00:00 bdi-defaultroot 12 2 0 02:57 ? 00:00:00 kintegritydroot 13 2 0 02:57 ? 00:00:00 kblockdroot 14 2 0 02:57 ? 00:00:00 kacpidroot 15 2 0 02:57 ?

7、 00:00:00 kacpi_notifyroot 16 2 0 02:57 ? 00:00:00 kacpi_hotplugroot 17 2 0 02:57 ? 00:00:00 ata_sffroot 18 2 0 02:57 ? 00:00:00 khubdroot 19 2 0 02:57 ? 00:00:00 mdroot 22 2 0 02:57 ? 00:00:00 khungtaskdroot 23 2 0 02:57 ? 00:00:00 kswapd0root 24 2 0 02:57 ? 00:00:00 ksmdroot 25 2 0 02:57 ? 00:00:0

8、0 fsnotify_markroot 26 2 0 02:57 ? 00:00:00 aioroot 27 2 0 02:57 ? 00:00:00 ecryptfs-kthrearoot 28 2 0 02:57 ? 00:00:00 cryptoroot 32 2 0 02:57 ? 00:00:00 kthrotldroot 34 2 0 02:57 ? 00:00:00 scsi_eh_0root 35 2 0 02:57 ? 00:00:01 scsi_eh_1root 36 2 0 02:57 ? 00:00:00 kworker/u:3root 39 2 0 02:57 ? 0

9、0:00:00 kmpathdroot 40 2 0 02:57 ? 00:00:00 kmpath_handlerdroot 41 2 0 02:57 ? 00:00:00 kondemandroot 42 2 0 02:57 ? 00:00:00 kconservativeroot 160 2 0 02:57 ? 00:00:00 scsi_eh_2root 176 2 0 02:57 ? 00:00:00 jbd2/sda1-8root 177 2 0 02:57 ? 00:00:00 ext4-dio-unwritroot 224 1 0 02:57 ? 00:00:00 upstar

10、t-udev-bridge -daemonroot 235 1 0 02:57 ? 00:00:00 udevd -daemonsyslog 329 1 0 02:57 ? 00:00:00 rsyslogd -c4102 334 1 0 02:57 ? 00:00:00 dbus-daemon -system -fork -avahi 361 1 0 02:57 ? 00:00:00 avahi-daemon: running hao-Viravahi 362 361 0 02:57 ? 00:00:00 avahi-daemon: chroot helperroot 375 1 0 02:

11、57 ? 00:00:00 NetworkManagerroot 383 1 0 02:57 ? 00:00:00 /usr/sbin/modem-managerroot 392 1 0 02:57 ? 00:00:00 /usr/lib/policykit-1/polkitdroot 437 1 0 02:57 ? 00:00:00 /sbin/wpa_supplicant -u -sroot 445 2 0 02:57 ? 00:00:00 kpsmousedroot 506 2 0 02:57 ? 00:00:00 iprtroot 526 1 0 02:57 ? 00:00:00 up

12、start-socket-bridge -daemonroot 606 1 0 02:57 tty4 00:00:00 /sbin/getty -8 38400 tty4root 614 1 0 02:57 tty5 00:00:00 /sbin/getty -8 38400 tty5root 626 1 0 02:57 tty2 00:00:00 /sbin/getty -8 38400 tty2root 633 1 0 02:57 tty3 00:00:00 /sbin/getty -8 38400 tty3root 636 1 0 02:57 tty6 00:00:00 /sbin/ge

13、tty -8 38400 tty6daemon 643 1 0 02:57 ? 00:00:00 atdroot 644 1 0 02:57 ? 00:00:00 acpid -c /etc/acpi/events -s /root 645 1 0 02:57 ? 00:00:00 cronroot 664 2 0 02:57 ? 00:00:00 flush-8:0root 746 1 0 02:57 ? 00:00:02 /usr/sbin/VBoxServiceroot 905 1 0 02:57 ? 00:00:00 gdm-binaryroot 908 1 0 02:57 ? 00:

14、00:00 /usr/sbin/cupsd -Froot 910 1 0 02:57 tty1 00:00:00 /sbin/getty -8 38400 tty1root 914 1 0 02:57 ? 00:00:00 /usr/sbin/console-kit-daemon -root 980 905 0 02:57 ? 00:00:00 /usr/lib/gdm/gdm-simple-slaveroot 985 980 2 02:57 tty7 00:01:28 /usr/bin/X :0 -nr -verbose -auroot 1000 980 0 02:57 ? 00:00:00

15、 /usr/lib/gdm/gdm-session-workehao 1009 1000 0 02:57 ? 00:00:00 gnome-session -session=ubuntuhao 1052 1 0 02:57 ? 00:00:00 /usr/bin/VBoxClient -clipboarhao 1064 1 0 02:57 ? 00:00:00 /usr/bin/VBoxClient -displayhao 1070 1 0 02:57 ? 00:00:00 /usr/bin/VBoxClient -seamlesshao 1076 1 0 02:57 ? 00:00:30 /

16、usr/bin/VBoxClient -draganddhao 1079 1009 0 02:57 ? 00:00:00 /usr/bin/ssh-agent /usr/bin/dbhao 1082 1 0 02:57 ? 00:00:00 /usr/bin/dbus-launch -exit-wihao 1083 1 0 02:57 ? 00:00:01 /bin/dbus-daemon -fork -prihao 1088 1 0 02:57 ? 00:00:00 /usr/lib/libgconf2-4/gconfd-2hao 1101 1 0 02:57 ? 00:00:00 /usr

17、/bin/gnome-keyring-daemonhao 1106 1 0 02:57 ? 00:00:04 /usr/lib/gnome-settings-daemonhao 1109 1 0 02:57 ? 00:00:00 /usr/lib/gvfs/gvfsdhao 1114 1009 0 02:57 ? 00:00:05 metacityhao 1116 1 0 02:57 ? 00:00:00 /usr/lib/gvfs/gvfs-fuse-daemohao 1120 1 0 02:57 ? 00:00:04 /usr/bin/pulseaudio -start -rtkit 11

18、22 1 0 02:57 ? 00:00:00 /usr/lib/rtkit/rtkit-daemonhao 1127 1009 0 02:57 ? 00:00:10 nautilushao 1128 1009 0 02:57 ? 00:00:00 /usr/lib/evolution/2.32/evoluthao 1131 1009 0 02:57 ? 00:00:04 gnome-panelhao 1135 1009 0 02:57 ? 00:00:00 zeitgeist-datahubhao 1137 1120 0 02:57 ? 00:00:00 /usr/lib/pulseaudi

19、o/pulse/gconhao 1138 1009 0 02:57 ? 00:00:00 nm-applet -sm-disablehao 1140 1009 0 02:57 ? 00:00:00 gnome-power-managerhao 1142 1009 0 02:57 ? 00:00:00 /usr/lib/policykit-1-gnome/polhao 1143 1009 0 02:57 ? 00:00:00 bluetooth-applethao 1152 1 0 02:57 ? 00:00:00 /usr/lib/gvfs/gvfs-gdu-volume-root 1156

20、1 0 02:57 ? 00:00:00 /usr/lib/udisks/udisks-daemonroot 1158 1156 0 02:57 ? 00:00:01 udisks-daemon: polling /dev/srhao 1160 1 0 02:57 ? 00:00:01 /usr/bin/python /usr/bin/zeitghao 1163 1 0 02:57 ? 00:00:00 /usr/lib/gvfs/gvfs-afc-volume-hao 1167 1 0 02:57 ? 00:00:00 /usr/lib/gvfs/gvfs-gphoto2-volhao 11

21、71 1160 0 02:57 ? 00:00:00 /bin/cathao 1176 1160 0 02:57 ? 00:00:00 zeitgeist-datah root 1195 1 0 02:57 ? 00:00:00 /usr/lib/upower/upowerdhao 1263 1 0 02:57 ? 00:00:00 /usr/lib/gvfs/gvfsd-trash -sphao 1265 1 0 02:57 ? 00:00:00 gnome-screensaverhao 1272 1 0 02:57 ? 00:00:02 /usr/lib/notify-osd/notify

22、-osdhao 1290 1 0 02:57 ? 00:00:00 /usr/lib/bonobo-activation/bonhao 1303 1 0 02:57 ? 00:00:03 /usr/lib/gnome-panel/wnck-applhao 1305 1 0 02:57 ? 00:00:00 /usr/lib/gnome-applets/trashaphao 1311 1 0 02:57 ? 00:00:00 /usr/lib/gnome-panel/notificathao 1312 1 0 02:57 ? 00:00:01 /usr/lib/indicator-applet/

23、indihao 1327 1009 0 02:57 ? 00:00:00 /usr/lib/gnome-disk-utility/gdhao 1330 1 0 02:57 ? 00:00:00 /usr/lib/gvfs/gvfsd-burn -spahao 1339 1 0 02:57 ? 00:00:00 /usr/lib/gvfs/gvfsd-metadatahao 1343 1 0 02:57 ? 00:00:00 /usr/lib/d-conf/dconf-servicehao 1347 1 0 02:57 ? 00:00:00 /usr/lib/indicator-messages

24、/inhao 1349 1 0 02:57 ? 00:00:00 /usr/lib/indicator-sound/indichao 1351 1 0 02:57 ? 00:00:00 /usr/lib/indicator-applicationhao 1353 1 0 02:57 ? 00:00:00 /usr/lib/indicator-session/indhao 1356 1 0 02:57 ? 00:00:00 /usr/lib/indicator-datetime/inhao 1357 1 0 02:57 ? 00:00:00 /usr/lib/indicator-me/indic

25、atohao 1397 1 0 02:57 ? 00:00:00 /usr/lib/geoclue/geoclue-mastehao 1399 1009 0 02:57 ? 00:00:00 /usr/bin/python /usr/share/syshao 1404 1 0 02:58 ? 00:00:02 /usr/lib/bamf/bamfdaemonhao 1409 1009 0 02:58 ? 00:00:00 update-notifierroot 1864 2 0 03:32 ? 00:00:00 kworker/0:0root 1871 2 0 03:37 ? 00:00:00

26、 kworker/0:1root 1918 2 0 03:42 ? 00:00:00 kworker/0:2root 1954 235 0 03:45 ? 00:00:00 udevd -daemonroot 1955 235 0 03:45 ? 00:00:00 udevd -daemonroot 1983 2 0 03:45 ? 00:00:00 kworker/0:3hao 2010 1 1 03:46 ? 00:00:03 gedit /home/hao/Desktop/test.chao 2015 1 1 03:47 ? 00:00:01 gnome-terminalhao 2019

27、 2015 0 03:47 ? 00:00:00 gnome-pty-helperhao 2020 2015 0 03:47 pts/0 00:00:00 bashhao 2085 2020 0 03:49 pts/0 00:00:00 ./testhao 2086 2085 3 03:49 pts/0 00:00:00 ps -efparent catched the child A!creat process B!father is wating for child B!B process is running( 5 S )!father is wating for child B!father is wating for child B!father is wating for child B!father is wating for child B!B process end!child B very well!haohao-VirtualBox:/Desktop$

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1