top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What happens to parent process, when a child process is created using vfork() and killed before calling exec

+4 votes
630 views

When a process is created using vfork() child process is created and starts running in the parent process address space, until exit() or exec() is called.

What happens to the parent process, if some one kills the child process before calling the exit()/exec()?

posted Oct 28, 2014 by Pradeep Kumar Nalla

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
This is what Wiki is saying -
The use of vfork for any purpose except as a prelude to an immediate call to a function from the exec family (and a select few other operations) gives rise to undefined behavior. In particular the Linux man page for vfork strongly discourages its use:

It is rather unfortunate that Linux revived this specter from the past. The BSD man page states: "This system call will be eliminated when proper system sharing mechanisms are implemented. Users should not depend on the memory sharing semantics of vfork() as it will, in that case, be made synonymous to fork."


So behavior may be undefined, waiting for others to comment.

2 Answers

+1 vote

According to the vfork man page:

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).

So I should imagine that when the child is killed, the parent resumes, and can call wait() and retrieve the child's exit status.

answer Oct 29, 2014 by anonymous
–1 vote

When a process is created using vfork() child process is created and starts running in the parent process address space, until exit() or exec() is called.

Wrong. The child runs in its own address space.

What happens to the parent process, if some one kills the child process before calling the exit()/exec()?

"Killing" a process means sending it a signal. If there is no signal handler (or the signal cannot be caught) the kernel phase of the process wraps up and informs the parent via a SIGCHLD signal. If the parent is dead, it informs process 1 (traditionally init, now systemd).
See signal(2) and _exit(2).

answer Oct 28, 2014 by anonymous
My apologies. I misread your question and described what happens with fork() rather than vfork().
Similar Questions
+2 votes

Same question for Thread also..
If i use exit system call in thread then what happens to the main process?

+3 votes

Please understand the scenario :

I have an embedded system, on which i do telnet and then i starts i run an application using ./binary_name &.
Now if i close the terminal, and if i do telnet from new terminal then i can see above process is still running.

Now, To check this, i have written a sample program,

#include<stdio.h>
main()
{
    while(1);
}

I just compiled it and i ran it on my linux PC using ./a.out &.
Then i just closed the terminal and from new terminal i checked using ps -elf command this process was killed.

My question is why different behavior for both process. i started both the process in background. Then why?

Any suggestion?

Thanks in advance

+4 votes

Lets assume I have a system with RAM of 1GB. and virtual memory is 500MB. That brings to 1.5GB i.e. 1500 MBytes.

I have read somewhere that when I process is created stack of 8MB is associated to that process. So, assuming that any of the process is not allocating any dynamic memory or anything, then does it mean that, Maximum number of process that i can create is 1500/8 and i.e. 187 Process.

Please clarify my understanding,

+1 vote

for Ex:
Process Control Block,
then what else?

...