Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Simple Linux Processes Program

  1. Nov 18, 2008 #1
    Hello,
    I try to make a program which gets the number of desired childs from user, then creates them sequentially and destroys them in reverse order.
    I just don't understand why it doesn't work correctly :(

    Code (Text):

    #include <stdio.h>
    #include <unistd.h>
    #include <sys/wait.h>

    int main(int argc, char** argv) {
            int pid, status,n_sons,current_son=0;
            printf("Enter number of sons:");
            scanf("%d",&n_sons);

            do {
                    pid=fork();
                    if(pid !=0 ) {
                            printf("Created Son, with PID:%d and PPID:%d\n",pid,getppid());
                            wait(&status);
                            printf("Son with PID:%d, terminated with status:%d\n",pid,status);
                            break;
                    }
                    else {
                           current_son++;
                    }
            }while(current_son < n_sons);

            return 0;
    }

     
     
  2. jcsd
  3. Nov 18, 2008 #2
    found the problem
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Simple Linux Processes Program
  1. An simple program (Replies: 3)

Loading...