免费注册 查看新帖 |

Chinaunix

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

fork是否会阻塞吗? [复制链接]

pcanywhere 该用户已被删除
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-09-19 16:05 |只看该作者 |倒序浏览
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
2 [报告]
发表于 2006-09-19 16:06 |只看该作者
fork 应该会阻塞吧。
不过应该阻塞时间不会太长,否则系统性能可想而知。
pcanywhere 该用户已被删除
3 [报告]
发表于 2006-09-19 16:09 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
pcanywhere 该用户已被删除
4 [报告]
发表于 2006-09-19 16:13 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
pcanywhere 该用户已被删除
5 [报告]
发表于 2006-09-19 16:18 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
6 [报告]
发表于 2006-09-19 17:23 |只看该作者
FreeBSD6.1 fork.S Alpha
  1. #include <machine/asm.h>
  2. __FBSDID("$FreeBSD: src/lib/libc/alpha/sys/fork.S,v 1.5 2003/08/16 18:59:08 marcel Exp $");

  3. #include "SYS.h"

  4. SYSCALL(fork)
  5.         cmovne        a4, zero, v0                /* a4 (rv[1]) != 0, child */
  6.         RET
  7. END(__sys_fork)
复制代码


FreeBSD6.1 fork.S IA64

  1. #include <machine/asm.h>
  2. __FBSDID("$FreeBSD: src/lib/libc/ia64/sys/fork.S,v 1.6 2003/08/01 22:17:12 marcel Exp $");

  3. #include "SYS.h"

  4. SYSCALL(fork)
  5.         cmp.ne        p7,p0=ret1,r0                /* ret1!=0 for child */
  6.         ;;
  7. (p7)        mov        ret0=r0
  8.         br.ret.sptk.few rp
  9. END(__sys_fork)
复制代码

论坛徽章:
0
7 [报告]
发表于 2006-09-19 17:29 |只看该作者
vfork.S Solaris i386

  1. /*
  2. * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  3. * Use is subject to license terms.
  4. */

  5. #pragma ident        "@(#)vfork.s        1.21        05/06/08 SMI"

  6.         .file        "vfork.s"

  7. #include <sys/asm_linkage.h>

  8.         ANSI_PRAGMA_WEAK(vfork,function)

  9. #include "SYS.h"
  10. #include <assym.h>

  11. / The child of vfork() will execute in the parent's address space,
  12. / thereby changing the stack before the parent runs again.
  13. / Therefore we have to be careful how we return from vfork().
  14. / Pity the poor debugger developer who has to deal with this kludge.
  15. /
  16. / We block all blockable signals while performing the vfork() system call
  17. / trap.  This enables us to set curthread->ul_vfork safely, so that we
  18. / don't end up in a signal handler with curthread->ul_vfork set wrong.

  19.         ENTRY(vfork)
  20.         movl        0(%esp),%ecx                / save %eip in %ecx
  21.         _prologue_
  22.         leal        _sref_(0f),%eax                / arrange for RET to return here
  23.         _epilogue_
  24.         movl        %eax,0(%esp)
  25.         ret

  26. 0:
  27.         pushl        $MASKSET1                / block signals
  28.         pushl        $MASKSET0
  29.         pushl        $SIG_SETMASK
  30.         pushl        %ecx
  31.         __SYSCALLINT(lwp_sigmask)
  32.         addl        $16, %esp

  33.         __SYSCALLINT(vfork)
  34.         jae         2f

  35.         / reconstruct stack before jumping to __cerror
  36.         call        1f
  37. 1:        movl        %ecx,0(%esp)
  38.         pushl        %eax                / save the vfork() error number

  39.         pushl        %gs:UL_SIGMASK+4        / reinstate signals
  40.         pushl        %gs:UL_SIGMASK
  41.         pushl        $SIG_SETMASK
  42.         pushl        %ecx
  43.         __SYSCALLINT(lwp_sigmask)
  44.         addl        $16, %esp

  45.         popl        %eax                / restore the vfork() error number
  46.         jmp        __cerror

  47. 2:
  48.         / To determine if we are (still) a child of vfork(), the child
  49.         / increments curthread->ul_vfork by one and the parent decrements
  50.         / it by one.  If the result is zero, then we are not a child of
  51.         / vfork(), else we are.  We do this to deal with the case of
  52.         / a vfork() child calling vfork().
  53.         /
  54.         / %edx is zero if we are the parent, non-zero if we are the child.
  55.         /
  56.         cmpl        $0,%edx
  57.         jne        3f
  58.         movl        %gs:UL_VFORK, %edx
  59.         cmpl        $0, %edx        / don't let it go negative
  60.         je        4f
  61.         subl        $1, %edx        / curthread->ul_vfork--;
  62.         jmp        4f
  63. 3:
  64.         movl        $0,%eax                / zero the return value in the child
  65.         movl        %gs:UL_VFORK, %edx
  66.         addl        $1, %edx        / curthread->ul_vfork++;
  67. 4:
  68.         movl        %edx, %gs:UL_VFORK
  69.         /
  70.         / Clear the schedctl interface in both parent and child.
  71.         / (The child might have modified the parent.)
  72.         /
  73.         xorl        %edx, %edx
  74.         movl        %edx, %gs:UL_SCHEDCTL
  75.         movl        %edx, %gs:UL_SCHEDCTL_CALLED
  76.         pushl        %eax                / save the vfork() return value

  77.         pushl        %gs:UL_SIGMASK+4        / reinstate signals
  78.         pushl        %gs:UL_SIGMASK
  79.         pushl        $SIG_SETMASK
  80.         pushl        %ecx
  81.         __SYSCALLINT(lwp_sigmask)
  82.         addl        $16, %esp

  83.         popl        %eax                / restore the vfork() return value
  84.         jmp        *%ecx                / jump back to the caller
  85.         SET_SIZE(vfork)
