JavaEar 专注于收集分享传播有价值的技术资料

vfork()../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory

I've got a problem when i try to using vfork(). Here's the code!

#include <stdio.h>
#include <unistd.h>

    if(vfork() == 0)
        printf("This is the child process\n");
    } else{
        printf("This is the parent process\n");

and debug with gdb error infomation:

(gdb) r
Starting program: /home/shawn/Documents/gcc/demo/./a.out 
This is the child process
This is the parent process
a.out: cxa_atexit.c:99: __new_exitfn: Assertion `l != ((void *)0)' failed.

Program received signal SIGABRT, Aborted.
0x00007ffff7a48f77 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
56  ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.

Can anybody help?

I am using:

  • ubuntu 13.10 64bit OS
  • gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu8)


  1. The "no such file" message is because you don't have the source for the C library available. I wouldn't worry about it; you rarely need to look at that.

    The crash is because you're misusing vfork. The only valid things you can do in the child process are to call execve or similar, to replace the process with another program, or call _exit (not exit) to exit. You get undefined behaviour if the child tries to modify any data, return from the function that called vfork, or call another function.

    If you want the child to be a clone of the parent and able to continue running the same program, use fork not vfork.

  2. 参考答案2
  3. Man page for vfork(), says you should never return from the function in the child, or call exit() - call either _exit() or one of the exec() functions.

    vfork() differs from fork(2) in that the calling thread is suspended until the child terminates (either normally, by calling _exit(2), or abnormally, after delivery of a fatal signal), or it makes a call to execve(2). Until that point, the child shares all memory with its parent, including the stack. The child must not return from the current function or call exit(3), but may call _exit(2).

    The error comes after returning from the first printf call.