no error thrown with exit(0) in the child process of vfork()

Niroj Pokhrel nirojpokhrel at gmail.com
Fri Jan 18 09:29:38 EST 2013


Hi all,
I have been trying to create a process using vfork(). And both of the child
and the parent process execute it in the same address space. So, if I
execute exit(0) in the child process, it should throw some error right.
Since the execution is happening in child process first and if I release
all the resources by using exit(0) in the child process then parent should
be deprived of the resources and should throw some errors right ??
In the following code, however the process ran fine even though I have
exit(0) in the child process ........
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<unistd.h>
int main()
{
    int val,i=0;
    val=vfork();
    if(val==0)
    {
        printf("\nI am a child process.\n");
        printf(" %d ",i++);
        exit(0);
    }
    else
    {
        printf("\nI am a parent process.\n");
        printf(" %d ",i);
    }
    return 0;
}
// The program is running fine .....
But as I have read it should throw some error right ?? I don't know what I
am missing . Please point out the point I'm missing. Thanking you in
advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130118/933e5347/attachment.html 


More information about the Kernelnewbies mailing list