1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Dismiss Notice

Separating c code files per process

Discussion in 'C /C ++' started by Linux-SWAT, Dec 18, 2016.

  1. Linux-SWAT

    Linux-SWAT Advanced Member

    Joined:
    Feb 13, 2010
    Messages:
    7,912
    Hi,

    I would like to know how to properly organize c files, I'll use fork() and I'd like processus to have their own .c/.h files.
    Better to have the fork() in the main parent or in the separate files ?
     
    Tags:
  2. levi

    levi Still fresh, damnit!

    Joined:
    Oct 6, 2008
    Messages:
    8,057
    Location:
    Somewhere off the coast of the EU
    It's up to you isn't it? You could import the daughter files in the main c file and call their functions from a fork, or you could define those functions locally. It doesn't matter once it's been through the preprocessor.
     
  3. TeDaDeS

    TeDaDeS Very Active Member

    Joined:
    Jan 15, 2004
    Messages:
    709
    Location:
    The Netherlands
    If you use fork it implies the child process is somewhat completely separate from the (main) parent process, else you would have used a thread.
    In that case I assume it is more logical to put the fork into the main function of the parent, as the child process itself does not 'care' about what the parent process do as the process itself does not use fork (or it has to have child processes to).

    Also if there is a situation where you would want to use each .c file separately for some reason; you would probably not use the fork function in that file, right?

    What ever you choose I would at least keep it consistent.
     
  4. Linux-SWAT

    Linux-SWAT Advanced Member

    Joined:
    Feb 13, 2010
    Messages:
    7,912
    Yup that's what I did, I fork then call the function.
     

Share This Page

Loading...