Help - can anyone explain this segfault?

Help - can anyone explain this segfault?

Ehud Karni ehud at unix.mvs.co.il
Sun Jun 21 13:04:37 IDT 2009


On Fri, 19 Jun 2009 19:10:33 Shachar Shemesh wrote:
>
> Dotan Shavit wrote:
> >
> > From man vfork:
> >
> > behavior is undefined if the process created by vfork() returns from the
> > function in which vfork() was called...
> >
> Well done, you nailed it.
>
> Placing an explicit call to exit for the child process solves the segfault.

I hope you used _exit() and NOT exit(). The man page on my system for vfork
says (read carefully, at least 3 catch you):

    vfork() differs from fork() in that the parent is suspended until the
    child makes a call to execve(2) or _exit(2). The child shares all memory
    with its parent, including the stack, until execve() is issued by the
    child. The child must not return from the current function or call
    exit(), but may call _exit().

Also note that vfork on GNU/Linux stops the parent until it exit by either
calling _exit() or executing execve(). Normally (in older systems) it was
used solely to execute another program.

BTW. On linux, If you do execute a program right away, vfork is not really
better than fork. On older systems (e.g. DG/UX) fork copied the whole
memory before continuing, and vfork changed the shared (read: parent)
memory. On linux fork use "copy on write" so it does not copy (almost)
any memory before doing its work.


Ehud.


--
 Ehud Karni           Tel: +972-3-7966-561  /"\
 Mivtach - Simon      Fax: +972-3-7976-561  \ /  ASCII Ribbon Campaign
 Insurance agencies   (USA) voice mail and   X   Against   HTML   Mail
 http://www.mvs.co.il  FAX:  1-815-5509341  / \
 GnuPG: 98EA398D <http://www.keyserver.net/>    Better Safe Than Sorry



More information about the Linux-il mailing list