problem of wait()

Discussion in 'C Programming' started by Richard Tobin, Jun 25, 2007.

  1. In article <>,
    Ravi <> wrote:

    > int pid = fork();


    You want a unix newsgroup for this.

    >Can you please explain why exclusion of the *ed statement changes the
    >output of the program


    And it would be helpful to tell people what the change is. If you want
    people to help you, don't make them do unnecessary work.

    -- Richard



    --
    "Consideration shall be given to the need for as many as 32 characters
    in some alphabets" - X3.4, 1963.
    Richard Tobin, Jun 25, 2007
    #1
    1. Advertising

  2. Richard Tobin

    Ravi Guest

    #include <stdio.h>
    main()
    {
    int pid = fork();
    if(pid==0) {
    printf("1:the child about to become a zombie.pid = %d",getpid());
    } else {
    printf("\n0.0:parent here. pid = %d",getpid());
    getchar(); // inclusion of this line changes the output. why?-----*
    pid=fork();
    if (pid==0) {
    printf("\n2:the child about to become a zombie. pid =
    %d",getpid());
    } else {
    printf("\n0.1:parent here. pid = %d",getpid());
    printf("\n0.2:now look into process table");
    getchar();
    }
    }
    }


    Can you please explain why exclusion of the *ed statement changes the
    output of the program
    Ravi, Jun 25, 2007
    #2
    1. Advertising

  3. Richard Tobin

    Lew Pitcher Guest

    Re: problem of wait()

    On Jun 25, 11:36 am, Ravi <> wrote:
    > #include <stdio.h>
    > main()
    > {
    > int pid = fork();
    > if(pid==0) {
    > printf("1:the child about to become a zombie.pid = %d",getpid());
    > } else {
    > printf("\n0.0:parent here. pid = %d",getpid());
    > getchar(); // inclusion of this line changes the output. why?-----*
    > pid=fork();
    > if (pid==0) {
    > printf("\n2:the child about to become a zombie. pid =
    > %d",getpid());
    > } else {
    > printf("\n0.1:parent here. pid = %d",getpid());
    > printf("\n0.2:now look into process table");
    > getchar();
    > }
    > }
    >
    > }
    >
    > Can you please explain why exclusion of the *ed statement changes the
    > output of the program


    Sorry, but no, we can't.

    First off, you use a function (fork()) that is not part of the C
    language. Likely, you got this function from someplace else (my guess
    is a Unix system function), and while /you/ may know what it does, we
    don't.

    Secondly, even if we did know what fork() does (and a great number of
    here probably do), we don't know what the output of your program looks
    like, in order to explain why a single call to getchar() would change
    it.

    My suggestion is that you ask your question (with more details) in a
    forum that knows about C programming and the fork() function.
    Lew Pitcher, Jun 25, 2007
    #3
  4. Richard Tobin

    Default User Guest

    Re: problem of wait()

    Ravi wrote:

    > #include <stdio.h>
    > main()
    > {
    > int pid = fork();
    > if(pid==0) {
    > printf("1:the child about to become a zombie.pid = %d",getpid());
    > } else {
    > printf("\n0.0:parent here. pid = %d",getpid());
    > getchar(); // inclusion of this line changes the output. why?-----*
    > pid=fork();
    > if (pid==0) {
    > printf("\n2:the child about to become a zombie. pid =
    > %d",getpid());
    > } else {
    > printf("\n0.1:parent here. pid = %d",getpid());
    > printf("\n0.2:now look into process table");
    > getchar();
    > }
    > }
    > }


    Try comp.unix.programmer.

    > Can you please explain why exclusion of the *ed statement changes the
    > output of the program



    When you do, tell them what the outputs are.




    Brian
    Default User, Jun 25, 2007
    #4
    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. Abraham Khalil

    Theads problem - wait and notify

    Abraham Khalil, Sep 3, 2003, in forum: Java
    Replies:
    1
    Views:
    512
    Roedy Green
    Sep 3, 2003
  2. Huey

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

    Huey, Mar 1, 2004, in forum: C Programming
    Replies:
    1
    Views:
    1,942
    -berlin.de
    Mar 1, 2004
  3. Vera
    Replies:
    5
    Views:
    830
  4. uncutstone
    Replies:
    13
    Views:
    253
    Robert Klemme
    May 14, 2006
  5. Yaron Cohen

    body.style.cursor='wait' problem

    Yaron Cohen, Oct 19, 2003, in forum: Javascript
    Replies:
    1
    Views:
    128
Loading...

Share This Page