复制代码

论坛徽章:
0
8 [报告]
发表于 2006-09-19 17:29 |只看该作者
vfork.S  Solaris Sparc

  1. /*
  2. * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
  3. * Use is subject to license terms.
  4. */

  5. .ident        "@(#)vfork.s        1.13        05/06/08 SMI"

  6. /*
  7. * C library -- vfork
  8. * pid_t vfork(void);
  9. */

  10. /*
  11. * From the syscall:
  12. * %o1 == 0 in parent process, %o1 == 1 in child process.
  13. * %o0 == pid of child in parent, %o0 == pid of parent in child.
  14. *
  15. * The child process gets a zero return value from vfork; the parent
  16. * gets the pid of the child.
  17. *
  18. * We block all blockable signals while performing the vfork() system call
  19. * trap.  This enables us to set curthread->ul_vfork safely, so that we
  20. * don't end up in a signal handler with curthread->ul_vfork set wrong.
  21. *
  22. * Note that since the SPARC architecture maintains stack maintence
  23. * information (return pc, sp, fp) in the register windows, both parent
  24. * and child can execute in a common address space without conflict.
  25. */

  26.         .file        "vfork.s"

  27. #include <sys/asm_linkage.h>

  28.         ANSI_PRAGMA_WEAK(vfork,function)

  29. #include "SYS.h"
  30. #include <../assym.h>

  31.         ENTRY(vfork)
  32.         mov        SIG_SETMASK, %o0        ! block signals
  33.         set        MASKSET0, %o1
  34.         set        MASKSET1, %o2
  35.         SYSTRAP_2RVALS(lwp_sigmask)

  36.         SYSTRAP_2RVALS(vfork)
  37.         bcc,a,pt %icc, 1f
  38.         tst        %o1
  39.         mov        %o0, %o3        ! save the vfork() error number

  40.         mov        SIG_SETMASK, %o0        ! reinstate signals
  41.         ld        [%g7 + UL_SIGMASK], %o1
  42.         ld        [%g7 + UL_SIGMASK + 4], %o2
  43.         SYSTRAP_2RVALS(lwp_sigmask)

  44.         mov        %o3, %o0        ! restore the vfork() error number
  45.         ba,a        __cerror
  46. 1:
  47.         /*
  48.          * To determine if we are (still) a child of vfork(), the child
  49.          * increments curthread->ul_vfork by one and the parent decrements
  50.          * it by one.  If the result is zero, then we are not a child of
  51.          * vfork(), else we are.  We do this to deal with the case of
  52.          * a vfork() child calling vfork().
  53.          */
  54.         bnz,pt        %icc, 2f
  55.         ld        [%g7 + UL_VFORK], %g1
  56.         brnz,a,pt %g1, 3f        ! don't let it go negative
  57.         sub        %g1, 1, %g1        ! curthread->ul_vfork--;
  58.         ba,a        3f
  59. 2:
  60.         clr        %o0                ! child, return (0)
  61.         add        %g1, 1, %g1        ! curthread->ul_vfork++;
  62. 3:
  63.         st        %g1, [%g7 + UL_VFORK]
  64.         /*
  65.          * Clear the schedctl interface in both parent and child.
  66.          * (The child might have modified the parent.)
  67.          */
  68.         stn        %g0, [%g7 + UL_SCHEDCTL]
  69.         stn        %g0, [%g7 + UL_SCHEDCTL_CALLED]
  70.         mov        %o0, %o3        ! save the vfork() return value

  71.         mov        SIG_SETMASK, %o0        ! reinstate signals
  72.         ld        [%g7 + UL_SIGMASK], %o1
  73.         ld        [%g7 + UL_SIGMASK + 4], %o2
  74.         SYSTRAP_2RVALS(lwp_sigmask)

  75.         retl
  76.         mov        %o3, %o0        ! restore the vfork() return value
  77.         SET_SIZE(vfork)
复制代码
pcanywhere 该用户已被删除
9 [报告]
发表于 2006-09-19 17:36 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
pcanywhere 该用户已被删除
10 [报告]
发表于 2006-09-20 11:38 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP