Thread: fork + exec

  1. #1
    Registered User
    Join Date
    Feb 2009
    Location
    India, Gujarat
    Posts
    22

    fork + exec

    what things we have to take care when we fork and exec new process?

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    31
    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)

  3. #3
    Registered User
    Join Date
    Feb 2009
    Location
    India, Gujarat
    Posts
    22
    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?

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    31
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 06-02-2009, 06:13 PM
  2. Signals, fork(), wait() and exec()
    By DJTurboToJo in forum C Programming
    Replies: 7
    Last Post: 03-18-2008, 09:14 AM
  3. fork(), exit() - few questions!
    By s3t3c in forum C Programming
    Replies: 10
    Last Post: 11-30-2004, 06:58 AM
  4. Daemon programming: allocated memory vs. fork()
    By twisgabak in forum Linux Programming
    Replies: 2
    Last Post: 09-25-2003, 02:53 PM
  5. Procesees, fork(), wait() and exec()
    By Stewdent in forum Linux Programming
    Replies: 1
    Last Post: 02-20-2003, 11:34 AM