forking processes

This is a discussion on forking processes within the C++ Programming forums, part of the General Programming Boards category; Im working on this program and the output should be like this whenthe user enters in something. the output should ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    215

    forking processes

    Im working on this program and the output should be like this whenthe user enters in something.


    the output should be like this:

    input: line one
    pid 5302 outputs: line one
    input:line three
    pid 5302 outputs: line three
    pid 5307 outputs: line three
    input: line two
    pid 5307 outputs: line two
    pid 5302 outputs: line two
    pid 5308 outputs: line two
    input: terminate
    pid 5302 exits
    pid 5308 exits
    pid 5307 exits
    pid 5001 exits

    my code doesnt do that, instead the text entered after the first input line is rearranged. Here is my code, thanks.

    http://sourcepost.sytes.net/sourcepo...ource_id=22592

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    i'm not too familiar with processes or what you need or even what's wrong - but from the way you named your variables (childPID) it seems that you might need == instead of =

    if(childPID == fork())
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  3. #3
    Registered User
    Join Date
    May 2004
    Posts
    215
    oh, well the ChildPID = fork() makes it create another child, thats why i use it instead of ==, im trying to create another child, which i do

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    i didn't realize the if-else did the same thing (i wasn't really looking at your code)

    save yourself a few bytes
    Code:
    do{
                     cin.getline(message.greeting,50,'\n');
                     cout << "input: " << message.greeting << endl;
                     if(childPID = fork())
                          counter++;
                         
                     cout << "pid " << getppid() << "outputs:" << message.greeting << endl;
     
                  }
                 }while(strcmp(message.greeting,"terminate")!=0);

    what do you mean "the first input line is rearranged"?
    post the console output.
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 34
    Last Post: 05-27-2009, 01:26 PM
  2. Why isn't this printing all 1024 processes?
    By DayOldPorridge in forum C Programming
    Replies: 4
    Last Post: 04-19-2009, 06:47 PM
  3. Processes not dying
    By Elkvis in forum Linux Programming
    Replies: 12
    Last Post: 04-23-2008, 09:59 AM
  4. binary tree of processes
    By gregulator in forum C Programming
    Replies: 1
    Last Post: 02-28-2005, 12:59 AM
  5. Computer Processes.... Which can be stopped?
    By Sevrin in forum Tech Board
    Replies: 3
    Last Post: 06-08-2003, 09:13 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21