Forking !

Discussion in 'C++' started by harishashim@gmail.com, Jan 17, 2008.

  1. Guest

    I sure hope this question is relevent to comp.lang.c++ . I have my
    doubt but here I go!

    I have very code that do as follows


    pid_t pId = fork();

    //Very large body of code
    codeline1();
    codeline2();
    codeline3();
    //etc etc etc

    if (pId == 0) {

    //child codes

    }else if (pId < 0 ) {

    //some error codes

    }else {

    //parent codes

    }

    My question is codeline1(), codeline2() and codeline3(). Are they
    executed by the parent children or both?

    Any comments?

    Thanks In Advance!
     
    , Jan 17, 2008
    #1
    1. Advertising

  2. a écrit :
    > I sure hope this question is relevent to comp.lang.c++ . I have my
    > doubt but here I go!


    It isn't. fork() is POSIX specific.

    >
    > I have very code that do as follows
    >
    >
    > pid_t pId = fork();
    >
    > //Very large body of code
    > codeline1();
    > codeline2();
    > codeline3();
    > //etc etc etc
    >
    > if (pId == 0) {
    >
    > //child codes
    >
    > }else if (pId < 0 ) {
    >
    > //some error codes
    >
    > }else {
    >
    > //parent codes
    >
    > }
    >
    > My question is codeline1(), codeline2() and codeline3(). Are they
    > executed by the parent children or both?


    Both.

    >
    > Any comments?


    I find it strange that you check for the error case so late (usually a
    memory matter, so it is rather important) and I would also question the
    interest of having instructions execution duplicated in the fater and
    the child when you don't know if it successful or in with process you are.

    Michael
     
    Michael DOUBEZ, Jan 17, 2008
    #2
    1. Advertising

  3. Guest


    > > Any comments?

    >
    > I find it strange that you check for the error case so late (usually a
    > memory matter, so it is rather important) and I would also question the
    > interest of having instructions execution duplicated in the fater and
    > the child when you don't know if it successful or in with process you are.
    >
    > Michael


    Thanks for the reply. I am maintaining old codes.

    If it is executed by both than I have a reason to cry foul and point
    out that it is a bug.

    Thanks again!
     
    , Jan 17, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SRam

    Forking server

    SRam, Aug 21, 2003, in forum: Perl
    Replies:
    1
    Views:
    3,000
  2. SRam

    Forking Server

    SRam, Sep 15, 2003, in forum: Perl
    Replies:
    0
    Views:
    547
  3. Matt Stevens

    Forking HTTP Daemon - Problem

    Matt Stevens, Dec 8, 2003, in forum: Perl
    Replies:
    1
    Views:
    671
    Jim Gibson
    Dec 9, 2003
  4. Ed
    Replies:
    0
    Views:
    691
  5. James

    forking and using MySQL

    James, May 15, 2004, in forum: Perl
    Replies:
    1
    Views:
    528
    Mothra
    May 19, 2004
Loading...

Share This Page