I am totally new with C.
What are the process items that are inherited in a child created using
fork();
?What are the process items that are different from the process's parent?
I am totally new with C.
What are the process items that are inherited in a child created using fork();
?
What are the process items that are different from the process's parent?
This hasn't got much to do with C, rather with
fork()
, which is a POSIX system call (and I guess it could behave differently on different systems).I'd suggest you to read the
fork
manual, which is really clear about this:If you're interested about Linux, you should also check the
clone
system call, that lets you specify with more accuracy what you want.The fork(2) man page on your system (
man fork
) should give you better details but generally the child only inherits the parent's list of file descriptors, including open files, sockets, and process handles.From my system's man page (Mac OS X 10.6.6):
The only things of child that are different its parent are its
PPID i.e parent process id and
PID process id.
And when it comes to similarity child process inherits its parent's FILE DESCRIPTOR table thus you would see that always three FILE DESCRIPTORS of child are always occupied which correspond to STDIN,STDOUT and STDERR.
See the official description of fork(2)
There is no object-oriented inheritence in C.
Fork'ing in C is basically the process being stopped while it is running, and an entire copy of it being made in (effectively) a different memory space, then both processes being told to continue. They will both continue from where the parent was paused. The only way you can tell which process you are in is to check the return value of the
fork()
call.In such a situation the child doesn't really inherit everything from the parent process, it's more like it gets a complete copy of everything the parent had.