Find the answer to your Linux question:
Results 1 to 2 of 2
hello i need some help with my program. here is the code i can't figure out: Code: int main() { ... if ((pid[1] = fork()) == 0) { printf("Running..."); system("<run ...
  1. #1
    Just Joined!
    Join Date
    Oct 2007
    Posts
    2

    child process

    hello

    i need some help with my program. here is the code i can't figure out:

    Code:
    int main() {
    
    ...
    
    if ((pid[1] = fork()) == 0) {
         printf("Running...");
         system("<run some infinite program>");
         exit(0);
    }
    
    ...
    
    kill(pid[1], 9);
    wait(NULL);
    return 0;
    }
    child doesn't seem to end with kill(). at the end of program i get this on output:

    Code:
    ... some program output...
    
    sh: line 1:  <pid> Terminated              <child program>
    what i don't understand is how to run infinite program as a child process and then end it clean with parent without any messages? thanks for your help.

    btw, im using arch. on ubuntu, the "Terminated" message doesn't show up.

  2. #2
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    Make the child process fork() again and get it to write its PID into a known file. The parent can reap its child and kill the grandchild but sending the signal to the PID read from the file.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...