免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2313 | 回复: 2
打印 上一主题 下一主题

Proc::Fork产生的父子进程ID怎么没变化 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-11-01 14:57 |只看该作者 |倒序浏览
我的Proc::Fork版本:0.61
  1. #!/usr/bin/perl -w

  2. use Proc::Fork;

  3. child {
  4.         print "this is child\n";
  5.         print "child id ".getppid()."\n";
  6. }
  7. parent {
  8.         my $child_pid = shift;
  9.         print "this is parent\n";
  10.         print "parent id ".getppid()."\n";
  11.         waitpid $child_pid, 0;
  12. }
复制代码
多次运行,总是一样的结果:
  1. $ perl procfork.pl
  2. this is parent
  3. parent id 11734
  4. this is child
  5. child id 12777
复制代码
我的问题是,为什么多次运行了,进程ID都没变化?

论坛徽章:
46
15-16赛季CBA联赛之四川
日期:2018-03-27 11:59:132015年亚洲杯之沙特阿拉伯
日期:2015-04-11 17:31:45天蝎座
日期:2015-03-25 16:56:49双鱼座
日期:2015-03-25 16:56:30摩羯座
日期:2015-03-25 16:56:09巳蛇
日期:2015-03-25 16:55:30卯兔
日期:2015-03-25 16:54:29子鼠
日期:2015-03-25 16:53:59申猴
日期:2015-03-25 16:53:29寅虎
日期:2015-03-25 16:52:29羊年新春福章
日期:2015-03-25 16:51:212015亚冠之布里斯班狮吼
日期:2015-07-13 10:44:56
2 [报告]
发表于 2010-11-01 16:20 |只看该作者
是不是该用 $$ ?

论坛徽章:
0
3 [报告]
发表于 2010-11-01 16:46 |只看该作者
刚说自己解决了,就被高人占了沙发。
查了一下perl文档:
http://perldoc.perl.org/functions/getppid.html
getppid

Returns the process id of the parent process.

Note for Linux users: on Linux, the C functions getpid() and getppid() return different values from different threads. In order to be portable, this behavior is not reflected by the Perl-level function getppid(), that returns a consistent value across threads.

果然的,用$$就好了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP