what things we have to take care when we fork and exec new process?
Printable View
what things we have to take care when we fork and exec new process?
Pretty much nothing. As long as you check if the return-values from fork and exec~ functions are satisfying you will be alright.
(For example, don't forget to exit the child if exec~ was unsuccessful)
when we fork the process it will copy all the open fd set, signal set and many other things to child process image from parent process image. Then we make the exec call for running particular command. now it is necessary to close all fd & block signals and other things in child process. because we are going to make a new process which is differ then parent process.
so how impotent to handle this type of things in fork+exec?
You should close open file-descriptors that are lying around.
If this is important or not is up to you, but if your process has a lot resources open at the same time and the OS the process is running under has a low limit for how many files that can be open (how many file-descriptors that can be in use) and you choose to fork()/xecl to a process that wants to open many more descriptors.. well you do the math.