pid's

This is a discussion on pid's within the Linux Programming forums, part of the Platform Specific Boards category; hi, how I can get everyone child pid's the some parent?...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    77

    pid's

    hi, how I can get everyone child pid's the some parent?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,590
    Add them to some record when you call fork()
    Remove them from that record when you waitpid() for them to exit

    Or are you trying to create some kind of process tree?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    77
    for instance, i use it function many times... I can tell parent from child (1), but how I can tell from child with B child A?
    Code:
    int main(void){
    launcher("A");
    launcher("B");
    }
    void launcher(char *put){
    pid_t   pid;
             TELL_WAIT();
        if ((pid = fork()) < 0) {
            printf("fork error\n");
        }
      if (pid == 0) {
            glob++;
            var++;
    
            if(strcmp(put,"A")){
            printf("output from child glob = %d, var = %d , put = A \n",glob, var);
    
    
            }
            if(strcmp(put,"B")){
            printf("output from child glob = %d, var = %d , put = B \n",glob, var);
            TELL_CHILD(pid); // I want call child A from child B
            WAIT_CHILD();
            }
    //WAIT_PARENT(); //1
        } else {
            if(strcmp(put,"A")){
            printf("pid = %d, parent_pid=%u,glob = %d, var = %d, xxx %d put = A \n", getpid(), getppid(), glob, var, pid);
            }
    
            if(strcmp(put,"B")){
            printf("pid = %d, parent_pid=%u,glob = %d, var = %d, xxx %d put = B\n", getpid(), getppid(), glob, var, pid);
    //TELL_CHILD(pid); //1
            }
        }
    }
    and why parent_pid different
    pid = 31483, parent_pid=4460,glob = 6, var = 88, xxx 31485 put = B
    output from child glob = 7, var = 89 , put = B
    pid = 31483, parent_pid=4460,glob = 6, var = 88, xxx 31486 put = A
    pid = 31485, parent_pid=31483,glob = 7, var = 89, xxx 31487 put = A
    output from child glob = 7, var = 89 , put = A
    output from child glob = 8, var = 90 , put = A
    Last edited by quantt; 08-13-2009 at 05:04 AM.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Your code starts three children:
    A, which then returns to start a B process.
    and B started from the main process.

    So you have two "B" processes, one with the main process as parent, and one with A as parent.

    You may want to change your code around so that the launch of A doesn't return to start B.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Jan 2009
    Posts
    77
    right, how make one parent with two child's and telling from one child another child?

  6. #6
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by quantt View Post
    right, how make one parent with two child's and telling from one child another child?
    Use the pid of each child.

    You might also want to investigate getppid() (get parent process id) and this stuff:

    Launching Jobs - The GNU C Library
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fork(), pause(), and storing PID's in a linked list
    By vital101 in forum C Programming
    Replies: 10
    Last Post: 09-28-2007, 02:16 AM
  2. Keeping pids
    By DarrenY in forum C Programming
    Replies: 6
    Last Post: 06-04-2006, 03:14 AM
  3. Passing PIDs to another program
    By DarrenY in forum C Programming
    Replies: 3
    Last Post: 06-02-2006, 02:04 PM

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