How to make "fork/wait" to WAIT longer?

Discussion in 'C Programming' started by Huey, Mar 1, 2004.

  1. Huey

    Huey Guest

    Hi All,

    I encountered a funny thing, and my code schetch as below:


    #define READ 0
    #define WRITE 1
    int byteRead, status, pd[2];
    char buff[100];

    pipe(pd);

    if (fork()) {
    wait(&status);
    byteRead = read(pd[READ], buff, 100);
    buff[byteRead] = '\0';

    } else {
    close(WRITE);
    dup(pd[WRITE]);
    execl("./c_executable", argv1, argv2, NULL);

    }

    This piece of code works very well for years for me. However, when my
    c_executable got slightly heavier work load (a number of hash and
    processing, and tesed thoroghly), it was broken. While I replaced
    c_executable with lighter work load, it worked again. I am puzzled:
    does the fork/wait pair has a timeout that terminates the child
    process of execl()? If not, why a heavier work load in child process
    failed? If yes, how to make the wait() to WAIT longer? If it is not
    the issue of timeout, what is the kicker behind?

    Thanks!

    Huey
     
    Huey, Mar 1, 2004
    #1
    1. Advertising

  2. Huey

    -berlin.de Guest

    Huey <> wrote:
    > I encountered a funny thing, and my code schetch as below:


    > #define READ 0
    > #define WRITE 1
    > int byteRead, status, pd[2];
    > char buff[100];
    >
    > pipe(pd);
    >
    > if (fork()) {
    > wait(&status);
    > byteRead = read(pd[READ], buff, 100);
    > buff[byteRead] = '\0';
    >
    > } else {
    > close(WRITE);
    > dup(pd[WRITE]);
    > execl("./c_executable", argv1, argv2, NULL);
    >
    > }


    > This piece of code works very well for years for me. However, when my
    > c_executable got slightly heavier work load (a number of hash and
    > processing, and tesed thoroghly), it was broken. While I replaced
    > c_executable with lighter work load, it worked again. I am puzzled:
    > does the fork/wait pair has a timeout that terminates the child
    > process of execl()? If not, why a heavier work load in child process
    > failed? If yes, how to make the wait() to WAIT longer? If it is not
    > the issue of timeout, what is the kicker behind?


    Sorry, but not a single of the functions you're using here is a
    standard C function, making the question off-topic for clc. Please
    ask this kind of questions e.g. comp.unix.programmer or a similar
    group. It would also be reasonable to specify exactly what you
    mean by "broken".

    <OT>
    No, fork()/wait() doesn't have any timeout. But there are some
    strange things in your code, like calling close with an argument
    of 1 (I guess you mean STDOUT_FILENO) or the arguments you pass to
    execl() - is argv1 the name of the program? - etc. You're also mis-
    using the pipe as a temporary buffer, which only works as long as
    you don't try to write more bytes to it than the pipe length. And
    there are several other things that could go wrong under certain
    conditions.
    </OT>
    Regards, Jens
    --
    \ Jens Thoms Toerring ___ -berlin.de
    \__________________________ http://www.toerring.de
     
    -berlin.de, Mar 1, 2004
    #2
    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. NBB
    Replies:
    2
    Views:
    8,942
  2. George Ter-Saakov

    Make session last longer than 20 minutes.

    George Ter-Saakov, Apr 28, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    393
    Laurent Bugnion
    Apr 29, 2006
  3. sorry.no.email@post_NG.com

    How to make page longer in IE!!!

    sorry.no.email@post_NG.com, Jun 6, 2006, in forum: HTML
    Replies:
    3
    Views:
    532
    sorry.no.email@post_NG.com
    Jun 7, 2006
  4. Bo

    Make tooltip text visible longer

    Bo, Oct 1, 2004, in forum: Javascript
    Replies:
    3
    Views:
    211
    Vladdy
    Oct 1, 2004
  5. James Marshall

    Possible bug in 5.8.6: accept/fork/wait/exit ?

    James Marshall, Jun 6, 2005, in forum: Perl Misc
    Replies:
    2
    Views:
    128
Loading...

Share This Page