avatar
how to fork a subroutine in unix?# Unix - 噫吁兮,危乎高哉
z*h
1
hi, guys,
I just wonder how I could fork a subroutine in unix other than the whole
copy of current process. any idea? thanks.
avatar
L*e
2
just use fork() API. And you need to include "unistd.h"

【在 z*h 的大作中提到】
: hi, guys,
: I just wonder how I could fork a subroutine in unix other than the whole
: copy of current process. any idea? thanks.

avatar
j*y
3
I think in the current systems, all the fork functions will work as vforks.
it means that the system won't copy the whole context until it's necessary.

【在 z*h 的大作中提到】
: hi, guys,
: I just wonder how I could fork a subroutine in unix other than the whole
: copy of current process. any idea? thanks.

avatar
L*e
4
fork is different from vfork as after vfork the child process shares the
same address space as the calling process. Because of the shared address,
you must be careful to use vfork.

【在 j***y 的大作中提到】
: I think in the current systems, all the fork functions will work as vforks.
: it means that the system won't copy the whole context until it's necessary.

avatar
m*e
5
You are definitely wrong.

【在 L********e 的大作中提到】
: fork is different from vfork as after vfork the child process shares the
: same address space as the calling process. Because of the shared address,
: you must be careful to use vfork.

avatar
j*y
6
You are right that vfork does have some differences with fork. But I think
the difference between vork and the modern fork is that with vfork, you
yourself have to do a copy-on-write synchronization. But with fork, the system
will do it automatically.
In vfork, it does share address space with parent, but more exactly, it
borrows address space from parent. Because the parent will suspend as vfork
is called. But this is not consistant in all platforms, in some platforms,
after vfork, the parent w

【在 L********e 的大作中提到】
: fork is different from vfork as after vfork the child process shares the
: same address space as the calling process. Because of the shared address,
: you must be careful to use vfork.

avatar
L*e
7
oh? where?
I hardly use vfork and i have no refernce book with
me right now.

【在 m*****e 的大作中提到】
: You are definitely wrong.
avatar
L*e
8
//nod nod
you are right. In some platforms, the parent will be suspended after vfork.
why not just use fork to avoid any possible problems neh.

【在 j***y 的大作中提到】
: You are right that vfork does have some differences with fork. But I think
: the difference between vork and the modern fork is that with vfork, you
: yourself have to do a copy-on-write synchronization. But with fork, the system
: will do it automatically.
: In vfork, it does share address space with parent, but more exactly, it
: borrows address space from parent. Because the parent will suspend as vfork
: is called. But this is not consistant in all platforms, in some platforms,
: after vfork, the parent w

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。